add services for edit and delete out guilds
This commit is contained in:
@@ -10,6 +10,7 @@ import { Grid } from "../../../../components/grid/Grid";
|
|||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { RiSearchLine } from "react-icons/ri";
|
import { RiSearchLine } from "react-icons/ri";
|
||||||
import { fetchOutProvinceLegalBuyers } from "../../services/province-out-province-buyers";
|
import { fetchOutProvinceLegalBuyers } from "../../services/province-out-province-buyers";
|
||||||
|
import { ProvinceTrueGuildsOutProvinceOperations } from "../province-true-guilds-out-province/ProvinceTrueGuildsOutProvinceOperations";
|
||||||
|
|
||||||
export const ProvinceLegalGuildsOutProvince = () => {
|
export const ProvinceLegalGuildsOutProvince = () => {
|
||||||
const handleTextChange = (event) => {
|
const handleTextChange = (event) => {
|
||||||
@@ -73,6 +74,11 @@ export const ProvinceLegalGuildsOutProvince = () => {
|
|||||||
item?.requestsInfo?.numberOfRequests?.toLocaleString() || "0",
|
item?.requestsInfo?.numberOfRequests?.toLocaleString() || "0",
|
||||||
item?.requestsInfo?.totalQuantity?.toLocaleString() || "0",
|
item?.requestsInfo?.totalQuantity?.toLocaleString() || "0",
|
||||||
item?.requestsInfo?.totalWeight?.toLocaleString() || "0",
|
item?.requestsInfo?.totalWeight?.toLocaleString() || "0",
|
||||||
|
<ProvinceTrueGuildsOutProvinceOperations
|
||||||
|
key={item?.unitName}
|
||||||
|
item={item}
|
||||||
|
updateTable={() => fetchApiData(1)}
|
||||||
|
/>,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -132,6 +138,7 @@ export const ProvinceLegalGuildsOutProvince = () => {
|
|||||||
"تعداد درخواست ها",
|
"تعداد درخواست ها",
|
||||||
"حجم تقریبی (قطعه)",
|
"حجم تقریبی (قطعه)",
|
||||||
"وزن (کیلوگرم)",
|
"وزن (کیلوگرم)",
|
||||||
|
"عملیات",
|
||||||
]}
|
]}
|
||||||
handlePageChange={handlePageChange}
|
handlePageChange={handlePageChange}
|
||||||
totalRows={totalRows}
|
totalRows={totalRows}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { Grid } from "../../../../components/grid/Grid";
|
|||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { RiSearchLine } from "react-icons/ri";
|
import { RiSearchLine } from "react-icons/ri";
|
||||||
import { fetchOutProvinceRealBuyers } from "../../services/province-out-province-buyers";
|
import { fetchOutProvinceRealBuyers } from "../../services/province-out-province-buyers";
|
||||||
|
import { ProvinceTrueGuildsOutProvinceOperations } from "./ProvinceTrueGuildsOutProvinceOperations";
|
||||||
|
|
||||||
export const ProvinceTrueGuildsOutProvince = () => {
|
export const ProvinceTrueGuildsOutProvince = () => {
|
||||||
const handleTextChange = (event) => {
|
const handleTextChange = (event) => {
|
||||||
@@ -72,6 +73,11 @@ export const ProvinceTrueGuildsOutProvince = () => {
|
|||||||
item?.requestsInfo?.numberOfRequests?.toLocaleString() || "0",
|
item?.requestsInfo?.numberOfRequests?.toLocaleString() || "0",
|
||||||
item?.requestsInfo?.totalQuantity?.toLocaleString() || "0",
|
item?.requestsInfo?.totalQuantity?.toLocaleString() || "0",
|
||||||
item?.requestsInfo?.totalWeight?.toLocaleString() || "0",
|
item?.requestsInfo?.totalWeight?.toLocaleString() || "0",
|
||||||
|
<ProvinceTrueGuildsOutProvinceOperations
|
||||||
|
key={item?.unitName}
|
||||||
|
item={item}
|
||||||
|
updateTable={() => fetchApiData(1)}
|
||||||
|
/>,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -131,6 +137,7 @@ export const ProvinceTrueGuildsOutProvince = () => {
|
|||||||
"تعداد درخواست ها",
|
"تعداد درخواست ها",
|
||||||
"حجم تقریبی (قطعه)",
|
"حجم تقریبی (قطعه)",
|
||||||
"وزن (کیلوگرم)",
|
"وزن (کیلوگرم)",
|
||||||
|
"عملیات",
|
||||||
]}
|
]}
|
||||||
handlePageChange={handlePageChange}
|
handlePageChange={handlePageChange}
|
||||||
totalRows={totalRows}
|
totalRows={totalRows}
|
||||||
|
|||||||
@@ -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 (
|
||||||
|
<Grid container>
|
||||||
|
<IconButton
|
||||||
|
aria-describedby={id}
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={handleClick}
|
||||||
|
>
|
||||||
|
<TuneIcon />
|
||||||
|
</IconButton>
|
||||||
|
<Popover
|
||||||
|
anchorOrigin={{
|
||||||
|
vertical: "bottom",
|
||||||
|
horizontal: "right",
|
||||||
|
}}
|
||||||
|
transformOrigin={{
|
||||||
|
vertical: "top",
|
||||||
|
horizontal: "left",
|
||||||
|
}}
|
||||||
|
id={id}
|
||||||
|
open={open}
|
||||||
|
anchorEl={anchorEl}
|
||||||
|
onClose={handleClose}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
padding: "10px",
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Grid container direction="column">
|
||||||
|
<Tooltip title="ویرایش" placement="right">
|
||||||
|
<IconButton
|
||||||
|
color="primary"
|
||||||
|
onClick={() => {
|
||||||
|
handleClose();
|
||||||
|
dispatch(
|
||||||
|
DRAWER({
|
||||||
|
title: "ویرایش واحد",
|
||||||
|
right: !(window.innerWidth <= 600),
|
||||||
|
bottom: window.innerWidth <= 600,
|
||||||
|
content: (
|
||||||
|
<SlaughterSellCarcassOutProvinceAddBuyer
|
||||||
|
updateTable={updateTable}
|
||||||
|
isEdit
|
||||||
|
data={item}
|
||||||
|
defaultPersonType={
|
||||||
|
item?.buyer?.parentLegalPersonNationalCode
|
||||||
|
? "legal"
|
||||||
|
: "real"
|
||||||
|
}
|
||||||
|
defaultNationalCode={item?.buyer?.nationalCode}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<EditIcon />
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip title="حذف" placement="right">
|
||||||
|
<IconButton
|
||||||
|
color="error"
|
||||||
|
onClick={() => {
|
||||||
|
handleClose();
|
||||||
|
dispatch(
|
||||||
|
OPEN_MODAL({
|
||||||
|
title: "آیا مطمئن هستید؟",
|
||||||
|
size: "auto",
|
||||||
|
content: (
|
||||||
|
<Grid
|
||||||
|
container
|
||||||
|
sx={{
|
||||||
|
width: "300px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
color="error"
|
||||||
|
sx={{
|
||||||
|
flex: 1,
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
dispatch(CLOSE_MODAL());
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
لغو
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="error"
|
||||||
|
sx={{
|
||||||
|
flex: 1,
|
||||||
|
}}
|
||||||
|
onClick={() => deleteGuild()}
|
||||||
|
>
|
||||||
|
تایید
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DeleteIcon />
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
</Grid>
|
||||||
|
</div>
|
||||||
|
</Popover>
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -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 };
|
||||||
|
}
|
||||||
|
);
|
||||||
@@ -76,9 +76,12 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({
|
|||||||
city: Yup.string()
|
city: Yup.string()
|
||||||
.required("این فیلد اجباری است!")
|
.required("این فیلد اجباری است!")
|
||||||
.typeError("لطفا فیلد را به درستی وارد کنید!"),
|
.typeError("لطفا فیلد را به درستی وارد کنید!"),
|
||||||
nationalId: Yup.string()
|
nationalId:
|
||||||
.required("این فیلد اجباری است!")
|
defaultPersonType === "legal" && isEdit
|
||||||
.matches(/^\d{10,11}$/, "شناسه باید 10 یا 11 رقم و فقط عدد باشد"),
|
? Yup.string().nullable()
|
||||||
|
: Yup.string()
|
||||||
|
.required("این فیلد اجباری است!")
|
||||||
|
.matches(/^\d{10,11}$/, "شناسه باید 10 یا 11 رقم و فقط عدد باشد"),
|
||||||
}),
|
}),
|
||||||
validateOnMount: true,
|
validateOnMount: true,
|
||||||
});
|
});
|
||||||
@@ -90,21 +93,27 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({
|
|||||||
},
|
},
|
||||||
validationSchema: Yup.object({
|
validationSchema: Yup.object({
|
||||||
personType: Yup.string().oneOf(["real", "legal"]).required(),
|
personType: Yup.string().oneOf(["real", "legal"]).required(),
|
||||||
nationalCode: Yup.string()
|
nationalCode:
|
||||||
.required("این فیلد اجباری است!")
|
isEdit && defaultPersonType === "real"
|
||||||
.when("personType", {
|
? Yup.string().nullable()
|
||||||
is: "real",
|
: Yup.string()
|
||||||
then: (schema) =>
|
.required("این فیلد اجباری است!")
|
||||||
schema
|
.when("personType", {
|
||||||
.length(10, "کد ملی باید 10 رقم باشد")
|
is: "real",
|
||||||
.matches(/^\d{10}$/, "کد ملی باید فقط شامل اعداد باشد"),
|
then: (schema) =>
|
||||||
otherwise: (schema) =>
|
schema
|
||||||
schema
|
.length(10, "کد ملی باید 10 رقم باشد")
|
||||||
.length(11, "شناسه ملی حقوقی باید 11 رقم باشد")
|
.matches(/^\d{10}$/, "کد ملی باید فقط شامل اعداد باشد"),
|
||||||
.matches(/^\d{11}$/, "شناسه ملی حقوقی باید فقط شامل اعداد باشد"),
|
otherwise: (schema) =>
|
||||||
}),
|
schema
|
||||||
|
.length(11, "شناسه ملی حقوقی باید 11 رقم باشد")
|
||||||
|
.matches(
|
||||||
|
/^\d{11}$/,
|
||||||
|
"شناسه ملی حقوقی باید فقط شامل اعداد باشد"
|
||||||
|
),
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
validateOnMount: true,
|
validateOnMount: isEdit ? false : true,
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -404,74 +413,86 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({
|
|||||||
direction="column"
|
direction="column"
|
||||||
gap={2}
|
gap={2}
|
||||||
>
|
>
|
||||||
<Grid container xs={12}>
|
{!isEdit && (
|
||||||
<LabelField label="نوع شخص">
|
<Grid container xs={12}>
|
||||||
<RadioGroup
|
<LabelField label="نوع شخص">
|
||||||
row
|
<RadioGroup
|
||||||
name="personType"
|
row
|
||||||
value={formik2.values.personType}
|
name="personType"
|
||||||
onChange={(e) => {
|
value={formik2.values.personType}
|
||||||
const value = e.target.value;
|
onChange={(e) => {
|
||||||
formik2.setFieldValue("personType", value);
|
const value = e.target.value;
|
||||||
// reset previous results when toggling type
|
formik2.setFieldValue("personType", value);
|
||||||
setUserData(null);
|
// reset previous results when toggling type
|
||||||
setNotFound(false);
|
setUserData(null);
|
||||||
setLockedFields({});
|
setNotFound(false);
|
||||||
formik.resetForm({
|
setLockedFields({});
|
||||||
values: {
|
formik.resetForm({
|
||||||
mobile: "",
|
values: {
|
||||||
firstName: "",
|
mobile: "",
|
||||||
lastName: "",
|
firstName: "",
|
||||||
unitName: "",
|
lastName: "",
|
||||||
province: "",
|
unitName: "",
|
||||||
city: "",
|
province: "",
|
||||||
nationalId: "",
|
city: "",
|
||||||
},
|
nationalId: "",
|
||||||
});
|
},
|
||||||
}}
|
});
|
||||||
>
|
}}
|
||||||
<FormControlLabel value="real" control={<Radio />} label="حقیقی" />
|
>
|
||||||
<FormControlLabel value="legal" control={<Radio />} label="حقوقی" />
|
<FormControlLabel
|
||||||
</RadioGroup>
|
value="real"
|
||||||
</LabelField>
|
control={<Radio />}
|
||||||
<Typography mt={2}>
|
label="حقیقی"
|
||||||
{"استعلام "}
|
/>
|
||||||
{formik2.values.personType === "legal" ? "شناسه ملی حقوقی" : "کد ملی"}
|
<FormControlLabel
|
||||||
</Typography>
|
value="legal"
|
||||||
<Grid mt={SPACING.SMALL} display="flex" width={1}>
|
control={<Radio />}
|
||||||
<TextField
|
label="حقوقی"
|
||||||
fullWidth
|
/>
|
||||||
id="nationalCode"
|
</RadioGroup>
|
||||||
name="nationalCode"
|
</LabelField>
|
||||||
label={
|
<Typography mt={2}>
|
||||||
formik2.values.personType === "legal"
|
{"استعلام "}
|
||||||
? "شناسه ملی حقوقی"
|
{formik2.values.personType === "legal"
|
||||||
: "کد ملی"
|
? "شناسه ملی حقوقی"
|
||||||
}
|
: "کد ملی"}
|
||||||
variant="outlined"
|
</Typography>
|
||||||
value={formik2.values.nationalCode}
|
<Grid mt={SPACING.SMALL} display="flex" width={1}>
|
||||||
error={Boolean(
|
<TextField
|
||||||
formik2.touched.nationalCode && formik2.errors.nationalCode
|
fullWidth
|
||||||
)}
|
id="nationalCode"
|
||||||
onChange={formik2.handleChange}
|
name="nationalCode"
|
||||||
onBlur={formik2.handleBlur}
|
label={
|
||||||
helperText={
|
formik2.values.personType === "legal"
|
||||||
formik2.touched.nationalCode && formik2.errors.nationalCode
|
? "شناسه ملی حقوقی"
|
||||||
}
|
: "کد ملی"
|
||||||
inputProps={{
|
}
|
||||||
maxLength: formik2.values.personType === "legal" ? 11 : 10,
|
variant="outlined"
|
||||||
}}
|
value={formik2.values.nationalCode}
|
||||||
/>
|
error={Boolean(
|
||||||
<IconButton
|
formik2.touched.nationalCode && formik2.errors.nationalCode
|
||||||
disabled={!formik2.isValid || inquiryInProgress}
|
)}
|
||||||
aria-label="search"
|
onChange={formik2.handleChange}
|
||||||
color="primary"
|
onBlur={formik2.handleBlur}
|
||||||
onClick={handleNationalInquiry}
|
helperText={
|
||||||
>
|
formik2.touched.nationalCode && formik2.errors.nationalCode
|
||||||
<SearchIcon />
|
}
|
||||||
</IconButton>
|
inputProps={{
|
||||||
|
maxLength: formik2.values.personType === "legal" ? 11 : 10,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<IconButton
|
||||||
|
disabled={!formik2.isValid || inquiryInProgress}
|
||||||
|
aria-label="search"
|
||||||
|
color="primary"
|
||||||
|
onClick={handleNationalInquiry}
|
||||||
|
>
|
||||||
|
<SearchIcon />
|
||||||
|
</IconButton>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
)}
|
||||||
|
|
||||||
{userData || notFound || isEdit ? (
|
{userData || notFound || isEdit ? (
|
||||||
<Grid
|
<Grid
|
||||||
|
|||||||
Reference in New Issue
Block a user