d582f15681
- Implemented tests for import polling functionality, ensuring correct behavior for active and terminal import statuses. - Created tests for the login page, validating user interactions and error handling. - Added unit tests for money utility functions, covering parsing, formatting, and summation of monetary values. - Developed tests for query keys, ensuring proper scoping and invalidation roots. chore: setup testing environment and configuration - Added setup file for testing with Vitest and Testing Library. - Configured TypeScript and Vite for the frontend project. - Created Docker and Nginx configurations for local development and production environments. - Established a PostgreSQL initialization script for setting up application roles. docs: add README and environment configuration for infra - Included README for the infra directory, detailing local development setup and service descriptions. - Created an example environment configuration file for local development with placeholders for sensitive information.
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
import { api } from '@/api/endpoints'
|
|
import { queryKeys } from '@/api/queryKeys'
|
|
import type { AcceptInvitePayload, LoginPayload, PasswordResetPayload, User } from '@/api/types'
|
|
|
|
export function useMe() {
|
|
return useQuery({
|
|
queryKey: queryKeys.me(),
|
|
queryFn: api.auth.me,
|
|
retry: false,
|
|
staleTime: 60_000,
|
|
})
|
|
}
|
|
|
|
function useSessionMutation<P>(mutationFn: (payload: P) => Promise<User>) {
|
|
const queryClient = useQueryClient()
|
|
return useMutation({
|
|
mutationFn,
|
|
onSuccess: (user) => {
|
|
queryClient.clear()
|
|
queryClient.setQueryData(queryKeys.me(), user)
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useLogin() {
|
|
return useSessionMutation<LoginPayload>((payload) => api.auth.login(payload))
|
|
}
|
|
|
|
export function useAcceptInvite() {
|
|
return useSessionMutation<AcceptInvitePayload>((payload) => api.auth.acceptInvite(payload))
|
|
}
|
|
|
|
export function useRequestPasswordReset() {
|
|
return useMutation({ mutationFn: (email: string) => api.auth.requestPasswordReset(email) })
|
|
}
|
|
|
|
export function useConfirmPasswordReset() {
|
|
return useSessionMutation<PasswordResetPayload>((payload) => api.auth.confirmPasswordReset(payload))
|
|
}
|
|
|
|
export function useLogout() {
|
|
const queryClient = useQueryClient()
|
|
return useMutation({
|
|
mutationFn: () => api.auth.logout(),
|
|
onSettled: () => {
|
|
queryClient.clear()
|
|
},
|
|
})
|
|
}
|