diff --git a/src/pages/paymentMethods/Create.tsx b/src/pages/paymentMethods/Create.tsx index 2f96c08..cf6e3be 100644 --- a/src/pages/paymentMethods/Create.tsx +++ b/src/pages/paymentMethods/Create.tsx @@ -46,14 +46,36 @@ const CreatePaymentMethod: FC = () => { validationSchema: Yup.object().shape({ title: Yup.string().required('عنوان الزامی است'), method: Yup.string().required('روش پرداخت الزامی است'), - gateway: Yup.string().required('درگاه پرداخت الزامی است'), + gateway: Yup.string().when('method', { + is: PaymentMethodEnum.Online, + then: (schema) => schema.required('درگاه پرداخت الزامی است'), + otherwise: (schema) => schema.notRequired(), + }), description: Yup.string().required('توضیحات الزامی است'), enabled: Yup.boolean(), order: Yup.number().required('ترتیب الزامی است').min(0, 'ترتیب باید مثبت باشد'), - merchantId: Yup.string().required('شناسه مرچنت الزامی است'), + merchantId: Yup.string().when('method', { + is: PaymentMethodEnum.Online, + then: (schema) => schema.required('شناسه مرچنت الزامی است'), + otherwise: (schema) => schema.notRequired(), + }), }), onSubmit: (values) => { - createPaymentMethod(values, { + const submitValues: CreateRestaurantPaymentMethodType = { + title: values.title, + method: values.method, + description: values.description, + enabled: values.enabled, + order: values.order, + ...(values.method === PaymentMethodEnum.Online + ? { + gateway: values.gateway, + merchantId: values.merchantId, + } + : {}), + } + + createPaymentMethod(submitValues, { onSuccess: () => { toast.success('روش پرداخت با موفقیت ایجاد شد') navigate(Pages.payment_methods.list) @@ -107,26 +129,30 @@ const CreatePaymentMethod: FC = () => { error_text={formik.touched.title && formik.errors.title ? formik.errors.title : ''} /> -
- -
+ {formik.values.method === PaymentMethodEnum.Online && ( + <> +
+ +
+ + )}