mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 09:16:22 +02:00
add updateUserMutationAtom with cache invalidation
This commit is contained in:
parent
0ba5de511e
commit
1dbc27b0a3
1 changed files with 19 additions and 0 deletions
19
surfsense_web/atoms/user/user-mutation.atoms.ts
Normal file
19
surfsense_web/atoms/user/user-mutation.atoms.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { atomWithMutation, queryClientAtom } from "jotai-tanstack-query";
|
||||
import type { UpdateUserRequest } from "@/contracts/types/user.types";
|
||||
import { userApiService } from "@/lib/apis/user-api.service";
|
||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||
|
||||
export const updateUserMutationAtom = atomWithMutation((get) => {
|
||||
const queryClient = get(queryClientAtom);
|
||||
|
||||
return {
|
||||
mutationKey: cacheKeys.user.current(),
|
||||
mutationFn: async (request: UpdateUserRequest) => {
|
||||
return userApiService.updateMe(request);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: cacheKeys.user.current() });
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue