changes and improvements
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import toast from "react-hot-toast";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import { useSession } from "next-auth/react";
|
||||
|
||||
const useUser = () => {
|
||||
@@ -24,13 +22,10 @@ const useUser = () => {
|
||||
};
|
||||
|
||||
const useUpdateUser = () => {
|
||||
const { t } = useTranslation();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (user: any) => {
|
||||
const load = toast.loading(t("applying_settings"));
|
||||
|
||||
const response = await fetch(`/api/v1/users/${user.id}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
@@ -39,14 +34,11 @@ const useUpdateUser = () => {
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
toast.dismiss(load);
|
||||
|
||||
if (!response.ok) throw new Error(data.response);
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
toast.success(t("settings_applied"));
|
||||
queryClient.setQueryData(["user"], data.response);
|
||||
},
|
||||
onMutate: async (user) => {
|
||||
@@ -55,9 +47,6 @@ const useUpdateUser = () => {
|
||||
return { ...oldData, ...user };
|
||||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(error.message);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user