From 66d71c9c25bee5251a7932724ae05071d21c612d Mon Sep 17 00:00:00 2001 From: workashrafi77-web Date: Mon, 26 Jan 2026 15:22:33 +0330 Subject: [PATCH] fixed form for create guilds basiclly --- .vscode/settings.json | 13 +- .../components/create-guilds/CreateGuilds.js | 201 ++++++++++++++++-- .../create-guilds/components/FormActions.js | 18 +- .../components/GuildInfoAccordionItem.js | 2 + .../components/GuildInfoSection.js | 102 +++++---- .../components/PersonalInfoSection.js | 109 +++++++++- .../create-guilds/utils/dataMapping.js | 10 +- .../create-guilds/utils/formUtils.js | 44 +++- .../ManageGuildsRequests.js | 74 ++++++- .../components/manage-guilds/ManageGuilds.js | 45 ++-- .../ProvinceLegalGuildsForm.js | 34 ++- .../ProvinceLegalGuildsInProvince.js | 7 + 12 files changed, 536 insertions(+), 123 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e82b1ec..e6c0cf6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,14 @@ { - "workbench.editor.enablePreviewFromCodeNavigation": true + "workbench.editor.enablePreviewFromCodeNavigation": true, + "launch": { + "configurations": [], + "compounds": [] + }, + "editor.defaultFormatter": "rvest.vs-code-prettier-eslint", + "editor.formatOnSave": true, + "notebook.defaultFormatter": "rvest.vs-code-prettier-eslint", + "notebook.formatOnSave.enabled": true, + "[javascript]": { + "editor.defaultFormatter": "rvest.vs-code-prettier-eslint" + } } diff --git a/src/features/province/components/create-guilds/CreateGuilds.js b/src/features/province/components/create-guilds/CreateGuilds.js index c77142c..a2075f9 100644 --- a/src/features/province/components/create-guilds/CreateGuilds.js +++ b/src/features/province/components/create-guilds/CreateGuilds.js @@ -22,6 +22,8 @@ import { provinceGetFieldOfWorks } from "../../services/ProvinceGetFieldOfWorks" import { provinceGetTypeActivity } from "../../services/provinceGetTypeActivity"; import { provinceGetRegisterCodeStateService } from "../../services/province-get-register-code-state"; import { mainGetGuildsForUpdateOrCreateService } from "../../services/main-get-guilds-for-update-or-create"; +import { cityGetProvinces } from "../../../city/services/CityGetProvinces"; +import { cityGetCity } from "../../../city/services/city-get-city"; import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl"; import { PersonalInfoSection } from "./components/PersonalInfoSection"; import { InquiryForm } from "./components/InquiryForm"; @@ -87,6 +89,8 @@ export const CreateGuilds = ({ guild, updateTable }) => { return []; }); const [cities, setCities] = useState([]); + const [provinces, setProvinces] = useState([]); + const [provinceCities, setProvinceCities] = useState([]); const [typeActivities, setTypeActivities] = useState([]); const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); const [deleteDialogIndex, setDeleteDialogIndex] = useState(null); @@ -109,6 +113,7 @@ export const CreateGuilds = ({ guild, updateTable }) => { const combinedValues = { ...values, // Personal info (shared) ...guildValues, // Guild-specific info (overrides if same keys exist) + national_id: values?.national_id, }; return prepareSubmitData( combinedValues, @@ -117,7 +122,7 @@ export const CreateGuilds = ({ guild, updateTable }) => { hasInquiry ); }); - + console.log(guildsDataArray); dispatch(updateGuildByNationalIdNewService(guildsDataArray)).then( (result) => { if (result.payload.error) { @@ -151,12 +156,78 @@ export const CreateGuilds = ({ guild, updateTable }) => { dispatch(provinceGetTypeActivity()).then((r) => { setTypeActivities(r.payload.data || []); }); + // Fetch provinces for province/city selection + dispatch(cityGetProvinces()).then((r) => { + if (r?.payload?.data) { + setProvinces(r.payload.data); + } + }); }, []); useEffect(() => { + // Initialize Formik's guilds array if we have initial guild data + if (guild && guildsList.length > 0) { + const guildsForFormik = guildsList.map((guildItem) => { + const combinedGuild = { + ...guildItem, + user: guild?.user || {}, + }; + const initialValues = getInitialValues(combinedGuild); + return { + steward: initialValues.steward || false, + guild: initialValues.guild || false, + }; + }); + formik.setFieldValue("guilds", guildsForFormik, false).then(() => { + formik.validateField("guilds"); + }); + } formik.validateForm(); }, []); + // Set province ID from state name when provinces are loaded + useEffect(() => { + if ( + formik.values.state && + provinces.length > 0 && + !formik.values.province + ) { + const province = provinces.find((p) => p.name === formik.values.state); + if (province) { + formik.setFieldValue("province", province.key); + } + } + }, [provinces, formik.values.state, formik.values.province]); + + // Fetch cities when province is selected + useEffect(() => { + if (formik.values.province) { + dispatch(cityGetCity(formik.values.province)).then((r) => { + if (r?.payload?.data) { + setProvinceCities(r.payload.data); + } + }); + } else { + setProvinceCities([]); + } + }, [formik.values.province, dispatch]); + + // Set city ID from person_city name when provinceCities are loaded + useEffect(() => { + if ( + formik.values.person_city && + !formik.values.city && + provinceCities.length > 0 + ) { + const city = provinceCities.find( + (c) => c.name === formik.values.person_city + ); + if (city) { + formik.setFieldValue("city", city.key); + } + } + }, [provinceCities, formik.values.person_city, formik.values.city]); + const mapResponseToFormFields = useCallback( (responseData) => { const guildsData = Array.isArray(responseData.guilds) @@ -187,10 +258,34 @@ export const CreateGuilds = ({ guild, updateTable }) => { return getInitialValues(combinedGuild); }); setGuildsFormValues(initialGuildValues); + + // Update Formik's guilds array for validation + const guildsForFormik = guildsData.map((guildItem) => ({ + steward: + typeof guildItem?.steward === "boolean" + ? guildItem.steward + : typeof guildItem?.isSteward === "boolean" + ? guildItem.isSteward + : false, + guild: + typeof guildItem?.guild === "boolean" + ? guildItem.guild + : typeof guildItem?.isGuild === "boolean" + ? guildItem.isGuild + : false, + })); + formik.setFieldValue("guilds", guildsForFormik, true).then(() => { + formik.validateField("guilds"); + }); + setExpandedAccordion(0); } else { setGuildsList([]); setGuildsFormValues([]); + + formik.setFieldValue("guilds", [], true).then(() => { + formik.validateField("guilds"); + }); } setTimeout(() => { @@ -333,6 +428,19 @@ export const CreateGuilds = ({ guild, updateTable }) => { const newIndex = guildsList.length; setGuildsList([...guildsList, null]); setGuildsFormValues([...guildsFormValues, getInitialValues(null)]); + + // Add to Formik's guilds array for validation + const currentGuilds = formik.values.guilds || []; + formik + .setFieldValue( + "guilds", + [...currentGuilds, { steward: false, guild: false }], + true + ) + .then(() => { + formik.validateField("guilds"); + }); + setExpandedAccordion(newIndex); }; @@ -346,6 +454,19 @@ export const CreateGuilds = ({ guild, updateTable }) => { if (guildsList.length > 1) { setGuildsList(guildsList.filter((_, i) => i !== index)); setGuildsFormValues(guildsFormValues.filter((_, i) => i !== index)); + + // Remove from Formik's guilds array + const currentGuilds = formik.values.guilds || []; + formik + .setFieldValue( + "guilds", + currentGuilds.filter((_, i) => i !== index), + true + ) + .then(() => { + formik.validateField("guilds"); + }); + if (expandedAccordion === index) { setExpandedAccordion(0); } else if (expandedAccordion > index) { @@ -386,6 +507,19 @@ export const CreateGuilds = ({ guild, updateTable }) => { setGuildsFormValues( guildsFormValues.filter((_, i) => i !== deleteDialogIndex) ); + + // Remove from Formik's guilds array + const currentGuilds = formik.values.guilds || []; + formik + .setFieldValue( + "guilds", + currentGuilds.filter((_, i) => i !== deleteDialogIndex), + true + ) + .then(() => { + formik.validateField("guilds"); + }); + // If deleted accordion was expanded, expand the first one if (expandedAccordion === deleteDialogIndex) { setExpandedAccordion(0); @@ -408,19 +542,38 @@ export const CreateGuilds = ({ guild, updateTable }) => { } }; - const handleGuildValuesChange = useCallback((index, fieldName, value) => { - setGuildsFormValues((prev) => { - const newValues = [...prev]; - if (!newValues[index]) { - newValues[index] = getInitialValues(null); + const handleGuildValuesChange = useCallback( + (index, fieldName, value) => { + setGuildsFormValues((prev) => { + const newValues = [...prev]; + if (!newValues[index]) { + newValues[index] = getInitialValues(null); + } + newValues[index] = { + ...newValues[index], + [fieldName]: value, + }; + return newValues; + }); + + // Sync with Formik's guilds array for steward and guild fields + if (fieldName === "steward" || fieldName === "guild") { + const currentGuilds = formik.values.guilds || []; + const updatedGuilds = [...currentGuilds]; + if (!updatedGuilds[index]) { + updatedGuilds[index] = { steward: false, guild: false }; + } + updatedGuilds[index] = { + ...updatedGuilds[index], + [fieldName]: value, + }; + formik.setFieldValue("guilds", updatedGuilds, true).then(() => { + formik.validateField("guilds"); + }); } - newValues[index] = { - ...newValues[index], - [fieldName]: value, - }; - return newValues; - }); - }, []); + }, + [formik] + ); const handleAccordionChange = (index) => (event, isExpanded) => { setExpandedAccordion(isExpanded ? index : false); @@ -438,6 +591,8 @@ export const CreateGuilds = ({ guild, updateTable }) => { const shouldShowInquiryForm = !guild && !isInquiryDone; const shouldShowFormContent = guild || isInquiryDone; + console.log(formik.errors); + return (
{ isAdmin={isAdmin} isSuperAdmin={isSuperAdmin} isKillHouse={isKillHouse} + provinces={provinces} + provinceCities={provinceCities} + guildsList={guildsList} /> { guildData={guildItem} guildActive={guildActive} isAdmin={isAdmin} - cities={cities} + isSuperAdmin={isSuperAdmin} + cities={ + provinceCities.length > 0 ? provinceCities : cities + } typeActivities={typeActivities} onDelete={() => handleDeleteGuild(index)} canDelete={ @@ -561,6 +722,18 @@ export const CreateGuilds = ({ guild, updateTable }) => { !isSuperAdmin && !isKillHouse } + formData={guildsList.map((guildItem, index) => { + const guildValues = guildsFormValues[index]; + const combinedValues = { + ...guildValues, // Guild-specific info (overrides if same keys exist) + }; + return prepareSubmitData( + combinedValues, + guildItem, + originalPhoneNumber, + hasInquiry + ); + })} isKillHouse={isKillHouse} onSubmit={formik.handleSubmit} /> diff --git a/src/features/province/components/create-guilds/components/FormActions.js b/src/features/province/components/create-guilds/components/FormActions.js index 3fdabae..7c4d69d 100644 --- a/src/features/province/components/create-guilds/components/FormActions.js +++ b/src/features/province/components/create-guilds/components/FormActions.js @@ -19,11 +19,14 @@ export const FormActions = ({ ); } - // For KillHouse: check if area_activity contains "مرغ" const isAreaActivityValid = isKillHouse ? formik.values.area_activity && formik.values.area_activity.includes("مرغ") : true; + // Check if guilds validation has errors + const hasGuildsError = formik.errors.guilds; + const hasGuilds = formik.values.guilds && formik.values.guilds.length > 0; + return ( <> @@ -44,7 +47,9 @@ export const FormActions = ({ disabled={ formik.errors.isAccepted || Boolean(formik.errors.national_id) || - !isAreaActivityValid + !isAreaActivityValid || + hasGuildsError || + !hasGuilds } color="primary" fullWidth @@ -63,6 +68,15 @@ export const FormActions = ({ رسته واحد صنفی باید شامل کلمه "مرغ" باشد )} + {hasGuildsError && ( + + {formik.errors.guilds} + + )} ); diff --git a/src/features/province/components/create-guilds/components/GuildInfoAccordionItem.js b/src/features/province/components/create-guilds/components/GuildInfoAccordionItem.js index 4fbec3d..b60227e 100644 --- a/src/features/province/components/create-guilds/components/GuildInfoAccordionItem.js +++ b/src/features/province/components/create-guilds/components/GuildInfoAccordionItem.js @@ -17,6 +17,7 @@ export const GuildInfoAccordionItem = ({ guildData, guildActive, isAdmin, + isSuperAdmin, cities, typeActivities, onDelete, @@ -86,6 +87,7 @@ export const GuildInfoAccordionItem = ({ guild={guildData} guildActive={guildActive} isAdmin={isAdmin} + isSuperAdmin={isSuperAdmin} cities={cities} typeActivities={typeActivities} hideTitle={true} diff --git a/src/features/province/components/create-guilds/components/GuildInfoSection.js b/src/features/province/components/create-guilds/components/GuildInfoSection.js index c599c04..bb56337 100644 --- a/src/features/province/components/create-guilds/components/GuildInfoSection.js +++ b/src/features/province/components/create-guilds/components/GuildInfoSection.js @@ -10,6 +10,7 @@ import { MenuItem, InputLabel, Checkbox, + Autocomplete, } from "@mui/material"; import { DatePicker } from "@mui/x-date-pickers"; import moment from "moment"; @@ -40,6 +41,7 @@ export const GuildInfoSection = ({ guild, guildActive, isAdmin, + isSuperAdmin, cities, typeActivities, hideTitle = false, @@ -81,7 +83,7 @@ export const GuildInfoSection = ({ xs={12} md={6} px={SPACING.TINY} - gap={SPACING.TINY} + gap={SPACING.SMALL} > {isAdmin ? ( @@ -150,60 +152,47 @@ export const GuildInfoSection = ({ {isAdmin ? ( - ({ + id: i.key, + label: i.name, + })) + : [] + } + value={ + cities.find((c) => c.name === formik.values.city_name) + ? { + id: cities.find( + (c) => c.name === formik.values.city_name + )?.key, + label: formik.values.city_name, + } + : formik.values.city_name + ? { + id: null, + label: formik.values.city_name, + } + : null + } + onChange={(e, value) => { + formik.setFieldValue("city_name", value ? value.label : ""); + }} + renderInput={(params) => ( + + )} /> - ) : ( - - )} - - - {isAdmin ? ( - - شهرستان - - ) : ( )} @@ -332,7 +321,7 @@ export const GuildInfoSection = ({ md={6} px={SPACING.TINY} direction="column" - gap={SPACING.TINY} + gap={SPACING.SMALL} > {isAdmin ? ( @@ -345,6 +334,8 @@ export const GuildInfoSection = ({ value={formik.values.postal_code} onChange={formik.handleChange} onBlur={formik.handleBlur} + error={Boolean(formik.errors.postal_code)} + helperText={formik.errors.postal_code} /> ) : ( ) : ( - {isAdmin ? ( + {isAdmin || isSuperAdmin ? ( <> { const getGenderDisplay = (gender) => { if (gender === "True" || gender === true) return GENDER_VALUES.MALE; @@ -305,21 +309,106 @@ export const PersonalInfoSection = ({ {isAdmin ? ( - ({ + id: i.key, + label: i.name, + })) + : [] + } + value={ + provinces.find((p) => p.key === formik.values.province) + ? { + id: formik.values.province, + label: + provinces.find( + (p) => p.key === formik.values.province + )?.name || "", + } + : null + } + onChange={(e, value) => { + formik.setFieldValue("province", value ? value.id : ""); + formik.setFieldValue("city", ""); + formik.setFieldValue("person_city", ""); + }} + disabled={guild} + renderInput={(params) => ( + + )} + /> + ) : ( + p.key === formik.values.province) + ?.name || + formik.values.state || + "-" + } + /> + )} + + + {isAdmin ? ( + ({ + id: i.key, + label: i.name, + })) + : [] + } + value={ + provinceCities.find((c) => c.key === formik.values.city) + ? { + id: formik.values.city, + label: + provinceCities.find( + (c) => c.key === formik.values.city + )?.name || "", + } + : formik.values.person_city + ? { + id: null, + label: formik.values.person_city, + } + : null + } + onChange={(e, value) => { + formik.setFieldValue("city", value ? value.id : ""); + formik.setFieldValue( + "person_city", + value ? value.label : "" + ); + }} + renderInput={(params) => ( + + )} /> ) : ( c.key === formik.values.city) + ?.name || + formik.values.person_city || + "-" + } /> )} diff --git a/src/features/province/components/create-guilds/utils/dataMapping.js b/src/features/province/components/create-guilds/utils/dataMapping.js index aa02a38..a2c1b66 100644 --- a/src/features/province/components/create-guilds/utils/dataMapping.js +++ b/src/features/province/components/create-guilds/utils/dataMapping.js @@ -25,7 +25,12 @@ export const prepareSubmitData = ( values.birth_date || "", hasInquiry === true ), - city: values.city || "", + // city is for user info (personal info) - use person_city from personal info + city: values.person_city || values.city || "", + // city_name is for guild info + city_name: values.city_name || "", + // province is stored as ID when selected, or as name from state field + province: values.province || "", address: values.address || "", postalcode: values.postal_code || "", licenseNumber: values.license_number || "", @@ -177,7 +182,8 @@ export const mapResponseDataToFormFields = ( ? guildData.isicname || "" : firstGuild.areaActivity || "", state: isExternalApi ? guildData.state || "" : provinceData.name || "", - city: isExternalApi ? guildData.city || "" : cityData.name || "", + province: isExternalApi ? "" : provinceData.key || "", + city: isExternalApi ? guildData.city || "" : cityData.key || "", address: isExternalApi ? guildData.address || "" : addressData.address || "", diff --git a/src/features/province/components/create-guilds/utils/formUtils.js b/src/features/province/components/create-guilds/utils/formUtils.js index 8287371..a97ec4e 100644 --- a/src/features/province/components/create-guilds/utils/formUtils.js +++ b/src/features/province/components/create-guilds/utils/formUtils.js @@ -43,6 +43,27 @@ export const getValidationSchema = (isEditMode) => return val === true; }) .required("این فیلد اجباری است!"), + guilds: yup + .array() + .min(1, "حداقل یک واحد صنفی باید وجود داشته باشد") + .of( + yup.object({ + steward: yup.boolean().default(false), + guild: yup.boolean().default(false), + }) + ) + .test( + "steward-guild-required", + "برای هر واحد صنفی، حداقل یکی از گزینه‌های مباشر یا صنف باید انتخاب شود", + function (guilds) { + if (!guilds || guilds.length === 0) { + return false; + } + return guilds.every( + (guild) => guild?.steward === true || guild?.guild === true + ); + } + ), }); export const getInitialValues = (guild) => ({ @@ -56,10 +77,11 @@ export const getInitialValues = (guild) => ({ gender: guild?.user?.gender || "", person_city: guild?.user?.city || "", is_alive: guild?.user?.isAlive || "", - guild_name: guild?.guildsName || "", + guild_name: guild?.guildsName || guild?.name || "", area_activity: guild?.areaActivity || "", state: guild?.address?.province?.name || "", - city: guild?.address?.city?.name || "", + province: guild?.address?.province?.key || "", + city_name: guild?.address?.city?.name || "", address: guild?.address?.address || "", license_expire_date: normalizeDatabaseDate(guild?.licenseExpireDate || ""), license_status: guild?.licenseStatus || "", @@ -92,4 +114,22 @@ export const getInitialValues = (guild) => ({ company_identifier: guild?.companyIdentifier || "", type_activity_name: guild?.typeActivityName || "", active: guild?.active ?? null, + guilds: guild + ? [ + { + steward: + typeof guild?.steward === "boolean" + ? guild.steward + : typeof guild?.isSteward === "boolean" + ? guild.isSteward + : false, + guild: + typeof guild?.guild === "boolean" + ? guild.guild + : typeof guild?.isGuild === "boolean" + ? guild.isGuild + : false, + }, + ] + : [], }); diff --git a/src/features/province/components/manage-guilds-requests/ManageGuildsRequests.js b/src/features/province/components/manage-guilds-requests/ManageGuildsRequests.js index 1415d7b..4563a2a 100644 --- a/src/features/province/components/manage-guilds-requests/ManageGuildsRequests.js +++ b/src/features/province/components/manage-guilds-requests/ManageGuildsRequests.js @@ -1,8 +1,9 @@ import React, { useEffect, useState } from "react"; -import { Button, TextField } from "@mui/material"; +import { Button, TextField, Typography } from "@mui/material"; import { useDispatch } from "react-redux"; import { RiSearchLine } from "react-icons/ri"; import { + CLOSE_MODAL, LOADING_END, LOADING_START, OPEN_MODAL, @@ -14,6 +15,8 @@ import { ManageGuildsRequestsOperations } from "../manage-guilds-requests-operat import { CreateGuilds } from "../create-guilds/CreateGuilds"; import { provinceGetTotalGuildsService } from "../../services/province-get-total-guilds"; import { provinceGetTotalStewardsService } from "../../services/province-get-total-stewards"; +import { formatTime } from "../../../../utils/formatTime"; +import { ProvinceLegalGuildsForm } from "../province-legal-guilds-in-province/ProvinceLegalGuildsForm"; export const ManageGuildsRequests = ({ userType }) => { const IS_STEWARD = userType === "steward"; @@ -76,6 +79,7 @@ export const ManageGuildsRequests = ({ userType }) => { const d = data?.map((item, i) => { return [ page === 1 ? i + 1 : i + perPage * (page - 1) + 1, + formatTime(item?.createDate) || "-", `${item?.registerarFullname || ""} ${ item?.registerarMobile ? "(" + item?.registerarMobile + " )" : " " }`, @@ -130,7 +134,9 @@ export const ManageGuildsRequests = ({ userType }) => { dispatch(LOADING_END()); } }; - + { + /* */ + } return ( { OPEN_MODAL({ title: `ثبت ${IS_STEWARD ? "مباشر" : "صنف"} جدید`, size: window.innerWidth <= 600 ? "small" : "auto", - content: , + content: ( + + + {`نوع ${ + IS_STEWARD ? "مباشر" : "صنف" + }:`} + + + + + + + ), }) ); }} > - {`ثبت ${IS_STEWARD ? "مباشر" : "صنف"} جدید`} + {`ثبت ${IS_STEWARD ? "مباشر" : "صنف"}`} )} @@ -182,6 +247,7 @@ export const ManageGuildsRequests = ({ userType }) => { data={tableData} columns={[ "ردیف", + "تاریخ ثبت", "ثبت کننده", `شناسه ${IS_STEWARD ? "مباشر" : "صنف"}`, `نام ${IS_STEWARD ? "مباشر" : "واحد صنفی"}`, diff --git a/src/features/province/components/manage-guilds/ManageGuilds.js b/src/features/province/components/manage-guilds/ManageGuilds.js index ce6ae3d..f5e539f 100644 --- a/src/features/province/components/manage-guilds/ManageGuilds.js +++ b/src/features/province/components/manage-guilds/ManageGuilds.js @@ -14,6 +14,7 @@ import { SimpleTable } from "../../../../components/simple-table/SimpleTable"; import { CreateGuilds } from "../create-guilds/CreateGuilds"; import { checkPathStartsWith } from "../../../../utils/checkPathStartsWith"; import { provinceGetTotalStewardsService } from "../../services/province-get-total-stewards"; +import { formatTime } from "../../../../utils/formatTime"; export const ManageGuilds = ({ userType }) => { const IS_STEWARD = userType === "steward"; @@ -100,6 +101,10 @@ export const ManageGuilds = ({ userType }) => { const d = data.map((item, i) => { const commonData = [ page === 1 ? i + 1 : i + perPage * (page - 1) + 1, + formatTime(item?.createDate) || "-", + `${item?.registerarFullname || ""} ${ + item?.registerarMobile ? "(" + item?.registerarMobile + " )" : " " + }`, item?.licenseNumber || "-", (IS_STEWARD ? item?.name : item?.guildsName) || "-", `${item?.user?.fullname || "-"} (${item?.user?.mobile || "-"})`, @@ -268,24 +273,22 @@ export const ManageGuilds = ({ userType }) => { > - {["KillHouse", "GuildRoom"].includes(getRoleFromUrl()) && ( - - )} + { getRoleFromUrl() === "CityJahad" || getRoleFromUrl() === "CityPoultry" ? [ "ردیف", + "تاریخ ثبت", + "ثبت کننده", IS_STEWARD ? "شناسه مباشر" : "شناسه صنف", "نام واحد صنفی", "نام شخص/شرکت", @@ -381,6 +386,8 @@ export const ManageGuilds = ({ userType }) => { : getRoleFromUrl() === "KillHouse" ? [ "ردیف", + "تاریخ ثبت", + "ثبت کننده", IS_STEWARD ? "شناسه مباشر" : "شناسه صنف", "نام واحد صنفی", "نام شخص/شرکت", @@ -400,6 +407,8 @@ export const ManageGuilds = ({ userType }) => { ] : [ "ردیف", + "تاریخ ثبت", + "ثبت کننده", IS_STEWARD ? "شناسه مباشر" : "شناسه صنف", "نام واحد صنفی", "نام شخص/شرکت", diff --git a/src/features/province/components/province-legal-guilds-in-province/ProvinceLegalGuildsForm.js b/src/features/province/components/province-legal-guilds-in-province/ProvinceLegalGuildsForm.js index 683fec6..9ba31a2 100644 --- a/src/features/province/components/province-legal-guilds-in-province/ProvinceLegalGuildsForm.js +++ b/src/features/province/components/province-legal-guilds-in-province/ProvinceLegalGuildsForm.js @@ -90,30 +90,27 @@ const InfoBox = ({ icon: Icon, label, value, iconSx }) => ( ); -const getValidationSchema = (isAdmin, userFound) => +const getValidationSchema = () => yup.object({ national_id: yup .string() .required("شناسه حقوقی الزامی است") .matches(/^[0-9]{11}$/, "شناسه حقوقی باید 11 رقم باشد"), - first_name: yup.string(), - last_name: yup.string(), + first_name: yup.string().required("نام اجباری است."), + last_name: yup.string().required("نام خانوادگی اجباری است."), unit_name: yup.string(), name: yup.string(), province: yup.string(), city: yup.string(), - mobile: - isAdmin || !userFound - ? yup - .string() - .nullable() - .test( - "mobile-format", - "شماره تلفن باید 11 رقم باشد", - (value) => !value || /^[0-9]{11}$/.test(value) - ) - : yup.string(), - type_activity: yup.string(), + mobile: yup + .string() + .test( + "mobile-format", + "شماره تلفن باید 11 رقم باشد", + (value) => !value || /^[0-9]{11}$/.test(value) + ) + .required("شماره موبایل اجباری است."), + type_activity: yup.string().required("نوع فعالیت اجباری است."), }); const LegalGuildForm = ({ @@ -125,7 +122,7 @@ const LegalGuildForm = ({ cities, }) => { const IS_STEWARD = userType === "steward"; - + const IS_ADMIN = getRoleFromUrl() === "AdminX"; return ( @@ -146,7 +143,7 @@ const LegalGuildForm = ({ error={Boolean(formik.errors.national_id)} helperText={formik.errors.national_id} inputProps={{ maxLength: 11 }} - disabled={true} + disabled={!IS_ADMIN} /> ) : ( { // Find type_activity key from the title const typeActivityObj = typeActivities.find( diff --git a/src/features/province/components/province-legal-guilds-in-province/ProvinceLegalGuildsInProvince.js b/src/features/province/components/province-legal-guilds-in-province/ProvinceLegalGuildsInProvince.js index 8e6c19c..8ee90bc 100644 --- a/src/features/province/components/province-legal-guilds-in-province/ProvinceLegalGuildsInProvince.js +++ b/src/features/province/components/province-legal-guilds-in-province/ProvinceLegalGuildsInProvince.js @@ -11,6 +11,7 @@ import ResponsiveTable from "../../../../components/responsive-table/ResponsiveT import { RiSearchLine } from "react-icons/ri"; import { provinceGetTotalStewardsService } from "../../services/province-get-total-stewards"; import { checkPathStartsWith } from "../../../../utils/checkPathStartsWith"; +import { formatTime } from "../../../../utils/formatTime"; export const ProvinceLegalGuildsInProvince = ({ userType }) => { const IS_STEWARD = userType === "steward"; @@ -85,6 +86,10 @@ export const ProvinceLegalGuildsInProvince = ({ userType }) => { const d = data.map((item, i) => { return [ page === 1 ? i + 1 : i + perPage * (page - 1) + 1, + formatTime(item?.createDate) || "-", + `${item?.registerarFullname || ""} ${ + item?.registerarMobile ? "(" + item?.registerarMobile + " )" : " " + }`, (IS_STEWARD ? item?.licenseNumber : item?.nationalId) || "-", (IS_STEWARD ? item?.name : item?.guildsName) || "-", `${item?.user?.fullname || "-"}`, @@ -195,6 +200,8 @@ export const ProvinceLegalGuildsInProvince = ({ userType }) => { title={TABLE_TITLE} columns={[ "ردیف", + "تاریخ ثبت", + "ثبت کننده", "شناسه حقوقی", "نام واحد", "نام و نام خانوادگی",