Adds profile and settings pages
This commit is contained in:
@@ -80,7 +80,7 @@ export interface ChangeRolePayload {
|
||||
newRole: UserRole;
|
||||
}
|
||||
|
||||
export type AvailabilityStatus = 'Available' | 'Maintenance' | 'Unavailable';
|
||||
export type AvailabilityStatus = 'Available' | 'Maintenance' | 'NotAvailable';
|
||||
|
||||
export interface AvailabilityResponse {
|
||||
status: AvailabilityStatus;
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { api } from '@/lib/api-client';
|
||||
import type { AvailabilityResponse } from './types';
|
||||
import type { AvailabilityResponse, AvailabilityStatus } from './types';
|
||||
|
||||
export interface UpdateAvailabilityPayload {
|
||||
newStatus: AvailabilityStatus;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export function useAvailabilityStatus() {
|
||||
return useQuery<AvailabilityResponse, Error>({
|
||||
@@ -9,3 +14,11 @@ export function useAvailabilityStatus() {
|
||||
staleTime: 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateAvailability() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<void, Error, UpdateAvailabilityPayload>({
|
||||
mutationFn: (data) => api.post<void>('/api/v1/Availability/admin/status', data),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['availability', 'status'] }),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
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),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user