32 lines
931 B
TypeScript
32 lines
931 B
TypeScript
import { useMutation } from '@tanstack/react-query';
|
|
import { api } from '@/lib/api-client';
|
|
import { useAuth } from '@/contexts/auth-context';
|
|
import type { UserListItem } from './types';
|
|
|
|
export interface UpdateProfilePayload {
|
|
name: string;
|
|
email: string;
|
|
}
|
|
|
|
export interface ChangePasswordPayload {
|
|
currentPassword: string;
|
|
newPassword: string;
|
|
}
|
|
|
|
export function useUpdateProfile() {
|
|
const { refresh } = useAuth();
|
|
return useMutation<UserListItem, Error, UpdateProfilePayload>({
|
|
mutationFn: (data) => api.put<UserListItem>('/api/v1/Users/me', data),
|
|
onSuccess: () => {
|
|
// Sync AuthContext with updated name/email via token refresh
|
|
void refresh();
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useChangePassword() {
|
|
return useMutation<void, Error, ChangePasswordPayload>({
|
|
mutationFn: (data) => api.post<void>('/api/v1/Auth/change-password', data),
|
|
});
|
|
}
|