change payment method
This commit is contained in:
@@ -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 : ''}
|
||||
/>
|
||||
</div>
|
||||
<div className='mt-6'>
|
||||
<Select
|
||||
label='درگاه پرداخت'
|
||||
name='gateway'
|
||||
value={formik.values.gateway}
|
||||
onChange={formik.handleChange}
|
||||
items={paymentGateways}
|
||||
placeholder='درگاه پرداخت را انتخاب کنید'
|
||||
error_text={formik.touched.gateway && formik.errors.gateway ? formik.errors.gateway : ''}
|
||||
/>
|
||||
</div>
|
||||
<div className='mt-6'>
|
||||
<Input
|
||||
label='شناسه مرچنت'
|
||||
name='merchantId'
|
||||
value={formik.values.merchantId}
|
||||
onChange={formik.handleChange}
|
||||
error_text={formik.touched.merchantId && formik.errors.merchantId ? formik.errors.merchantId : ''}
|
||||
/>
|
||||
</div>
|
||||
{formik.values.method === PaymentMethodEnum.Online && (
|
||||
<>
|
||||
<div className='mt-6'>
|
||||
<Select
|
||||
label='درگاه پرداخت'
|
||||
name='gateway'
|
||||
value={formik.values.gateway}
|
||||
onChange={formik.handleChange}
|
||||
items={paymentGateways}
|
||||
placeholder='درگاه پرداخت را انتخاب کنید'
|
||||
error_text={formik.touched.gateway && formik.errors.gateway ? formik.errors.gateway : ''}
|
||||
/>
|
||||
</div>
|
||||
<div className='mt-6'>
|
||||
<Input
|
||||
label='شناسه مرچنت'
|
||||
name='merchantId'
|
||||
value={formik.values.merchantId}
|
||||
onChange={formik.handleChange}
|
||||
error_text={formik.touched.merchantId && formik.errors.merchantId ? formik.errors.merchantId : ''}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<div className='mt-6'>
|
||||
<Textarea
|
||||
label='توضیحات'
|
||||
|
||||
@@ -65,16 +65,39 @@ const UpdatePaymentMethod: 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) => {
|
||||
if (!id) return
|
||||
|
||||
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,
|
||||
}
|
||||
: {}),
|
||||
}
|
||||
|
||||
updateRestaurantPaymentMethod(
|
||||
{ id, params: values },
|
||||
{ id, params: submitValues },
|
||||
{
|
||||
onSuccess: () => {
|
||||
toast.success('روش پرداخت با موفقیت ویرایش شد')
|
||||
@@ -146,26 +169,30 @@ const UpdatePaymentMethod: FC = () => {
|
||||
error_text={formik.touched.title && formik.errors.title ? formik.errors.title : ''}
|
||||
/>
|
||||
</div>
|
||||
<div className='mt-6'>
|
||||
<Select
|
||||
label='درگاه پرداخت'
|
||||
name='gateway'
|
||||
value={formik.values.gateway}
|
||||
onChange={formik.handleChange}
|
||||
items={paymentGateways}
|
||||
placeholder='درگاه پرداخت را انتخاب کنید'
|
||||
error_text={formik.touched.gateway && formik.errors.gateway ? formik.errors.gateway : ''}
|
||||
/>
|
||||
</div>
|
||||
<div className='mt-6'>
|
||||
<Input
|
||||
label='شناسه مرچنت'
|
||||
name='merchantId'
|
||||
value={formik.values.merchantId}
|
||||
onChange={formik.handleChange}
|
||||
error_text={formik.touched.merchantId && formik.errors.merchantId ? formik.errors.merchantId : ''}
|
||||
/>
|
||||
</div>
|
||||
{formik.values.method === PaymentMethodEnum.Online && (
|
||||
<>
|
||||
<div className='mt-6'>
|
||||
<Select
|
||||
label='درگاه پرداخت'
|
||||
name='gateway'
|
||||
value={formik.values.gateway}
|
||||
onChange={formik.handleChange}
|
||||
items={paymentGateways}
|
||||
placeholder='درگاه پرداخت را انتخاب کنید'
|
||||
error_text={formik.touched.gateway && formik.errors.gateway ? formik.errors.gateway : ''}
|
||||
/>
|
||||
</div>
|
||||
<div className='mt-6'>
|
||||
<Input
|
||||
label='شناسه مرچنت'
|
||||
name='merchantId'
|
||||
value={formik.values.merchantId}
|
||||
onChange={formik.handleChange}
|
||||
error_text={formik.touched.merchantId && formik.errors.merchantId ? formik.errors.merchantId : ''}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<div className='mt-6'>
|
||||
<Textarea
|
||||
label='توضیحات'
|
||||
|
||||
@@ -77,11 +77,11 @@ export type RestaurantPaymentMethodResponse = IResponse<
|
||||
export type CreateRestaurantPaymentMethodType = {
|
||||
title: string;
|
||||
method: string;
|
||||
gateway: string;
|
||||
gateway?: string;
|
||||
description: string;
|
||||
enabled: boolean;
|
||||
order: number;
|
||||
merchantId: string;
|
||||
merchantId?: string;
|
||||
};
|
||||
|
||||
export type GetRestaurantPaymentMethodsParams = {
|
||||
|
||||
Reference in New Issue
Block a user