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 { 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",
|
||||
<ProvinceTrueGuildsOutProvinceOperations
|
||||
key={item?.unitName}
|
||||
item={item}
|
||||
updateTable={() => fetchApiData(1)}
|
||||
/>,
|
||||
];
|
||||
});
|
||||
|
||||
@@ -132,6 +138,7 @@ export const ProvinceLegalGuildsOutProvince = () => {
|
||||
"تعداد درخواست ها",
|
||||
"حجم تقریبی (قطعه)",
|
||||
"وزن (کیلوگرم)",
|
||||
"عملیات",
|
||||
]}
|
||||
handlePageChange={handlePageChange}
|
||||
totalRows={totalRows}
|
||||
|
||||
@@ -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",
|
||||
<ProvinceTrueGuildsOutProvinceOperations
|
||||
key={item?.unitName}
|
||||
item={item}
|
||||
updateTable={() => fetchApiData(1)}
|
||||
/>,
|
||||
];
|
||||
});
|
||||
|
||||
@@ -131,6 +137,7 @@ export const ProvinceTrueGuildsOutProvince = () => {
|
||||
"تعداد درخواست ها",
|
||||
"حجم تقریبی (قطعه)",
|
||||
"وزن (کیلوگرم)",
|
||||
"عملیات",
|
||||
]}
|
||||
handlePageChange={handlePageChange}
|
||||
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()
|
||||
.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}
|
||||
>
|
||||
<Grid container xs={12}>
|
||||
<LabelField label="نوع شخص">
|
||||
<RadioGroup
|
||||
row
|
||||
name="personType"
|
||||
value={formik2.values.personType}
|
||||
onChange={(e) => {
|
||||
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: "",
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormControlLabel value="real" control={<Radio />} label="حقیقی" />
|
||||
<FormControlLabel value="legal" control={<Radio />} label="حقوقی" />
|
||||
</RadioGroup>
|
||||
</LabelField>
|
||||
<Typography mt={2}>
|
||||
{"استعلام "}
|
||||
{formik2.values.personType === "legal" ? "شناسه ملی حقوقی" : "کد ملی"}
|
||||
</Typography>
|
||||
<Grid mt={SPACING.SMALL} display="flex" width={1}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="nationalCode"
|
||||
name="nationalCode"
|
||||
label={
|
||||
formik2.values.personType === "legal"
|
||||
? "شناسه ملی حقوقی"
|
||||
: "کد ملی"
|
||||
}
|
||||
variant="outlined"
|
||||
value={formik2.values.nationalCode}
|
||||
error={Boolean(
|
||||
formik2.touched.nationalCode && formik2.errors.nationalCode
|
||||
)}
|
||||
onChange={formik2.handleChange}
|
||||
onBlur={formik2.handleBlur}
|
||||
helperText={
|
||||
formik2.touched.nationalCode && formik2.errors.nationalCode
|
||||
}
|
||||
inputProps={{
|
||||
maxLength: formik2.values.personType === "legal" ? 11 : 10,
|
||||
}}
|
||||
/>
|
||||
<IconButton
|
||||
disabled={!formik2.isValid || inquiryInProgress}
|
||||
aria-label="search"
|
||||
color="primary"
|
||||
onClick={handleNationalInquiry}
|
||||
>
|
||||
<SearchIcon />
|
||||
</IconButton>
|
||||
{!isEdit && (
|
||||
<Grid container xs={12}>
|
||||
<LabelField label="نوع شخص">
|
||||
<RadioGroup
|
||||
row
|
||||
name="personType"
|
||||
value={formik2.values.personType}
|
||||
onChange={(e) => {
|
||||
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: "",
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormControlLabel
|
||||
value="real"
|
||||
control={<Radio />}
|
||||
label="حقیقی"
|
||||
/>
|
||||
<FormControlLabel
|
||||
value="legal"
|
||||
control={<Radio />}
|
||||
label="حقوقی"
|
||||
/>
|
||||
</RadioGroup>
|
||||
</LabelField>
|
||||
<Typography mt={2}>
|
||||
{"استعلام "}
|
||||
{formik2.values.personType === "legal"
|
||||
? "شناسه ملی حقوقی"
|
||||
: "کد ملی"}
|
||||
</Typography>
|
||||
<Grid mt={SPACING.SMALL} display="flex" width={1}>
|
||||
<TextField
|
||||
fullWidth
|
||||
id="nationalCode"
|
||||
name="nationalCode"
|
||||
label={
|
||||
formik2.values.personType === "legal"
|
||||
? "شناسه ملی حقوقی"
|
||||
: "کد ملی"
|
||||
}
|
||||
variant="outlined"
|
||||
value={formik2.values.nationalCode}
|
||||
error={Boolean(
|
||||
formik2.touched.nationalCode && formik2.errors.nationalCode
|
||||
)}
|
||||
onChange={formik2.handleChange}
|
||||
onBlur={formik2.handleBlur}
|
||||
helperText={
|
||||
formik2.touched.nationalCode && formik2.errors.nationalCode
|
||||
}
|
||||
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>
|
||||
)}
|
||||
|
||||
{userData || notFound || isEdit ? (
|
||||
<Grid
|
||||
|
||||
Reference in New Issue
Block a user