connect service => in province stewards
This commit is contained in:
@@ -244,7 +244,7 @@ const GuildMaangeGuilds = () => {
|
||||
selector: (item, i) => (
|
||||
<ManageGuildsOperations
|
||||
key={i + item?.guildsId}
|
||||
guild={item}
|
||||
item={item}
|
||||
updateTable={updateTable}
|
||||
/>
|
||||
),
|
||||
@@ -311,7 +311,7 @@ const GuildMaangeGuilds = () => {
|
||||
?.map((item) => `${item.name} (${item.mobile})`)
|
||||
.join(" - "),
|
||||
getItemState(item),
|
||||
<ManageGuildsOperations key={i + item?.guildsId} guild={item} />,
|
||||
<ManageGuildsOperations key={i + item?.guildsId} item={item} />,
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
@@ -27,13 +27,18 @@ import SendIcon from "@mui/icons-material/Send";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { SPACING } from "../../../../data/spacing";
|
||||
import { ProvinceManageGuildsSubmitRegisterCode } from "../province-manage-guilds-submit-register-code/ProvinceManageGuildsSubmitRegisterCode";
|
||||
import { provinceResendRegisterCodeStateService } from "../../services/province-get-register-code-state";
|
||||
import {
|
||||
provinceResendRegisterCodeStateService,
|
||||
provinceSendAgainSmsForRegisterCodeSteward,
|
||||
} from "../../services/province-get-register-code-state";
|
||||
import { ViewGuildDetails } from "../view-guild-details/ViewGuildDetails";
|
||||
import TuneIcon from "@mui/icons-material/Tune";
|
||||
import { updateStewardService } from "../../services/update-steward";
|
||||
|
||||
export const ManageGuildsOperations = ({ guild, updateTable }) => {
|
||||
export const ManageGuildsOperations = ({ item, updateTable, userType }) => {
|
||||
const IS_STEWARD = userType === "steward";
|
||||
const dispatch = useDispatch();
|
||||
const [checked, setChecked] = useState(guild.active);
|
||||
const [checked, setChecked] = useState(item.active);
|
||||
const [popoverOpen, setPopoverOpen] = useState(false);
|
||||
const [anchorEl, setAnchorEl] = useState(null);
|
||||
const [openNotif] = useContext(AppContext);
|
||||
@@ -51,29 +56,51 @@ export const ManageGuildsOperations = ({ guild, updateTable }) => {
|
||||
const handleChange = async (event) => {
|
||||
const newChecked = event.target.checked;
|
||||
setChecked(newChecked);
|
||||
|
||||
dispatch(LOADING_START());
|
||||
|
||||
try {
|
||||
const response = await axios.put("guilds/0/", {
|
||||
guilds_key: guild?.key,
|
||||
active: newChecked,
|
||||
role: getRoleFromUrl(),
|
||||
});
|
||||
let response = null;
|
||||
if (IS_STEWARD) {
|
||||
response = await dispatch(
|
||||
updateStewardService({
|
||||
params: {
|
||||
id: item?.id,
|
||||
},
|
||||
body: {
|
||||
active: newChecked,
|
||||
role: getRoleFromUrl(),
|
||||
},
|
||||
})
|
||||
).then(() => {
|
||||
updateTable();
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
});
|
||||
} else {
|
||||
response = await axios.put("guilds/0/", {
|
||||
guilds_key: item?.key,
|
||||
active: newChecked,
|
||||
role: getRoleFromUrl(),
|
||||
});
|
||||
if (response.status === 200) {
|
||||
updateTable();
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
dispatch(LOADING_END());
|
||||
|
||||
if (response.status === 200) {
|
||||
updateTable();
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
dispatch(LOADING_END());
|
||||
const errorMessage =
|
||||
error.response?.data?.result ||
|
||||
@@ -128,8 +155,10 @@ export const ManageGuildsOperations = ({ guild, updateTable }) => {
|
||||
closePopover();
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: "مشاهده جزییات صنف",
|
||||
content: <ViewGuildDetails guild={guild} />,
|
||||
title: `مشاهده جزییات ${IS_STEWARD ? "مباشر" : "صنف"}`,
|
||||
content: (
|
||||
<ViewGuildDetails userType={userType} item={item} />
|
||||
),
|
||||
size: window.innerWidth <= 600 ? "small" : "auto",
|
||||
})
|
||||
);
|
||||
@@ -173,7 +202,7 @@ export const ManageGuildsOperations = ({ guild, updateTable }) => {
|
||||
size: window.innerWidth <= 600 ? "small" : "auto",
|
||||
content: (
|
||||
<CreateGuilds
|
||||
guild={guild}
|
||||
guild={item}
|
||||
updateTable={updateTable}
|
||||
/>
|
||||
),
|
||||
@@ -197,7 +226,7 @@ export const ManageGuildsOperations = ({ guild, updateTable }) => {
|
||||
title: "اعمال محدودیت",
|
||||
content: (
|
||||
<GuildLimitaion
|
||||
guild={guild}
|
||||
guild={item}
|
||||
updateTable={updateTable}
|
||||
/>
|
||||
),
|
||||
@@ -210,7 +239,7 @@ export const ManageGuildsOperations = ({ guild, updateTable }) => {
|
||||
</>
|
||||
)}
|
||||
|
||||
{!guild?.isRegistered && (
|
||||
{!item?.isRegistered && (
|
||||
<Grid
|
||||
container
|
||||
alignItems="flex-start"
|
||||
@@ -228,10 +257,12 @@ export const ManageGuildsOperations = ({ guild, updateTable }) => {
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: "ثبت کد احراز",
|
||||
size: "auto",
|
||||
content: (
|
||||
<ProvinceManageGuildsSubmitRegisterCode
|
||||
item={guild}
|
||||
item={item}
|
||||
updateTable={updateTable}
|
||||
userType={userType}
|
||||
/>
|
||||
),
|
||||
})
|
||||
@@ -248,11 +279,14 @@ export const ManageGuildsOperations = ({ guild, updateTable }) => {
|
||||
sx={{ fontSize: { xs: 12, md: 15 } }}
|
||||
onClick={() => {
|
||||
closePopover();
|
||||
|
||||
dispatch(
|
||||
provinceResendRegisterCodeStateService({
|
||||
key: guild.key,
|
||||
})
|
||||
IS_STEWARD
|
||||
? provinceSendAgainSmsForRegisterCodeSteward({
|
||||
key: item.key,
|
||||
})
|
||||
: provinceResendRegisterCodeStateService({
|
||||
key: item.key,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
|
||||
@@ -16,12 +16,14 @@ import { ProvinceManageGuildsSubmitRegisterCode } from "../province-manage-guild
|
||||
import { provinceResendRegisterCodeStateService } from "../../services/province-get-register-code-state";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import { ViewGuildDetails } from "../view-guild-details/ViewGuildDetails";
|
||||
import { updateStewardService } from "../../services/update-steward";
|
||||
|
||||
export const ManageGuildsRequestsOperations = ({
|
||||
guild,
|
||||
item,
|
||||
updateTable,
|
||||
userType,
|
||||
}) => {
|
||||
const IS_STEWARD = userType === "steward";
|
||||
const [popoverOpen, setPopoverOpen] = useState(false);
|
||||
const [anchorEl, setAnchorEl] = useState(null);
|
||||
|
||||
@@ -111,9 +113,9 @@ export const ManageGuildsRequestsOperations = ({
|
||||
closePopover();
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: "مشاهده جزییات صنف",
|
||||
title: `مشاهده جزییات ${IS_STEWARD ? "مباشر" : "صنف"}`,
|
||||
content: (
|
||||
<ViewGuildDetails guild={guild} userType={userType} />
|
||||
<ViewGuildDetails item={item} userType={userType} />
|
||||
),
|
||||
size: window.innerWidth <= 600 ? "small" : "auto",
|
||||
})
|
||||
@@ -124,8 +126,8 @@ export const ManageGuildsRequestsOperations = ({
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{(guild?.activeRegisterCode && guild?.loggedRegisterCode) ||
|
||||
!guild?.activeRegisterCode ? (
|
||||
{(item?.activeRegisterCode && item?.loggedRegisterCode) ||
|
||||
!item?.activeRegisterCode ? (
|
||||
<Grid
|
||||
container
|
||||
alignItems="flex-start"
|
||||
@@ -140,13 +142,21 @@ export const ManageGuildsRequestsOperations = ({
|
||||
sx={{ fontSize: { xs: 12, md: 15 } }}
|
||||
onClick={() => {
|
||||
closePopover();
|
||||
|
||||
dispatch(
|
||||
checkKillhouseRequestGuildService({
|
||||
guilds_key: guild.key,
|
||||
state: "accepted",
|
||||
role: getRoleFromUrl(),
|
||||
})
|
||||
IS_STEWARD
|
||||
? updateStewardService({
|
||||
body: {
|
||||
province_accept_state: "accepted",
|
||||
},
|
||||
params: {
|
||||
id: item?.id,
|
||||
},
|
||||
})
|
||||
: checkKillhouseRequestGuildService({
|
||||
guilds_key: item.key,
|
||||
state: "accepted",
|
||||
role: getRoleFromUrl(),
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
@@ -179,10 +189,12 @@ export const ManageGuildsRequestsOperations = ({
|
||||
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: "رد درخواست ثبت صنف",
|
||||
title: `رد درخواست ثبت ${IS_STEWARD ? "مباشر" : "صنف"}`,
|
||||
size: "auto",
|
||||
content: (
|
||||
<RejectModal
|
||||
guild={guild}
|
||||
userType={userType}
|
||||
item={item}
|
||||
updateTable={updateTable}
|
||||
/>
|
||||
),
|
||||
@@ -213,7 +225,7 @@ export const ManageGuildsRequestsOperations = ({
|
||||
title: "ثبت کد احراز",
|
||||
content: (
|
||||
<ProvinceManageGuildsSubmitRegisterCode
|
||||
item={guild}
|
||||
item={item}
|
||||
updateTable={updateTable}
|
||||
/>
|
||||
),
|
||||
@@ -234,7 +246,7 @@ export const ManageGuildsRequestsOperations = ({
|
||||
|
||||
dispatch(
|
||||
provinceResendRegisterCodeStateService({
|
||||
key: guild.key,
|
||||
key: item.key,
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
@@ -267,7 +279,8 @@ export const ManageGuildsRequestsOperations = ({
|
||||
);
|
||||
};
|
||||
|
||||
const RejectModal = ({ guild, updateTable }) => {
|
||||
const RejectModal = ({ userType, item, updateTable }) => {
|
||||
const IS_STEWARD = userType === "steward";
|
||||
const [openNotif] = useContext(AppContext);
|
||||
const [text, setText] = useState("");
|
||||
const dispatch = useDispatch();
|
||||
@@ -275,7 +288,7 @@ const RejectModal = ({ guild, updateTable }) => {
|
||||
return (
|
||||
<Grid container gap={SPACING.TINY}>
|
||||
<TextField
|
||||
placeholder="دلیل رد درخواست..."
|
||||
placeholder=" دلیل رد درخواست ..."
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
/>
|
||||
@@ -286,12 +299,22 @@ const RejectModal = ({ guild, updateTable }) => {
|
||||
disabled={!text}
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
checkKillhouseRequestGuildService({
|
||||
guilds_key: guild.key,
|
||||
state: "rejected",
|
||||
message: text,
|
||||
role: getRoleFromUrl(),
|
||||
})
|
||||
IS_STEWARD
|
||||
? updateStewardService({
|
||||
body: {
|
||||
province_accept_state: "rejected",
|
||||
province_message: text,
|
||||
},
|
||||
params: {
|
||||
id: item?.id,
|
||||
},
|
||||
})
|
||||
: checkKillhouseRequestGuildService({
|
||||
guilds_key: item.key,
|
||||
state: "rejected",
|
||||
message: text,
|
||||
role: getRoleFromUrl(),
|
||||
})
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
|
||||
@@ -53,8 +53,8 @@ export const ManageGuildsRequests = ({ userType }) => {
|
||||
})
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
setData(response.data?.results || []);
|
||||
setTotalRows(response.data?.count || 0);
|
||||
setData(response.payload?.data?.results || []);
|
||||
setTotalRows(response.payload?.data?.count || 0);
|
||||
};
|
||||
|
||||
const handlePageChange = (page) => {
|
||||
@@ -72,6 +72,7 @@ export const ManageGuildsRequests = ({ userType }) => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
console.log(data);
|
||||
const d = data?.map((item, i) => {
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
@@ -79,21 +80,21 @@ export const ManageGuildsRequests = ({ userType }) => {
|
||||
item?.registerarMobile ? "(" + item?.registerarMobile + " )" : " "
|
||||
}`,
|
||||
item?.licenseNumber || "-",
|
||||
item?.guildsName || "-",
|
||||
item?.name || "-",
|
||||
`${item?.user?.fullname || "-"} (${item?.user?.mobile || "-"})`,
|
||||
item?.user?.nationalId || "-",
|
||||
item?.typeActivity || "-",
|
||||
item?.areaActivity || "-",
|
||||
item?.address?.postalCode || "-",
|
||||
`${item?.address?.province?.name || "-"}/${
|
||||
`${item?.address?.province?.name || "-"} / ${
|
||||
item?.address?.city?.name || "-"
|
||||
}/${item?.address?.address || "-"}`,
|
||||
} / ${item?.address?.address || "-"}`,
|
||||
item?.hasInquiry ? "استعلامی" : "دستی",
|
||||
item?.activeRegisterCode ? "انجام شده" : "انجام نشده",
|
||||
<ManageGuildsRequestsOperations
|
||||
updateTable={updateTable}
|
||||
key={item?.guildsName}
|
||||
guild={item}
|
||||
item={item}
|
||||
userType={userType}
|
||||
/>,
|
||||
];
|
||||
@@ -121,8 +122,8 @@ export const ManageGuildsRequests = ({ userType }) => {
|
||||
state: "pending",
|
||||
})
|
||||
);
|
||||
setData(response.data?.results || []);
|
||||
setTotalRows(response.data?.count || 0);
|
||||
setData(response.payload?.data?.results || []);
|
||||
setTotalRows(response.payload?.data?.count || 0);
|
||||
dispatch(LOADING_END());
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
@@ -182,14 +183,14 @@ export const ManageGuildsRequests = ({ userType }) => {
|
||||
columns={[
|
||||
"ردیف",
|
||||
"ثبت کننده",
|
||||
`${IS_STEWARD ? "مباشر" : "صنف"} شناسه`,
|
||||
`شناسه ${IS_STEWARD ? "مباشر" : "صنف"}`,
|
||||
`نام ${IS_STEWARD ? "مباشر" : "واحد صنفی"}`,
|
||||
"نام شخص/شرکت",
|
||||
"کدملی",
|
||||
"کد ملی",
|
||||
"نوع فعالیت",
|
||||
"حوزه فعالیت",
|
||||
"کدپستی",
|
||||
"استان/شهر/آدرس",
|
||||
"استان / شهر / آدرس",
|
||||
"نوع ثبت",
|
||||
"احراز شماره موبایل",
|
||||
"عملیات",
|
||||
|
||||
@@ -13,6 +13,7 @@ import { SPACING } from "../../../../data/spacing";
|
||||
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";
|
||||
|
||||
export const ManageGuilds = ({ userType }) => {
|
||||
const IS_STEWARD = userType === "steward";
|
||||
@@ -37,18 +38,30 @@ export const ManageGuilds = ({ userType }) => {
|
||||
|
||||
const fetchApiData = async (page) => {
|
||||
const response = await dispatch(
|
||||
provinceGetTotalGuildsService({
|
||||
search: "filter",
|
||||
value: textValue,
|
||||
page: page,
|
||||
page_size: perPage,
|
||||
steward: false,
|
||||
active_state: activeState,
|
||||
is_real_person: true,
|
||||
role_key: checkPathStartsWith("province")
|
||||
? selectedSubUser?.key || ""
|
||||
: "",
|
||||
})
|
||||
IS_STEWARD
|
||||
? provinceGetTotalStewardsService({
|
||||
search: "filter",
|
||||
value: textValue,
|
||||
page: page,
|
||||
page_size: perPage,
|
||||
active_state: activeState,
|
||||
is_real_person: true,
|
||||
role_key: checkPathStartsWith("province")
|
||||
? selectedSubUser?.key || ""
|
||||
: "",
|
||||
})
|
||||
: provinceGetTotalGuildsService({
|
||||
search: "filter",
|
||||
value: textValue,
|
||||
page: page,
|
||||
page_size: perPage,
|
||||
steward: false,
|
||||
active_state: activeState,
|
||||
is_real_person: true,
|
||||
role_key: checkPathStartsWith("province")
|
||||
? selectedSubUser?.key || ""
|
||||
: "",
|
||||
})
|
||||
);
|
||||
|
||||
if (response.payload.error) {
|
||||
@@ -88,15 +101,15 @@ export const ManageGuilds = ({ userType }) => {
|
||||
const commonData = [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
item?.licenseNumber || "-",
|
||||
item?.guildsName || "-",
|
||||
(IS_STEWARD ? item?.name : item?.guildsName) || "-",
|
||||
`${item?.user?.fullname || "-"} (${item?.user?.mobile || "-"})`,
|
||||
item?.user?.nationalId ? item?.user?.nationalId : "-",
|
||||
item?.typeActivity || "-",
|
||||
item?.areaActivity || "-",
|
||||
item?.address?.postalCode || "-",
|
||||
`${item?.address?.province?.name || "-"}/${
|
||||
`${item?.address?.province?.name || "-"} / ${
|
||||
item?.address?.city?.name || "-"
|
||||
}/${item?.address?.address || "-"}`,
|
||||
} / ${item?.address?.address || "-"}`,
|
||||
item?.steward ? "می باشد" : "نمی باشد",
|
||||
item?.limitationAllocation ? "دارد" : "ندارد",
|
||||
item?.allocationLimit ? item?.allocationLimit : "-",
|
||||
@@ -196,7 +209,8 @@ export const ManageGuilds = ({ userType }) => {
|
||||
if (getRoleFromUrl() !== "KillHouse") {
|
||||
commonData.push(
|
||||
<ManageGuildsOperations
|
||||
guild={item}
|
||||
item={item}
|
||||
userType={userType}
|
||||
updateTable={updateTable}
|
||||
isModal={true}
|
||||
/>
|
||||
@@ -346,7 +360,7 @@ export const ManageGuilds = ({ userType }) => {
|
||||
getRoleFromUrl() === "CityJahad" || getRoleFromUrl() === "CityPoultry"
|
||||
? [
|
||||
"ردیف",
|
||||
"شناسه صنف",
|
||||
IS_STEWARD ? "شناسه مباشر" : "شناسه صنف",
|
||||
"نام واحد صنفی",
|
||||
"نام شخص/شرکت",
|
||||
"کدملی",
|
||||
@@ -367,7 +381,7 @@ export const ManageGuilds = ({ userType }) => {
|
||||
: getRoleFromUrl() === "KillHouse"
|
||||
? [
|
||||
"ردیف",
|
||||
"شناسه صنف",
|
||||
IS_STEWARD ? "شناسه مباشر" : "شناسه صنف",
|
||||
"نام واحد صنفی",
|
||||
"نام شخص/شرکت",
|
||||
"کدملی",
|
||||
@@ -386,7 +400,7 @@ export const ManageGuilds = ({ userType }) => {
|
||||
]
|
||||
: [
|
||||
"ردیف",
|
||||
"شناسه صنف",
|
||||
IS_STEWARD ? "شناسه مباشر" : "شناسه صنف",
|
||||
"نام واحد صنفی",
|
||||
"نام شخص/شرکت",
|
||||
"کدملی",
|
||||
|
||||
@@ -17,20 +17,26 @@ import {
|
||||
Select,
|
||||
MenuItem,
|
||||
InputLabel,
|
||||
Autocomplete,
|
||||
} from "@mui/material";
|
||||
import BusinessIcon from "@mui/icons-material/Business";
|
||||
import PublicIcon from "@mui/icons-material/Public";
|
||||
import PersonIcon from "@mui/icons-material/Person";
|
||||
import BadgeIcon from "@mui/icons-material/Badge";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { SPACING } from "../../../../data/spacing";
|
||||
import { CLOSE_MODAL, OPEN_MODAL } from "../../../../lib/redux/slices/appSlice";
|
||||
import {
|
||||
CLOSE_MODAL,
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
OPEN_MODAL,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { provinceGetLegalPersonUnitInfoService } from "../../services/province-get-legal-person-unit-info";
|
||||
import { provinceCreateLegalGuildService } from "../../services/province-create-legal-guild";
|
||||
import { provinceGetCitiesService } from "../../services/province-get-cities";
|
||||
import { provinceGetTypeActivity } from "../../services/provinceGetTypeActivity";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import { cityGetProvinces } from "../../../city/services/CityGetProvinces";
|
||||
import { cityGetCity } from "../../../city/services/city-get-city";
|
||||
|
||||
let preservedUserData = null;
|
||||
let preservedUserFound = false;
|
||||
@@ -90,10 +96,11 @@ const getValidationSchema = (isAdmin, userFound) =>
|
||||
.string()
|
||||
.required("شناسه حقوقی الزامی است")
|
||||
.matches(/^[0-9]{11}$/, "شناسه حقوقی باید 11 رقم باشد"),
|
||||
first_name: isAdmin || !userFound ? yup.string() : yup.string(),
|
||||
last_name: isAdmin || !userFound ? yup.string() : yup.string(),
|
||||
unit_name: isAdmin || !userFound ? yup.string() : yup.string(),
|
||||
province: isAdmin || !userFound ? yup.string() : yup.string(),
|
||||
first_name: yup.string(),
|
||||
last_name: yup.string(),
|
||||
unit_name: yup.string(),
|
||||
name: yup.string(),
|
||||
province: yup.string(),
|
||||
city: yup.string(),
|
||||
mobile:
|
||||
isAdmin || !userFound
|
||||
@@ -106,25 +113,56 @@ const getValidationSchema = (isAdmin, userFound) =>
|
||||
(value) => !value || /^[0-9]{11}$/.test(value)
|
||||
)
|
||||
: yup.string(),
|
||||
type_activity: isAdmin || !userFound ? yup.string() : yup.string(),
|
||||
type_activity: yup.string(),
|
||||
});
|
||||
|
||||
const LegalGuildForm = ({ formik, isAdmin, cities, typeActivities }) => {
|
||||
const LegalGuildForm = ({ formik, isAdmin, typeActivities, userType }) => {
|
||||
const IS_STEWARD = userType === "steward";
|
||||
|
||||
const [provinceData, setProvinceData] = useState();
|
||||
const [cityData, setCityData] = useState();
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(LOADING_START());
|
||||
dispatch(cityGetProvinces())
|
||||
?.then((r) => {
|
||||
if (r?.payload?.data) {
|
||||
setProvinceData(r.payload.data);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching provinces:", error);
|
||||
})
|
||||
.finally(() => {
|
||||
dispatch(LOADING_END());
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (formik?.values?.province) {
|
||||
dispatch(LOADING_START());
|
||||
dispatch(cityGetCity(formik?.values?.province))
|
||||
.then((r) => {
|
||||
if (r?.payload?.data) {
|
||||
setCityData(r.payload.data);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching cities:", error);
|
||||
})
|
||||
.finally(() => {
|
||||
dispatch(LOADING_END());
|
||||
});
|
||||
} else {
|
||||
setCityData([]);
|
||||
}
|
||||
}, [formik?.values?.province]);
|
||||
|
||||
return (
|
||||
<form onSubmit={formik.handleSubmit}>
|
||||
<Grid container gap={SPACING.SMALL} p={2}>
|
||||
<Grid item xs={12}>
|
||||
<Typography
|
||||
variant="h6"
|
||||
style={{
|
||||
fontSize: "16px",
|
||||
}}
|
||||
gutterBottom
|
||||
>
|
||||
اطلاعات واحد حقوقی
|
||||
</Typography>
|
||||
</Grid>
|
||||
|
||||
<Grid container spacing={2} xs={12}>
|
||||
<Grid item xs={12} md={6}>
|
||||
<Grid container direction="column" gap={SPACING.TINY}>
|
||||
@@ -205,19 +243,23 @@ const LegalGuildForm = ({ formik, isAdmin, cities, typeActivities }) => {
|
||||
label="نام واحد"
|
||||
variant="outlined"
|
||||
fullWidth
|
||||
id="unit_name"
|
||||
name="unit_name"
|
||||
value={formik.values.unit_name}
|
||||
id={IS_STEWARD ? "name" : "unit_name"}
|
||||
name={IS_STEWARD ? "name" : "unit_name"}
|
||||
value={formik.values[IS_STEWARD ? "name" : "unit_name"]}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={Boolean(formik.errors.unit_name)}
|
||||
helperText={formik.errors.unit_name}
|
||||
error={Boolean(
|
||||
formik.errors[IS_STEWARD ? "name" : "unit_name"]
|
||||
)}
|
||||
helperText={
|
||||
formik.errors[IS_STEWARD ? "name" : "unit_name"]
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<InfoBox
|
||||
icon={BusinessIcon}
|
||||
label="نام واحد"
|
||||
value={formik.values.unit_name}
|
||||
value={formik.values[IS_STEWARD ? "name" : "unit_name"]}
|
||||
/>
|
||||
)}
|
||||
</Grid>
|
||||
@@ -227,61 +269,56 @@ const LegalGuildForm = ({ formik, isAdmin, cities, typeActivities }) => {
|
||||
<Grid item xs={12} md={6}>
|
||||
<Grid container direction="column" gap={SPACING.TINY}>
|
||||
<Grid item xs={12}>
|
||||
{isAdmin ? (
|
||||
<TextField
|
||||
label="استان"
|
||||
variant="outlined"
|
||||
fullWidth
|
||||
id="province"
|
||||
name="province"
|
||||
value={formik.values.province}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
error={Boolean(formik.errors.province)}
|
||||
helperText={formik.errors.province}
|
||||
/>
|
||||
) : (
|
||||
<InfoBox
|
||||
icon={PublicIcon}
|
||||
label="استان"
|
||||
value={formik.values.province}
|
||||
/>
|
||||
)}
|
||||
<Autocomplete
|
||||
size="small"
|
||||
style={{ width: "100%" }}
|
||||
disablePortal
|
||||
id="province"
|
||||
options={
|
||||
provinceData
|
||||
? provinceData.map((i) => ({
|
||||
id: i.key,
|
||||
label: i.name,
|
||||
}))
|
||||
: []
|
||||
}
|
||||
onChange={(e, value) => {
|
||||
formik.setFieldValue("province", value ? value.id : "");
|
||||
formik.setFieldValue("city", "");
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField {...params} label={"استان"} />
|
||||
)}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12}>
|
||||
<FormControl fullWidth>
|
||||
<InputLabel id="city-select-label">شهرستان</InputLabel>
|
||||
<Select
|
||||
labelId="city-select-label"
|
||||
id="city"
|
||||
name="city"
|
||||
value={formik.values.city || ""}
|
||||
label="شهرستان"
|
||||
onChange={(e) => {
|
||||
formik.setFieldValue("city", e.target.value);
|
||||
}}
|
||||
onBlur={formik.handleBlur}
|
||||
disabled={false}
|
||||
>
|
||||
{cities.map((city) => (
|
||||
<MenuItem key={city.key} value={city.name}>
|
||||
{city.name}
|
||||
</MenuItem>
|
||||
))}
|
||||
{formik.values.city &&
|
||||
!cities.some(
|
||||
(city) => city.name === formik.values.city
|
||||
) && (
|
||||
<MenuItem
|
||||
key="current-value"
|
||||
value={formik.values.city}
|
||||
>
|
||||
{formik.values.city}
|
||||
</MenuItem>
|
||||
)}
|
||||
</Select>
|
||||
</FormControl>
|
||||
<Autocomplete
|
||||
size="small"
|
||||
minWidth={210}
|
||||
style={{ width: "100%" }}
|
||||
disabled={!formik.values.province}
|
||||
disablePortal
|
||||
id="city"
|
||||
options={
|
||||
cityData
|
||||
? cityData.map((i) => ({ id: i.name, label: i.name }))
|
||||
: []
|
||||
}
|
||||
onChange={(e, value) => {
|
||||
formik.setFieldValue("city", value ? value.id : "");
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
{...params}
|
||||
label={
|
||||
formik?.values?.city
|
||||
? `شهر ${formik?.values?.city}`
|
||||
: "شهر را انتخاب کنید"
|
||||
}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12}>
|
||||
@@ -396,44 +433,45 @@ const InquiryForm = ({ onInquiry, nationalCode, setNationalCode }) => {
|
||||
export const ProvinceLegalGuildsForm = ({
|
||||
onClose,
|
||||
updateTable,
|
||||
guild,
|
||||
item,
|
||||
userType,
|
||||
}) => {
|
||||
const IS_STEWARD = userType === "steward";
|
||||
const userInitialValue = {
|
||||
national_id: item?.user?.national_id || "",
|
||||
first_name: item?.user?.firstName || "",
|
||||
last_name: item?.user?.lastName || "",
|
||||
province: item?.address?.province?.name || "",
|
||||
city: item?.address?.city?.name || "",
|
||||
address: item?.address?.address || "",
|
||||
mobile: item?.user?.mobile || "",
|
||||
type_activity: item?.typeActivity || "",
|
||||
};
|
||||
|
||||
if (IS_STEWARD) {
|
||||
userInitialValue["name"] = item?.name;
|
||||
} else {
|
||||
userInitialValue["unit_name"] = item?.unitName;
|
||||
}
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const [openNotif] = useContext(AppContext);
|
||||
const [nationalCode, setNationalCode] = useState(
|
||||
guild?.user?.national_id ||
|
||||
guild?.national_code ||
|
||||
item?.user?.national_id ||
|
||||
item?.national_code ||
|
||||
preservedNationalCode ||
|
||||
""
|
||||
);
|
||||
const [userData, setUserData] = useState(
|
||||
guild
|
||||
? {
|
||||
national_id: guild?.user?.national_id || guild?.national_code || "",
|
||||
first_name: guild?.user?.first_name || "",
|
||||
last_name: guild?.user?.last_name || "",
|
||||
unit_name: guild?.guilds_name || "",
|
||||
province: guild?.address?.province?.name || "",
|
||||
city: guild?.address?.city?.name || "",
|
||||
address: guild?.address?.address || "",
|
||||
mobile: guild?.user?.mobile || "",
|
||||
type_activity: guild?.type_activity || "",
|
||||
}
|
||||
: preservedUserData
|
||||
item ? userInitialValue : preservedUserData
|
||||
);
|
||||
const [userFound, setUserFound] = useState(guild ? true : preservedUserFound);
|
||||
const [cities, setCities] = useState([]);
|
||||
const [userFound, setUserFound] = useState(item ? true : preservedUserFound);
|
||||
const [typeActivities, setTypeActivities] = useState([]);
|
||||
|
||||
const currentRole = getRoleFromUrl();
|
||||
const isAdmin = currentRole === "AdminX";
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(provinceGetCitiesService()).then((r) => {
|
||||
setCities(r.payload.data || []);
|
||||
});
|
||||
dispatch(provinceGetTypeActivity()).then((r) => {
|
||||
setTypeActivities(r.payload.data || []);
|
||||
});
|
||||
@@ -460,11 +498,14 @@ export const ProvinceLegalGuildsForm = ({
|
||||
// Update modal with larger size
|
||||
dispatch(
|
||||
OPEN_MODAL({
|
||||
title: `ثبت ${IS_STEWARD ? "مباشر" : "صنف"} حقوقی`,
|
||||
title: `${item ? "ویرایش" : "ثبت"} ${
|
||||
IS_STEWARD ? "مباشر" : "صنف"
|
||||
} حقوقی`,
|
||||
content: (
|
||||
<ProvinceLegalGuildsForm
|
||||
onClose={onClose}
|
||||
updateTable={updateTable}
|
||||
userType={userType}
|
||||
/>
|
||||
),
|
||||
size: { xs: "96vw", md: "90vw", lg: "600px" },
|
||||
@@ -489,16 +530,29 @@ export const ProvinceLegalGuildsForm = ({
|
||||
setUserFound(false);
|
||||
if (isAdmin) {
|
||||
// Admin can create even if user not found
|
||||
setUserData({
|
||||
is_real_person: false,
|
||||
first_name: "",
|
||||
last_name: "",
|
||||
national_id: nationalCode,
|
||||
province: "",
|
||||
unit_name: "",
|
||||
mobile: "",
|
||||
type_activity: "",
|
||||
});
|
||||
setUserData(
|
||||
IS_STEWARD
|
||||
? {
|
||||
is_real_person: false,
|
||||
first_name: "",
|
||||
last_name: "",
|
||||
national_id: nationalCode,
|
||||
province: "",
|
||||
name: "",
|
||||
mobile: "",
|
||||
type_activity: "",
|
||||
}
|
||||
: {
|
||||
is_real_person: false,
|
||||
first_name: "",
|
||||
last_name: "",
|
||||
national_id: nationalCode,
|
||||
province: "",
|
||||
unit_name: "",
|
||||
mobile: "",
|
||||
type_activity: "",
|
||||
}
|
||||
);
|
||||
} else {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
@@ -524,21 +578,28 @@ export const ProvinceLegalGuildsForm = ({
|
||||
});
|
||||
}
|
||||
});
|
||||
}, [dispatch, nationalCode, openNotif, isAdmin]);
|
||||
}, [dispatch, nationalCode, openNotif, isAdmin, IS_STEWARD]);
|
||||
|
||||
const formikIntitialValues = {
|
||||
national_id: userData?.national_id || userData?.nationalId || "",
|
||||
first_name: userData?.first_name || userData?.firstName || "",
|
||||
last_name: userData?.last_name || userData?.lastName || "",
|
||||
province: userData?.province || "",
|
||||
city: userData?.city || "",
|
||||
address: userData?.address || "",
|
||||
mobile: userData?.mobile || "",
|
||||
type_activity: userData?.type_activity || "",
|
||||
};
|
||||
|
||||
if (IS_STEWARD) {
|
||||
formikIntitialValues["name"] = userData?.name;
|
||||
} else {
|
||||
formikIntitialValues["unit_name"] = userData?.unit_name;
|
||||
}
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues: {
|
||||
national_id: userData?.national_id || userData?.nationalId || "",
|
||||
first_name: userData?.first_name || userData?.firstName || "",
|
||||
last_name: userData?.last_name || userData?.lastName || "",
|
||||
unit_name: userData?.unit_name || userData?.unitName || "",
|
||||
province: userData?.province || "",
|
||||
city: userData?.city || "",
|
||||
address: userData?.address || "",
|
||||
mobile: userData?.mobile || "",
|
||||
type_activity: userData?.type_activity || "",
|
||||
},
|
||||
validationSchema: getValidationSchema(isAdmin, userFound),
|
||||
initialValues: formikIntitialValues,
|
||||
validationSchema: getValidationSchema(isAdmin, userFound, userType),
|
||||
enableReinitialize: true,
|
||||
onSubmit: (values) => {
|
||||
// Find type_activity key from the title
|
||||
@@ -553,13 +614,18 @@ export const ProvinceLegalGuildsForm = ({
|
||||
national_id: values.national_id,
|
||||
province: values.province,
|
||||
address: values.address || "",
|
||||
unit_name: values.unit_name,
|
||||
mobile: values.mobile || "",
|
||||
city: values.city,
|
||||
type_activity: typeActivityKey, // Send key instead of title
|
||||
...(guild?.key && { guilds_key: guild.key }), // Include guild key for editing
|
||||
...(item?.key && { guilds_key: item.key }), // Include guild key for editing
|
||||
};
|
||||
|
||||
if (IS_STEWARD) {
|
||||
submitData["name"] = values?.name;
|
||||
} else {
|
||||
submitData["unit_name"] = values?.unit_name;
|
||||
}
|
||||
|
||||
dispatch(provinceCreateLegalGuildService(submitData)).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
@@ -584,7 +650,7 @@ export const ProvinceLegalGuildsForm = ({
|
||||
},
|
||||
});
|
||||
|
||||
if (!userData && !guild) {
|
||||
if (!userData && !item) {
|
||||
return (
|
||||
<InquiryForm
|
||||
onInquiry={handleInquiry}
|
||||
@@ -598,8 +664,8 @@ export const ProvinceLegalGuildsForm = ({
|
||||
<LegalGuildForm
|
||||
formik={formik}
|
||||
isAdmin={isAdmin}
|
||||
cities={cities}
|
||||
typeActivities={typeActivities}
|
||||
userType={userType}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { Button, TextField } from "@mui/material";
|
||||
import { DatePicker } from "@mui/x-date-pickers";
|
||||
import moment from "moment";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { SPACING } from "../../../../data/spacing";
|
||||
import { CLOSE_MODAL, OPEN_MODAL } from "../../../../lib/redux/slices/appSlice";
|
||||
@@ -11,6 +9,8 @@ import { ProvinceLegalGuildsForm } from "./ProvinceLegalGuildsForm";
|
||||
import { ProvinceLegalGuildsOperations } from "./ProvinceLegalGuildsOperations";
|
||||
import ResponsiveTable from "../../../../components/responsive-table/ResponsiveTable";
|
||||
import { RiSearchLine } from "react-icons/ri";
|
||||
import { provinceGetTotalStewardsService } from "../../services/province-get-total-stewards";
|
||||
import { checkPathStartsWith } from "../../../../utils/checkPathStartsWith";
|
||||
|
||||
export const ProvinceLegalGuildsInProvince = ({ userType }) => {
|
||||
const IS_STEWARD = userType === "steward";
|
||||
@@ -22,29 +22,40 @@ export const ProvinceLegalGuildsInProvince = ({ userType }) => {
|
||||
const [textValue, setTextValue] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [tableData, setTableData] = useState([]);
|
||||
const [selectedDate1, setSelectedDate1] = useState(null);
|
||||
const [selectedDate2, setSelectedDate2] = useState(null);
|
||||
const selectedSubUser = useSelector(
|
||||
(state) => state.userSlice.selectedSubUser
|
||||
);
|
||||
|
||||
const handleTextChange = (e) => setTextValue(e.target.value);
|
||||
|
||||
const fetchApiData = async (pageNum) => {
|
||||
const response = await dispatch(
|
||||
provinceGetTotalGuildsService({
|
||||
search: "filter",
|
||||
value: textValue,
|
||||
page: pageNum,
|
||||
page_size: perPage,
|
||||
steward: false,
|
||||
active_state: "all",
|
||||
is_real_person: false,
|
||||
...(selectedDate1 && {
|
||||
date_from: moment(selectedDate1).format("YYYY-MM-DD"),
|
||||
}),
|
||||
...(selectedDate2 && {
|
||||
date_to: moment(selectedDate2).format("YYYY-MM-DD"),
|
||||
}),
|
||||
})
|
||||
);
|
||||
let response = null;
|
||||
if (IS_STEWARD) {
|
||||
response = await dispatch(
|
||||
provinceGetTotalStewardsService({
|
||||
search: "filter",
|
||||
value: textValue,
|
||||
page: page,
|
||||
page_size: perPage,
|
||||
is_real_person: false,
|
||||
role_key: checkPathStartsWith("province")
|
||||
? selectedSubUser?.key || ""
|
||||
: "",
|
||||
})
|
||||
);
|
||||
} else {
|
||||
response = await dispatch(
|
||||
provinceGetTotalGuildsService({
|
||||
search: "filter",
|
||||
value: textValue,
|
||||
page: pageNum,
|
||||
page_size: perPage,
|
||||
steward: false,
|
||||
active_state: "all",
|
||||
is_real_person: false,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (response.payload.error) {
|
||||
console.error("Error fetching data:", response.payload.error);
|
||||
@@ -80,7 +91,7 @@ export const ProvinceLegalGuildsInProvince = ({ userType }) => {
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
item?.nationalId || "-",
|
||||
item?.guildsName || "-",
|
||||
(IS_STEWARD ? item?.name : item?.guildsName) || "-",
|
||||
`${item?.user?.fullname || "-"}`,
|
||||
item?.user?.mobile || "-",
|
||||
item?.address?.province?.name || "-",
|
||||
@@ -89,7 +100,7 @@ export const ProvinceLegalGuildsInProvince = ({ userType }) => {
|
||||
item?.active ? "فعال" : "غیر فعال",
|
||||
<ProvinceLegalGuildsOperations
|
||||
key={`operations-${item?.key || i}`}
|
||||
guild={item}
|
||||
item={item}
|
||||
updateTable={updateTableData}
|
||||
userType={userType}
|
||||
/>,
|
||||
@@ -119,12 +130,6 @@ export const ProvinceLegalGuildsInProvince = ({ userType }) => {
|
||||
steward: false,
|
||||
active_state: "all",
|
||||
is_real_person: false,
|
||||
...(selectedDate1 && {
|
||||
date_from: moment(selectedDate1).format("YYYY-MM-DD"),
|
||||
}),
|
||||
...(selectedDate2 && {
|
||||
date_to: moment(selectedDate2).format("YYYY-MM-DD"),
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
@@ -156,13 +161,13 @@ export const ProvinceLegalGuildsInProvince = ({ userType }) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container gap={SPACING.SMALL} p={2}>
|
||||
<Grid item gap={SPACING.SMALL} p={2} xs={12}>
|
||||
<Grid
|
||||
container
|
||||
xs={12}
|
||||
justifyContent="start"
|
||||
alignItems="center"
|
||||
gap={SPACING.SMALL}
|
||||
mb={SPACING.SMALL}
|
||||
>
|
||||
<Button variant="contained" color="primary" onClick={handleOpenModal}>
|
||||
{`ثبت ${IS_STEWARD ? "مباشر" : "واحد صنفی"}`}
|
||||
@@ -179,28 +184,6 @@ export const ProvinceLegalGuildsInProvince = ({ userType }) => {
|
||||
onChange={handleTextChange}
|
||||
/>
|
||||
|
||||
<DatePicker
|
||||
label="از تاریخ"
|
||||
value={selectedDate1}
|
||||
onChange={(newValue) => {
|
||||
setSelectedDate1(newValue);
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField {...params} size="small" style={{ width: 160 }} />
|
||||
)}
|
||||
/>
|
||||
|
||||
<DatePicker
|
||||
label="تا تاریخ"
|
||||
value={selectedDate2}
|
||||
onChange={(newValue) => {
|
||||
setSelectedDate2(newValue);
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField {...params} size="small" style={{ width: 160 }} />
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
|
||||
@@ -10,23 +10,34 @@ import {
|
||||
} from "@mui/material";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import DeleteIcon from "@mui/icons-material/Delete";
|
||||
import { useState } from "react";
|
||||
import { useContext, useState } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
import { OPEN_MODAL, CLOSE_MODAL } from "../../../../lib/redux/slices/appSlice";
|
||||
import {
|
||||
OPEN_MODAL,
|
||||
CLOSE_MODAL,
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
DRAWER,
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { ProvinceLegalGuildsForm } from "./ProvinceLegalGuildsForm";
|
||||
import TuneIcon from "@mui/icons-material/Tune";
|
||||
import { AppContext } from "../../../../contexts/AppContext";
|
||||
import { updateStewardService } from "../../services/update-steward";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import axios from "axios";
|
||||
|
||||
export const ProvinceLegalGuildsOperations = ({
|
||||
guild,
|
||||
item,
|
||||
updateTable,
|
||||
userType,
|
||||
}) => {
|
||||
const IS_STEWARD = userType === "steward";
|
||||
const dispatch = useDispatch();
|
||||
const [checked, setChecked] = useState(guild?.active);
|
||||
const [checked, setChecked] = useState(item?.active);
|
||||
const [popoverOpen, setPopoverOpen] = useState(false);
|
||||
const [anchorEl, setAnchorEl] = useState(null);
|
||||
const [openNotif] = useContext(AppContext);
|
||||
|
||||
const openPopover = (event) => {
|
||||
setPopoverOpen(true);
|
||||
@@ -38,9 +49,68 @@ export const ProvinceLegalGuildsOperations = ({
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
const handleActivationChange = (event) => {
|
||||
const handleActivationChange = async (event) => {
|
||||
const newChecked = event.target.checked;
|
||||
setChecked(newChecked);
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
let response = null;
|
||||
if (IS_STEWARD) {
|
||||
response = await dispatch(
|
||||
updateStewardService({
|
||||
params: {
|
||||
id: item?.id,
|
||||
},
|
||||
body: {
|
||||
active: newChecked,
|
||||
role: getRoleFromUrl(),
|
||||
},
|
||||
})
|
||||
).then(() => {
|
||||
updateTable();
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
});
|
||||
} else {
|
||||
response = await axios.put("guilds/0/", {
|
||||
guilds_key: item?.key,
|
||||
active: newChecked,
|
||||
role: getRoleFromUrl(),
|
||||
});
|
||||
if (response.status === 200) {
|
||||
updateTable();
|
||||
dispatch(DRAWER({ right: false, bottom: false, content: null }));
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
dispatch(LOADING_END());
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
dispatch(LOADING_END());
|
||||
const errorMessage =
|
||||
error.response?.data?.result ||
|
||||
error.response?.data?.error ||
|
||||
"خطا در انجام عملیات";
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: errorMessage,
|
||||
severity: "error",
|
||||
});
|
||||
// Revert the checkbox state on error
|
||||
setChecked(!newChecked);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
@@ -68,6 +138,41 @@ export const ProvinceLegalGuildsOperations = ({
|
||||
variant="contained"
|
||||
color="error"
|
||||
onClick={() => {
|
||||
if (IS_STEWARD) {
|
||||
dispatch(
|
||||
updateStewardService({
|
||||
params: {
|
||||
id: item?.id,
|
||||
},
|
||||
body: {
|
||||
active: false,
|
||||
trash: true,
|
||||
role: getRoleFromUrl(),
|
||||
},
|
||||
})
|
||||
)
|
||||
.then(() => {
|
||||
updateTable();
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات حذف با موفقیت انجام شد.",
|
||||
severity: "error",
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
const errorMessage =
|
||||
error.response?.data?.result ||
|
||||
error.response?.data?.error ||
|
||||
"خطا در انجام عملیات";
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: errorMessage,
|
||||
severity: "error",
|
||||
});
|
||||
});
|
||||
}
|
||||
dispatch(CLOSE_MODAL());
|
||||
}}
|
||||
sx={{ width: "48%" }}
|
||||
@@ -88,9 +193,10 @@ export const ProvinceLegalGuildsOperations = ({
|
||||
title: `ویرایش ${IS_STEWARD ? "مباشر" : "صنف"} حقوقی`,
|
||||
content: (
|
||||
<ProvinceLegalGuildsForm
|
||||
guild={guild}
|
||||
item={item}
|
||||
onClose={() => dispatch(CLOSE_MODAL())}
|
||||
updateTable={updateTable}
|
||||
userType={userType}
|
||||
/>
|
||||
),
|
||||
size: window.innerWidth <= 600 ? "small" : "auto",
|
||||
@@ -119,7 +225,7 @@ export const ProvinceLegalGuildsOperations = ({
|
||||
horizontal: "left",
|
||||
}}
|
||||
>
|
||||
<div style={{ padding: 10 }}>
|
||||
<div style={{ padding: 10, width: 120 }}>
|
||||
<Grid
|
||||
container
|
||||
direction="column"
|
||||
|
||||
@@ -21,7 +21,9 @@ const validationSchema = yup.object({
|
||||
export const ProvinceManageGuildsSubmitRegisterCode = ({
|
||||
item,
|
||||
updateTable,
|
||||
userType,
|
||||
}) => {
|
||||
const IS_STEWARD = userType === "steward";
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const [openNotif] = useContext(AppContext);
|
||||
@@ -32,12 +34,21 @@ export const ProvinceManageGuildsSubmitRegisterCode = ({
|
||||
validationSchema: validationSchema,
|
||||
onSubmit: (values) => {
|
||||
dispatch(
|
||||
checkKillhouseRequestGuildService({
|
||||
guilds_key: item.key,
|
||||
state: "accepted",
|
||||
code: values.verificationCode,
|
||||
role: getRoleFromUrl(),
|
||||
})
|
||||
checkKillhouseRequestGuildService(
|
||||
IS_STEWARD
|
||||
? {
|
||||
steward_key: item.key,
|
||||
state: "accepted",
|
||||
code: values.verificationCode,
|
||||
role: getRoleFromUrl(),
|
||||
}
|
||||
: {
|
||||
guilds_key: item.key,
|
||||
state: "accepted",
|
||||
code: values.verificationCode,
|
||||
role: getRoleFromUrl(),
|
||||
}
|
||||
)
|
||||
).then((r) => {
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
|
||||
@@ -19,7 +19,9 @@ import FavoriteIcon from "@mui/icons-material/Favorite";
|
||||
import CakeIcon from "@mui/icons-material/Cake";
|
||||
import HomeIcon from "@mui/icons-material/Home";
|
||||
import { formatJustDate } from "../../../../utils/formatTime";
|
||||
export const ViewGuildDetails = ({ guild }) => {
|
||||
|
||||
export const ViewGuildDetails = ({ item, userType }) => {
|
||||
const IS_STEWARD = userType === "steward";
|
||||
// Helper function to safely render values
|
||||
const renderValue = (value) => {
|
||||
if (!value) return "-";
|
||||
@@ -31,11 +33,11 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
};
|
||||
|
||||
// Extract nested values
|
||||
const provinceName = guild?.address?.province?.name || "-";
|
||||
const cityName = guild?.address?.city?.name || "-";
|
||||
const postalCode = guild?.address?.postalCode || "-";
|
||||
const guildCategory = guild?.guildAreaActivity?.title || "-";
|
||||
const unionName = guild?.unionName || "-";
|
||||
const provinceName = item?.address?.province?.name || "-";
|
||||
const cityName = item?.address?.city?.name || "-";
|
||||
const postalCode = item?.address?.postalCode || "-";
|
||||
const guildCategory = item?.guildAreaActivity?.title || "-";
|
||||
const unionName = item?.unionName || "-";
|
||||
return (
|
||||
<Grid
|
||||
container
|
||||
@@ -85,7 +87,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
کد ملی
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.user?.nationalId)}
|
||||
{renderValue(item?.user?.nationalId)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -106,7 +108,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
نام
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.user?.firstName)}
|
||||
{renderValue(item?.user?.firstName)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -128,7 +130,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
نام خانوادگی
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.user?.lastName)}
|
||||
{renderValue(item?.user?.lastName)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -149,7 +151,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
شماره شناسنامه
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.user?.nationalCode)}
|
||||
{renderValue(item?.user?.nationalCode)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -170,7 +172,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
در قید حیات
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{guild?.user?.isAlive ? "بلی" : "خیر"}
|
||||
{item?.user?.isAlive ? "بلی" : "خیر"}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -202,7 +204,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
تاریخ تولد
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.user?.birthday)}
|
||||
{renderValue(item?.user?.birthday)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -224,7 +226,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
نام پدر
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.user?.fatherName)}
|
||||
{renderValue(item?.user?.fatherName)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -246,9 +248,9 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
جنسیت
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{guild?.user?.gender === "True"
|
||||
{item?.user?.gender === "True"
|
||||
? "مرد"
|
||||
: guild?.user?.gender === "False"
|
||||
: item?.user?.gender === "False"
|
||||
? "زن"
|
||||
: "-"}
|
||||
</Typography>
|
||||
@@ -271,7 +273,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
شماره همراه
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.user?.mobile)}
|
||||
{renderValue(item?.user?.mobile)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -293,7 +295,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
شهر
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.user?.city)}
|
||||
{renderValue(item?.user?.city)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -307,7 +309,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
<Grid container gap={SPACING.TINY} direction="column">
|
||||
<Grid item xs={12}>
|
||||
<Typography variant="h6" gutterBottom>
|
||||
اطلاعات صنفی
|
||||
اطلاعات واحد
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid container xs={12}>
|
||||
@@ -335,7 +337,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
نام واحد
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.guildsName)}
|
||||
{renderValue(item?.guildsName)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -415,7 +417,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
تاریخ انقضا مجوز
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{formatJustDate(guild?.licenseExpireDate)}
|
||||
{formatJustDate(item?.licenseExpireDate)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -436,7 +438,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
شماره مجوز
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.licenseNumber)}
|
||||
{renderValue(item?.licenseNumber)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -505,7 +507,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
شماره تلفن
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.phone)}
|
||||
{renderValue(item?.phone)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -527,7 +529,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
آیا اتباع است؟
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{guild?.isForeignNational ? "بلی" : "خیر"}
|
||||
{item?.isForeignNational ? "بلی" : "خیر"}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -549,7 +551,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
نام شرکت
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.companyName)}
|
||||
{renderValue(item?.companyName)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -571,7 +573,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
شناسه ملی شرکت
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.companyIdentifier)}
|
||||
{renderValue(item?.companyIdentifier)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -593,7 +595,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
وضعیت مجوز
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.licenseStatus)}
|
||||
{renderValue(item?.licenseStatus)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -614,7 +616,7 @@ export const ViewGuildDetails = ({ guild }) => {
|
||||
آدرس
|
||||
</Typography>
|
||||
<Typography variant="body1">
|
||||
{renderValue(guild?.address?.address)}
|
||||
{renderValue(item?.address?.address)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
@@ -29,3 +29,21 @@ export const provinceResendRegisterCodeStateService = createAsyncThunk(
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export const provinceSendAgainSmsForRegisterCodeSteward = createAsyncThunk(
|
||||
"SEND_AGAIN_SMS_FOR_REGISTER_CODE_STEWARD",
|
||||
async (d, { dispatch }) => {
|
||||
dispatch(LOADING_START());
|
||||
try {
|
||||
const { data, status } = await axios.post(
|
||||
"send_again_sms_for_register_code_steward/",
|
||||
d
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -26,7 +26,7 @@ export const provinceGetTotalStewardsService = createAsyncThunk(
|
||||
},
|
||||
});
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
return { data: data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return {
|
||||
|
||||
21
src/features/province/services/update-steward.js
Normal file
21
src/features/province/services/update-steward.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import axios from "axios";
|
||||
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
|
||||
|
||||
export const updateStewardService = createAsyncThunk(
|
||||
"CHECK_KILLHOUSE_REQUEST_STEWARD_SERVICE",
|
||||
async (d, { dispatch }) => {
|
||||
try {
|
||||
dispatch(LOADING_START());
|
||||
const { data, status } = await axios.put(
|
||||
`main_steward_view/${d?.params?.id}/`,
|
||||
d?.body
|
||||
);
|
||||
dispatch(LOADING_END());
|
||||
return { data, status };
|
||||
} catch (e) {
|
||||
dispatch(LOADING_END());
|
||||
return { error: e.response.data.result };
|
||||
}
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user