Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 13x 13x 7x 5x 5x | /**
* useUpdateUser Hook
* React Query mutation hook for updating user profile
*/
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { updateUser, type UpdateUserData } from '@/services/api/userManagementApi';
import type { User } from '@/types/user.types';
interface UpdateUserParams {
username: string;
data: UpdateUserData;
}
/**
* Hook to update user profile
* Invalidates user queries on success
*/
export function useUpdateUser() {
const queryClient = useQueryClient();
return useMutation<User, Error, UpdateUserParams>({
mutationFn: async ({ username, data }: UpdateUserParams) => {
return await updateUser(username, data);
},
onSuccess: (_, variables) => {
// Invalidate relevant queries
queryClient.invalidateQueries({ queryKey: ['users'] });
queryClient.invalidateQueries({ queryKey: ['user', variables.username] });
},
});
}
|