init
This commit is contained in:
28
src/routes/(user)/my/-hooks/useSaveFile.ts
Normal file
28
src/routes/(user)/my/-hooks/useSaveFile.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { modifyFile, createFile } from "@/apis/file";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export const useSaveFile = (mutationOptions?: any) => {
|
||||
const { mutateAsync: saveMutateAsync, isPending: saveIsPending } =
|
||||
useMutation({
|
||||
mutationFn: (values: any) => {
|
||||
if (values.id) {
|
||||
return modifyFile(values);
|
||||
}
|
||||
return createFile(values);
|
||||
},
|
||||
...(mutationOptions || {}),
|
||||
});
|
||||
|
||||
const save = (values: any) => {
|
||||
toast.promise(saveMutateAsync(values), {
|
||||
loading: "提交中...",
|
||||
success: "操作成功",
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
save,
|
||||
saveIsPending,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user