diff --git a/apps/backoffice/src/app/gacha-roll/_components/modal-add-item.tsx b/apps/backoffice/src/app/gacha-roll/_components/modal-add-item.tsx index 967d89f..83dd111 100644 --- a/apps/backoffice/src/app/gacha-roll/_components/modal-add-item.tsx +++ b/apps/backoffice/src/app/gacha-roll/_components/modal-add-item.tsx @@ -1,7 +1,7 @@ import { Button } from '@imphnen-frontend-service/ui/atoms'; import { Modal } from '@imphnen-frontend-service/ui/molecules'; import { ControlledInputField } from '@imphnen-frontend-service/ui/organisms'; -import { useAddItem, useConfirmAddItem } from '../_hook/use-add-item'; +import { useItem, useConfirmItem } from '../_hook/use-item'; interface IModalAddItem { isOpen: boolean; @@ -18,7 +18,6 @@ const ModalAddItem = ({ onClose, currentStep, nextStep, - prevStep, resetStep, handleAddItem, }: IModalAddItem) => { @@ -50,7 +49,7 @@ interface IStepOneProps { } const StepOne = ({ nextStep }: IStepOneProps) => { - const { form, onSubmit } = useAddItem(nextStep); + const { form, onSubmit } = useItem(nextStep); return ( <> @@ -115,7 +114,11 @@ interface IStepTwoProps { } const StepTwo = ({ onClose, handleAddItem, resetStep }: IStepTwoProps) => { - const { onConfirm, onCancel } = useConfirmAddItem(onClose, resetStep); + const { onConfirm, onCancel } = useConfirmItem( + onClose, + resetStep, + handleAddItem + ); return ( <> diff --git a/apps/backoffice/src/app/gacha-roll/_components/modal-update-item.tsx b/apps/backoffice/src/app/gacha-roll/_components/modal-update-item.tsx index f9dee1c..057afe7 100644 --- a/apps/backoffice/src/app/gacha-roll/_components/modal-update-item.tsx +++ b/apps/backoffice/src/app/gacha-roll/_components/modal-update-item.tsx @@ -1,6 +1,7 @@ import { Button } from '@imphnen-frontend-service/ui/atoms'; -import { InputField, Modal } from '@imphnen-frontend-service/ui/molecules'; -import { useState } from 'react'; +import { Modal } from '@imphnen-frontend-service/ui/molecules'; +import { useConfirmItem, useItem } from '../_hook/use-item'; +import { ControlledInputField } from '@imphnen-frontend-service/ui/organisms'; interface IModalUpdateItem { isOpen: boolean; @@ -17,7 +18,6 @@ const ModalUpdateItem = ({ onClose, currentStep, nextStep, - prevStep, resetStep, handleUpdateItem, }: IModalUpdateItem) => { @@ -49,9 +49,13 @@ interface IStepOneProps { } const StepOne = ({ nextStep }: IStepOneProps) => { - const [itemName, setItemName] = useState('Hoodie IMPHNEN Official 2025'); - const [quantity, setQuantity] = useState('10'); - const [chanceRate, setChanceRate] = useState('0.1'); + const initialValues = { + itemName: 'Hoodie IMPHNEN Official 2025', + quantity: 10, + chanceRate: 0.1, + }; + + const { form, onSubmit } = useItem(nextStep, initialValues); return ( <> @@ -60,45 +64,52 @@ const StepOne = ({ nextStep }: IStepOneProps) => { Update Item Roll Gacha - -
- setItemName(e.target.value)} - size="lg" - className="w-full" - /> - setQuantity(e.target.value)} - size="lg" - className="w-full" - /> - setChanceRate(e.target.value)} - size="lg" - className="w-full" - /> -
+ +
+
+ + + +
- + +
); @@ -110,43 +121,44 @@ interface IStepTwoProps { resetStep: () => void; } -const StepTwo = ({ onClose, handleUpdateItem, resetStep }: IStepTwoProps) => ( - <> - -

- Update Item -

-

- Apakah kamu yakin dengan -
perubahan yang dilakukan? -

-
- - - - - -); +const StepTwo = ({ onClose, handleUpdateItem, resetStep }: IStepTwoProps) => { + const { onConfirm, onCancel } = useConfirmItem( + onClose, + resetStep, + handleUpdateItem + ); + + return ( + <> + +

+ Update Item +

+

+ Apakah kamu yakin dengan +
perubahan yang dilakukan? +

+
+ + + + + + ); +}; export default ModalUpdateItem; diff --git a/apps/backoffice/src/app/gacha-roll/_hook/use-add-item.ts b/apps/backoffice/src/app/gacha-roll/_hook/use-item.ts similarity index 76% rename from apps/backoffice/src/app/gacha-roll/_hook/use-add-item.ts rename to apps/backoffice/src/app/gacha-roll/_hook/use-item.ts index 21c36e4..42514ed 100644 --- a/apps/backoffice/src/app/gacha-roll/_hook/use-add-item.ts +++ b/apps/backoffice/src/app/gacha-roll/_hook/use-item.ts @@ -5,10 +5,14 @@ import { TGachaRollItem } from '@imphnen-frontend-service/service'; -export const useAddItem = (nextStep: () => void) => { +export const useItem = ( + nextStep: () => void, + initialValues?: TGachaRollItem +) => { const form = useForm({ resolver: zodResolver(gachaRollItemSchema), mode: 'all', + defaultValues: initialValues, }); const onSubmit = form.handleSubmit((data) => { @@ -22,13 +26,13 @@ export const useAddItem = (nextStep: () => void) => { }; }; -export const useConfirmAddItem = ( +export const useConfirmItem = ( onClose: () => void, resetStep: () => void, - handleAddItem?: () => void, + actionFunction?: () => void, ) => { const onConfirm = () => { - handleAddItem?.(); + actionFunction?.(); onClose(); resetStep(); };