From f62b7a8070b38bfe65162ef3f1bf4cf782102d3e Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Wed, 3 Dec 2025 10:26:42 +0330 Subject: [PATCH] change payment method --- src/langs/fa.json | 5 + src/pages/paymentMethods/Create.tsx | 93 +++++++++--- src/pages/paymentMethods/Update.tsx | 140 +++++++++++++----- .../components/PaymentMethodTableColumns.tsx | 34 +++-- src/pages/paymentMethods/enum/Enum.ts | 10 ++ .../hooks/usePaymentMethodData.ts | 7 - .../service/PaymentMethodService.ts | 26 +--- src/pages/paymentMethods/types/Types.ts | 19 ++- 8 files changed, 237 insertions(+), 97 deletions(-) create mode 100644 src/pages/paymentMethods/enum/Enum.ts diff --git a/src/langs/fa.json b/src/langs/fa.json index c302404..e508db9 100644 --- a/src/langs/fa.json +++ b/src/langs/fa.json @@ -763,6 +763,11 @@ "add_account": "افزودن حساب" }, "payment": { + "Online": "آنلاین", + "Cash": "نقدی", + "CardOnDelivery": "کارت هنگام تحویل", + "Wallet": "کیف پول", + "zarinpal": "زرین‌پال", "payments": "پرداخت ها", "status_payment": "وضعیت پرداخت", "user": "کاربر", diff --git a/src/pages/paymentMethods/Create.tsx b/src/pages/paymentMethods/Create.tsx index 4c92bb6..2f96c08 100644 --- a/src/pages/paymentMethods/Create.tsx +++ b/src/pages/paymentMethods/Create.tsx @@ -4,36 +4,53 @@ import * as Yup from 'yup' import { TickCircle } from 'iconsax-react' import { toast } from 'react-toastify' import { useNavigate } from 'react-router-dom' +import { useTranslation } from 'react-i18next' import Button from '@/components/Button' import Input from '@/components/Input' import Select from '@/components/Select' import Switch from '@/components/Switch' -import type { CreateRestaurantPaymentMethodType, PaymentMethod } from './types/Types' -import { useCreateRestaurantPaymentMethod, useGetPaymentMethods } from './hooks/usePaymentMethodData' +import Textarea from '@/components/Textarea' +import type { CreateRestaurantPaymentMethodType } from './types/Types' +import { useCreateRestaurantPaymentMethod } from './hooks/usePaymentMethodData' +import { PaymentMethodEnum, PaymentGatewayEnum } from './enum/Enum' import { Pages } from '@/config/Pages' import type { ErrorType } from '@/helpers/types' import { extractErrorMessage } from '@/config/func' const CreatePaymentMethod: FC = () => { + const { t } = useTranslation('global') const navigate = useNavigate() const { mutate: createPaymentMethod, isPending } = useCreateRestaurantPaymentMethod() - const { data: paymentMethodsData } = useGetPaymentMethods() - const paymentMethods = paymentMethodsData?.data?.map((method: PaymentMethod) => ({ - label: method.name, - value: method.id - })) || [] + const paymentMethods = [ + { label: t(`payment.${PaymentMethodEnum.Online}`), value: PaymentMethodEnum.Online }, + { label: t(`payment.${PaymentMethodEnum.Cash}`), value: PaymentMethodEnum.Cash }, + { label: t(`payment.${PaymentMethodEnum.CardOnDelivery}`), value: PaymentMethodEnum.CardOnDelivery }, + { label: t(`payment.${PaymentMethodEnum.Wallet}`), value: PaymentMethodEnum.Wallet }, + ] + + const paymentGateways = [ + { label: t(`payment.${PaymentGatewayEnum.ZarinPal}`), value: PaymentGatewayEnum.ZarinPal }, + ] const formik = useFormik({ initialValues: { - paymentMethodId: '', + title: '', + method: '', + gateway: '', + description: '', + enabled: true, + order: 0, merchantId: '', - isActive: true, }, validationSchema: Yup.object().shape({ - paymentMethodId: Yup.string().required('روش پرداخت الزامی است'), + title: Yup.string().required('عنوان الزامی است'), + method: Yup.string().required('روش پرداخت الزامی است'), + gateway: Yup.string().required('درگاه پرداخت الزامی است'), + description: Yup.string().required('توضیحات الزامی است'), + enabled: Yup.boolean(), + order: Yup.number().required('ترتیب الزامی است').min(0, 'ترتیب باید مثبت باشد'), merchantId: Yup.string().required('شناسه مرچنت الزامی است'), - isActive: Yup.boolean(), }), onSubmit: (values) => { createPaymentMethod(values, { @@ -73,12 +90,32 @@ const CreatePaymentMethod: FC = () => {
+
+
+