feat: add friend from settings pages

Now the user can add friend to his friends list through
the settings page
This commit is contained in:
Moon Patel
2023-10-13 00:53:52 +05:30
parent 5a0498af4d
commit ea04c7eb9d
2 changed files with 15 additions and 11 deletions
+7 -3
View File
@@ -10,13 +10,17 @@ const Friends = () => {
const form = useForm({ initialValues: { username: '' }, })
const addFriend = async () => {
console.log(form.values);
const response = await fetch(`${import.meta.env.VITE_BACKEND_HOST}/api/user/friends/${form.values.username}`, {
method: 'POST',
credentials: 'include'
credentials: 'include',
body: JSON.stringify({ username: form.values.username })
});
const resData = await response.json();
if (resData.success === false) {
if (!response.ok) {
const resData = await response.json();
form.setErrors({ username: resData.error.message })
} else {
console.log("Friend added");
}
}