more enhancements to loading and error feedback
This commit is contained in:
@@ -5,25 +5,43 @@ import {
|
||||
handleSystemSave,
|
||||
handleSystemRecall,
|
||||
} from "../components/SettingForms/System/SettingSaveRecall";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export const useSystemConfig = () => {
|
||||
const uploadSettingsMutation = useMutation({
|
||||
mutationKey: ["uploadSettings"],
|
||||
mutationFn: sendBlobFileUpload,
|
||||
onError: (error) => toast.error(error.message),
|
||||
onSuccess: (test) => toast(test),
|
||||
onError: (error) =>
|
||||
toast.error(error.message, {
|
||||
id: "uploadSettings",
|
||||
}),
|
||||
onSuccess: (test) =>
|
||||
toast(test, {
|
||||
id: "uploadSettings",
|
||||
}),
|
||||
});
|
||||
|
||||
const saveSystemSettings = useMutation({
|
||||
mutationKey: ["systemSaveSettings"],
|
||||
mutationFn: handleSystemSave,
|
||||
onError: (error) => console.error(error.message),
|
||||
onError: (error) =>
|
||||
toast.error(error.message, {
|
||||
id: "systemSettings",
|
||||
}),
|
||||
});
|
||||
|
||||
const getSystemSettings = useQuery({
|
||||
queryKey: ["getSystemSettings"],
|
||||
queryFn: handleSystemRecall,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (getSystemSettings.isError)
|
||||
toast.error(getSystemSettings.error.message, {
|
||||
id: "systemSettings",
|
||||
});
|
||||
}, [getSystemSettings?.error?.message, getSystemSettings.isError]);
|
||||
|
||||
return {
|
||||
uploadSettings: uploadSettingsMutation.mutate,
|
||||
saveSystemSettings: saveSystemSettings.mutate,
|
||||
|
||||
Reference in New Issue
Block a user