From 4e0c45e59585c25b5a581a3e186ec9b8d8d89a1f Mon Sep 17 00:00:00 2001 From: workashrafi77-web Date: Tue, 20 Jan 2026 12:38:07 +0330 Subject: [PATCH] add services for edit and delete out guilds --- .../ProvinceLegalGuildsOutProvince.js | 7 + .../ProvinceTrueGuildsOutProvince.js | 7 + ...ProvinceTrueGuildsOutProvinceOperations.js | 155 ++++++++++++++ .../delete-out-province-true-guilds.js | 15 ++ ...SlaughterSellCarcassOutProvinceAddBuyer.js | 189 ++++++++++-------- 5 files changed, 289 insertions(+), 84 deletions(-) create mode 100644 src/features/province/components/province-true-guilds-out-province/ProvinceTrueGuildsOutProvinceOperations.js create mode 100644 src/features/province/services/delete-out-province-true-guilds.js diff --git a/src/features/province/components/province-legal-guilds-out-province/ProvinceLegalGuildsOutProvince.js b/src/features/province/components/province-legal-guilds-out-province/ProvinceLegalGuildsOutProvince.js index 3962807..4dcb27a 100644 --- a/src/features/province/components/province-legal-guilds-out-province/ProvinceLegalGuildsOutProvince.js +++ b/src/features/province/components/province-legal-guilds-out-province/ProvinceLegalGuildsOutProvince.js @@ -10,6 +10,7 @@ import { Grid } from "../../../../components/grid/Grid"; import { useDispatch } from "react-redux"; import { RiSearchLine } from "react-icons/ri"; import { fetchOutProvinceLegalBuyers } from "../../services/province-out-province-buyers"; +import { ProvinceTrueGuildsOutProvinceOperations } from "../province-true-guilds-out-province/ProvinceTrueGuildsOutProvinceOperations"; export const ProvinceLegalGuildsOutProvince = () => { const handleTextChange = (event) => { @@ -73,6 +74,11 @@ export const ProvinceLegalGuildsOutProvince = () => { item?.requestsInfo?.numberOfRequests?.toLocaleString() || "0", item?.requestsInfo?.totalQuantity?.toLocaleString() || "0", item?.requestsInfo?.totalWeight?.toLocaleString() || "0", + fetchApiData(1)} + />, ]; }); @@ -132,6 +138,7 @@ export const ProvinceLegalGuildsOutProvince = () => { "تعداد درخواست ها", "حجم تقریبی (قطعه)", "وزن (کیلوگرم)", + "عملیات", ]} handlePageChange={handlePageChange} totalRows={totalRows} diff --git a/src/features/province/components/province-true-guilds-out-province/ProvinceTrueGuildsOutProvince.js b/src/features/province/components/province-true-guilds-out-province/ProvinceTrueGuildsOutProvince.js index bf88486..f9e04eb 100644 --- a/src/features/province/components/province-true-guilds-out-province/ProvinceTrueGuildsOutProvince.js +++ b/src/features/province/components/province-true-guilds-out-province/ProvinceTrueGuildsOutProvince.js @@ -10,6 +10,7 @@ import { Grid } from "../../../../components/grid/Grid"; import { useDispatch } from "react-redux"; import { RiSearchLine } from "react-icons/ri"; import { fetchOutProvinceRealBuyers } from "../../services/province-out-province-buyers"; +import { ProvinceTrueGuildsOutProvinceOperations } from "./ProvinceTrueGuildsOutProvinceOperations"; export const ProvinceTrueGuildsOutProvince = () => { const handleTextChange = (event) => { @@ -72,6 +73,11 @@ export const ProvinceTrueGuildsOutProvince = () => { item?.requestsInfo?.numberOfRequests?.toLocaleString() || "0", item?.requestsInfo?.totalQuantity?.toLocaleString() || "0", item?.requestsInfo?.totalWeight?.toLocaleString() || "0", + fetchApiData(1)} + />, ]; }); @@ -131,6 +137,7 @@ export const ProvinceTrueGuildsOutProvince = () => { "تعداد درخواست ها", "حجم تقریبی (قطعه)", "وزن (کیلوگرم)", + "عملیات", ]} handlePageChange={handlePageChange} totalRows={totalRows} diff --git a/src/features/province/components/province-true-guilds-out-province/ProvinceTrueGuildsOutProvinceOperations.js b/src/features/province/components/province-true-guilds-out-province/ProvinceTrueGuildsOutProvinceOperations.js new file mode 100644 index 0000000..82b99c0 --- /dev/null +++ b/src/features/province/components/province-true-guilds-out-province/ProvinceTrueGuildsOutProvinceOperations.js @@ -0,0 +1,155 @@ +import { useState } from "react"; +import { useDispatch } from "react-redux"; +import { Grid } from "../../../../components/grid/Grid"; +import TuneIcon from "@mui/icons-material/Tune"; +import { Button, IconButton, Popover, Tooltip } from "@mui/material"; +import { + CLOSE_MODAL, + DRAWER, + OPEN_MODAL, +} from "../../../../lib/redux/slices/appSlice"; +import EditIcon from "@mui/icons-material/Edit"; +import DeleteIcon from "@mui/icons-material/Delete"; +import { deleteOutProvinceTrueGuilds } from "../../services/delete-out-province-true-guilds"; +import { SlaughterSellCarcassOutProvinceAddBuyer } from "../../../slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer"; + +export const ProvinceTrueGuildsOutProvinceOperations = ({ + item, + updateTable, +}) => { + const dispatch = useDispatch(); + + const [anchorEl, setAnchorEl] = useState(null); + + const handleClick = (event) => { + setAnchorEl(event.currentTarget); + }; + + const handleClose = () => { + setAnchorEl(null); + }; + + const open = Boolean(anchorEl); + const id = open ? "popover" : undefined; + + const deleteGuild = () => { + const buyerKey = item?.key; + if (buyerKey) + dispatch(deleteOutProvinceTrueGuilds({ buyer_key: buyerKey })).then(() => + dispatch(CLOSE_MODAL()) + ); + }; + return ( + + + + + +
+ + + { + handleClose(); + dispatch( + DRAWER({ + title: "ویرایش واحد", + right: !(window.innerWidth <= 600), + bottom: window.innerWidth <= 600, + content: ( + + ), + }) + ); + }} + > + + + + + { + handleClose(); + dispatch( + OPEN_MODAL({ + title: "آیا مطمئن هستید؟", + size: "auto", + content: ( + + + + + ), + }) + ); + }} + > + + + + +
+
+
+ ); +}; diff --git a/src/features/province/services/delete-out-province-true-guilds.js b/src/features/province/services/delete-out-province-true-guilds.js new file mode 100644 index 0000000..e84d9b7 --- /dev/null +++ b/src/features/province/services/delete-out-province-true-guilds.js @@ -0,0 +1,15 @@ +import { createAsyncThunk } from "@reduxjs/toolkit"; +import axios from "axios"; + +export const deleteOutProvinceTrueGuilds = createAsyncThunk( + "DELETE_OUT_PROVINCE_TRUE_GUILDS", + async (d) => { + const { data, status } = await axios.delete( + "out-province-carcasses-buyer/0", + { + params: { buyer_key: d.buyer_key }, + } + ); + return { data, status }; + } +); diff --git a/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer.js b/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer.js index d03f0aa..e2f998d 100644 --- a/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer.js +++ b/src/features/slaughter-house/components/slaughter-sell-carcass-out-province-add-buyer/SlaughterSellCarcassOutProvinceAddBuyer.js @@ -76,9 +76,12 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({ city: Yup.string() .required("این فیلد اجباری است!") .typeError("لطفا فیلد را به درستی وارد کنید!"), - nationalId: Yup.string() - .required("این فیلد اجباری است!") - .matches(/^\d{10,11}$/, "شناسه باید 10 یا 11 رقم و فقط عدد باشد"), + nationalId: + defaultPersonType === "legal" && isEdit + ? Yup.string().nullable() + : Yup.string() + .required("این فیلد اجباری است!") + .matches(/^\d{10,11}$/, "شناسه باید 10 یا 11 رقم و فقط عدد باشد"), }), validateOnMount: true, }); @@ -90,21 +93,27 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({ }, validationSchema: Yup.object({ personType: Yup.string().oneOf(["real", "legal"]).required(), - nationalCode: Yup.string() - .required("این فیلد اجباری است!") - .when("personType", { - is: "real", - then: (schema) => - schema - .length(10, "کد ملی باید 10 رقم باشد") - .matches(/^\d{10}$/, "کد ملی باید فقط شامل اعداد باشد"), - otherwise: (schema) => - schema - .length(11, "شناسه ملی حقوقی باید 11 رقم باشد") - .matches(/^\d{11}$/, "شناسه ملی حقوقی باید فقط شامل اعداد باشد"), - }), + nationalCode: + isEdit && defaultPersonType === "real" + ? Yup.string().nullable() + : Yup.string() + .required("این فیلد اجباری است!") + .when("personType", { + is: "real", + then: (schema) => + schema + .length(10, "کد ملی باید 10 رقم باشد") + .matches(/^\d{10}$/, "کد ملی باید فقط شامل اعداد باشد"), + otherwise: (schema) => + schema + .length(11, "شناسه ملی حقوقی باید 11 رقم باشد") + .matches( + /^\d{11}$/, + "شناسه ملی حقوقی باید فقط شامل اعداد باشد" + ), + }), }), - validateOnMount: true, + validateOnMount: isEdit ? false : true, }); useEffect(() => { @@ -404,74 +413,86 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({ direction="column" gap={2} > - - - { - const value = e.target.value; - formik2.setFieldValue("personType", value); - // reset previous results when toggling type - setUserData(null); - setNotFound(false); - setLockedFields({}); - formik.resetForm({ - values: { - mobile: "", - firstName: "", - lastName: "", - unitName: "", - province: "", - city: "", - nationalId: "", - }, - }); - }} - > - } label="حقیقی" /> - } label="حقوقی" /> - - - - {"استعلام "} - {formik2.values.personType === "legal" ? "شناسه ملی حقوقی" : "کد ملی"} - - - - - - + {!isEdit && ( + + + { + const value = e.target.value; + formik2.setFieldValue("personType", value); + // reset previous results when toggling type + setUserData(null); + setNotFound(false); + setLockedFields({}); + formik.resetForm({ + values: { + mobile: "", + firstName: "", + lastName: "", + unitName: "", + province: "", + city: "", + nationalId: "", + }, + }); + }} + > + } + label="حقیقی" + /> + } + label="حقوقی" + /> + + + + {"استعلام "} + {formik2.values.personType === "legal" + ? "شناسه ملی حقوقی" + : "کد ملی"} + + + + + + + - + )} {userData || notFound || isEdit ? (