From a248064800fc773b1ed29bee5606ab91336c8568 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Mon, 29 Jun 2026 12:09:10 +0330 Subject: [PATCH] multi phones in setting --- src/pages/settings/GeneralSettings.tsx | 28 +++--- .../settings/components/PhonesSection.tsx | 92 +++++++++++++++++++ src/pages/settings/types/Types.ts | 5 +- 3 files changed, 111 insertions(+), 14 deletions(-) create mode 100644 src/pages/settings/components/PhonesSection.tsx diff --git a/src/pages/settings/GeneralSettings.tsx b/src/pages/settings/GeneralSettings.tsx index 2beb2e5..1392deb 100644 --- a/src/pages/settings/GeneralSettings.tsx +++ b/src/pages/settings/GeneralSettings.tsx @@ -17,11 +17,15 @@ import * as yup from 'yup' import { toast } from 'react-toastify' import { extractErrorMessage } from '@/config/func' import ServiceAreaPicker from './components/ServiceAreaPicker' +import PhonesSection from './components/PhonesSection' const validationSchema = yup.object({ name: yup.string().required('نام رستوران الزامی است'), menuColor: yup.string().required('رنگ منو الزامی است'), - phone: yup.string().required('شماره تماس الزامی است'), + phones: yup + .array() + .min(1, 'حداقل یک شماره تماس الزامی است') + .of(yup.string().required('شماره تماس الزامی است')), instagram: yup.string().url('لینک اینستاگرام معتبر نیست').nullable(), address: yup.string().required('آدرس الزامی است'), latitude: yup.number().required('انتخاب موقعیت روی نقشه الزامی است'), @@ -40,7 +44,7 @@ const GeneralSettings: FC = () => { initialValues: { name: '', menuColor: '#000000', - phone: '', + phones: [''], instagram: '', address: '', latitude: 0, @@ -93,7 +97,12 @@ const GeneralSettings: FC = () => { formik.setValues({ name: restaurantData.name || '', menuColor: restaurantData.menuColor || '#000000', - phone: restaurantData.phone || '', + phones: + restaurantData.phones?.length + ? restaurantData.phones + : restaurantData.phone + ? [restaurantData.phone] + : [''], instagram: restaurantData.instagram || '', address: restaurantData.address || '', latitude: restaurantData.latitude || 0, @@ -155,16 +164,11 @@ const GeneralSettings: FC = () => { } -
- +
+ +
+
+} + +const PhonesSection: FC = ({ formik }) => { + const phones = formik.values.phones ?? [] + const phonesError = formik.touched.phones && typeof formik.errors.phones === 'string' ? formik.errors.phones : '' + const phoneErrors = Array.isArray(formik.errors.phones) ? formik.errors.phones : [] + + const getFieldError = (index: number) => { + if (!formik.touched.phones?.[index] || !phoneErrors[index]) { + return '' + } + return String(phoneErrors[index]) + } + + return ( +
+
+
شماره‌های تماس
+ {phones.length > 0 && ( + {phones.length} شماره + )} +
+ +
+ {phones.map((phone, index) => ( +
+
+
+
+ +
+ شماره {index + 1} +
+ {phones.length > 1 && ( + + )} +
+ + +
+ ))} + + + + {phonesError &&
{phonesError}
} +
+
+ ) +} + +export default PhonesSection diff --git a/src/pages/settings/types/Types.ts b/src/pages/settings/types/Types.ts index 4a100cb..8786265 100644 --- a/src/pages/settings/types/Types.ts +++ b/src/pages/settings/types/Types.ts @@ -10,7 +10,7 @@ export type GeoJSONPolygon = { export type UpdateRestaurantType = { name?: string; menuColor?: string; - phone?: string; + phones?: string[]; instagram?: string; address?: string; logo?: string; @@ -51,7 +51,8 @@ export type Restaurant = { isActive: boolean; establishedYear: number | null; phoneNumber: string | null; - phone: string; + phone?: string; + phones?: string[]; instagram: string | null; telegram: string | null; whatsapp: string | null;