Files
imphnen-frontend-service/apps/backoffice/src/app/gacha-roll/_hook/use-add-item.ts
T

46 lines
834 B
TypeScript
Raw Normal View History

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