2025-04-03 23:32:44 +07:00
|
|
|
import { useForm } from 'react-hook-form';
|
|
|
|
|
import {
|
|
|
|
|
authRegisterSchema,
|
|
|
|
|
TRegisterRequest,
|
|
|
|
|
usePostRegister,
|
|
|
|
|
} from '@imphnen-frontend-service/service';
|
|
|
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
|
|
|
import { toast } from 'sonner';
|
|
|
|
|
|
|
|
|
|
export const useRegister = () => {
|
|
|
|
|
const postRegister = usePostRegister();
|
|
|
|
|
const form = useForm<TRegisterRequest>({
|
|
|
|
|
resolver: zodResolver(authRegisterSchema),
|
|
|
|
|
mode: 'all',
|
2025-04-04 16:38:21 +07:00
|
|
|
defaultValues: {
|
|
|
|
|
fullname: '',
|
|
|
|
|
email: '',
|
|
|
|
|
password: '',
|
|
|
|
|
confirm_password: '',
|
|
|
|
|
phone_number: '',
|
|
|
|
|
},
|
2025-04-03 23:32:44 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const onSubmit = form.handleSubmit((data) => {
|
|
|
|
|
postRegister.mutate(data, {
|
2025-05-23 00:28:29 +07:00
|
|
|
onSuccess: () => toast.success('Registrasi sukses'),
|
2025-04-03 23:32:44 +07:00
|
|
|
onError: (error) => toast.error(error.message),
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
form,
|
|
|
|
|
onSubmit,
|
|
|
|
|
};
|
|
|
|
|
};
|