refactor: fix validation for add gacha roll item

- Pisahkan type dan schema untuk gacha roll item
- Perbaiki validasi gacha roll item
- Parsing angka pada component ControlledInputField
- Update type number untuk component Input dan InputField
This commit is contained in:
Hafid Nur
2025-04-05 07:39:57 +07:00
parent 885d156833
commit 3958ae1098
8 changed files with 58 additions and 27 deletions
@@ -1,27 +1,13 @@
import { useForm } from 'react-hook-form';
import { z } from 'zod';
import { zodResolver } from '@hookform/resolvers/zod';
const addItemSchema = z.object({
itemName: z.string().min(1, 'Item name is required'),
quantity: z.string().min(1, 'Quantity is required'),
chanceRate: z
.string()
.min(1, 'Chance rate is required')
.refine(
(val) => {
const num = parseFloat(val);
return num >= 0.1 && num <= 1;
},
{ message: 'Chance rate must be between 0.1 and 1' }
),
});
type TAddItemForm = z.infer<typeof addItemSchema>;
import {
gachaRollItemSchema,
TGachaRollItem
} from '@imphnen-frontend-service/service';
export const useAddItem = (nextStep: () => void) => {
const form = useForm<TAddItemForm>({
resolver: zodResolver(addItemSchema),
const form = useForm<TGachaRollItem>({
resolver: zodResolver(gachaRollItemSchema),
mode: 'all',
});