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