2025-04-05 06:41:11 +07:00
|
|
|
import { useForm } from 'react-hook-form';
|
|
|
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
2025-04-05 07:39:57 +07:00
|
|
|
import {
|
|
|
|
|
gachaRollItemSchema,
|
|
|
|
|
TGachaRollItem
|
|
|
|
|
} from '@imphnen-frontend-service/service';
|
2025-04-05 06:41:11 +07:00
|
|
|
|
2025-04-05 08:02:13 +07:00
|
|
|
export const useItem = (
|
|
|
|
|
nextStep: () => void,
|
|
|
|
|
initialValues?: TGachaRollItem
|
|
|
|
|
) => {
|
2025-04-05 07:39:57 +07:00
|
|
|
const form = useForm<TGachaRollItem>({
|
|
|
|
|
resolver: zodResolver(gachaRollItemSchema),
|
2025-04-05 06:41:11 +07:00
|
|
|
mode: 'all',
|
2025-04-05 08:02:13 +07:00
|
|
|
defaultValues: initialValues,
|
2025-04-05 06:41:11 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const onSubmit = form.handleSubmit((data) => {
|
|
|
|
|
console.log('Form data:', data);
|
|
|
|
|
nextStep();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
form,
|
|
|
|
|
onSubmit,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-05 08:02:13 +07:00
|
|
|
export const useConfirmItem = (
|
2025-04-05 06:41:11 +07:00
|
|
|
onClose: () => void,
|
|
|
|
|
resetStep: () => void,
|
2025-04-05 08:02:13 +07:00
|
|
|
actionFunction?: () => void,
|
2025-04-05 06:41:11 +07:00
|
|
|
) => {
|
|
|
|
|
const onConfirm = () => {
|
2025-04-05 08:02:13 +07:00
|
|
|
actionFunction?.();
|
2025-04-05 06:41:11 +07:00
|
|
|
onClose();
|
|
|
|
|
resetStep();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onCancel = () => {
|
|
|
|
|
onClose();
|
|
|
|
|
resetStep();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
onConfirm,
|
|
|
|
|
onCancel,
|
|
|
|
|
};
|
|
|
|
|
};
|