90a42b9fc5
continuous-integration/drone/push Build is passing
- Introduced DynamicFormBuilder component to streamline form creation for admin and company categories. - Refactored CreateAdmin and CreateCompany components to utilize the new dynamic form structure. - Added createAdminFormSections and createCompanyFormSections functions to define form fields and validation rules. - Enhanced form handling with improved error management and dynamic field rendering. This update enhances maintainability and scalability of forms across the application.
35 lines
864 B
TypeScript
35 lines
864 B
TypeScript
import { useUser } from "@/contexts";
|
|
import { API_ENDPOINTS, userService } from "@/lib/api";
|
|
import { useMutation } from "@tanstack/react-query";
|
|
import { useMemo } from "react";
|
|
|
|
export const useLoginQuery = (callback?: () => void) => {
|
|
const mutationKey = useMemo(() => [API_ENDPOINTS.USER.LOGIN], []);
|
|
const { setAuthState } = useUser();
|
|
return useMutation({
|
|
mutationKey,
|
|
mutationFn: userService.login,
|
|
onSuccess: (response) => {
|
|
setAuthState(response.data);
|
|
console.log(response);
|
|
|
|
if (callback) {
|
|
callback();
|
|
}
|
|
},
|
|
});
|
|
};
|
|
|
|
export const useLogoutQuery = () => {
|
|
const { logout } = useUser();
|
|
const mutationKey = useMemo(() => [API_ENDPOINTS.USER.LOGOUT], []);
|
|
|
|
return useMutation({
|
|
mutationKey,
|
|
mutationFn: () => userService.logout(),
|
|
onSuccess: () => {
|
|
logout();
|
|
},
|
|
});
|
|
};
|