connect services => out province stewards
This commit is contained in:
@@ -80,7 +80,7 @@ export const ManageGuildsRequests = ({ userType }) => {
|
||||
item?.registerarMobile ? "(" + item?.registerarMobile + " )" : " "
|
||||
}`,
|
||||
item?.licenseNumber || "-",
|
||||
item?.name || "-",
|
||||
(IS_STEWARD ? item?.name : item?.guildsName) || "-",
|
||||
`${item?.user?.fullname || "-"} (${item?.user?.mobile || "-"})`,
|
||||
item?.user?.nationalId || "-",
|
||||
item?.typeActivity || "-",
|
||||
|
||||
@@ -116,56 +116,22 @@ const getValidationSchema = (isAdmin, userFound) =>
|
||||
type_activity: yup.string(),
|
||||
});
|
||||
|
||||
const LegalGuildForm = ({ formik, isAdmin, typeActivities, userType }) => {
|
||||
const LegalGuildForm = ({
|
||||
formik,
|
||||
isAdmin,
|
||||
typeActivities,
|
||||
userType,
|
||||
provinces,
|
||||
cities,
|
||||
}) => {
|
||||
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 container spacing={2} xs={12}>
|
||||
<Grid item xs={12} md={6}>
|
||||
<Grid container direction="column" gap={SPACING.TINY}>
|
||||
<Grid container gap={SPACING.SMALL}>
|
||||
<Grid item xs={12}>
|
||||
{isAdmin ? (
|
||||
<TextField
|
||||
@@ -267,7 +233,7 @@ const LegalGuildForm = ({ formik, isAdmin, typeActivities, userType }) => {
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12} md={6}>
|
||||
<Grid container direction="column" gap={SPACING.TINY}>
|
||||
<Grid container gap={SPACING.SMALL}>
|
||||
<Grid item xs={12}>
|
||||
<Autocomplete
|
||||
size="small"
|
||||
@@ -275,8 +241,8 @@ const LegalGuildForm = ({ formik, isAdmin, typeActivities, userType }) => {
|
||||
disablePortal
|
||||
id="province"
|
||||
options={
|
||||
provinceData
|
||||
? provinceData.map((i) => ({
|
||||
provinces
|
||||
? provinces.map((i) => ({
|
||||
id: i.key,
|
||||
label: i.name,
|
||||
}))
|
||||
@@ -301,22 +267,15 @@ const LegalGuildForm = ({ formik, isAdmin, typeActivities, userType }) => {
|
||||
disablePortal
|
||||
id="city"
|
||||
options={
|
||||
cityData
|
||||
? cityData.map((i) => ({ id: i.name, label: i.name }))
|
||||
cities
|
||||
? cities.map((i) => ({ id: i.key, label: i.name }))
|
||||
: []
|
||||
}
|
||||
onChange={(e, value) => {
|
||||
formik.setFieldValue("city", value ? value.id : "");
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
{...params}
|
||||
label={
|
||||
formik?.values?.city
|
||||
? `شهر ${formik?.values?.city}`
|
||||
: "شهر را انتخاب کنید"
|
||||
}
|
||||
/>
|
||||
<TextField {...params} label={"شهر"} />
|
||||
)}
|
||||
/>
|
||||
</Grid>
|
||||
@@ -436,6 +395,9 @@ export const ProvinceLegalGuildsForm = ({
|
||||
item,
|
||||
userType,
|
||||
}) => {
|
||||
const [provinceData, setProvinceData] = useState();
|
||||
const [cityData, setCityData] = useState();
|
||||
|
||||
const IS_STEWARD = userType === "steward";
|
||||
const userInitialValue = {
|
||||
national_id: item?.user?.national_id || "",
|
||||
@@ -471,6 +433,22 @@ export const ProvinceLegalGuildsForm = ({
|
||||
const currentRole = getRoleFromUrl();
|
||||
const isAdmin = currentRole === "AdminX";
|
||||
|
||||
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(() => {
|
||||
dispatch(provinceGetTypeActivity()).then((r) => {
|
||||
setTypeActivities(r.payload.data || []);
|
||||
@@ -529,6 +507,12 @@ export const ProvinceLegalGuildsForm = ({
|
||||
if (r.payload.error) {
|
||||
setUserFound(false);
|
||||
if (isAdmin) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
// Admin can create even if user not found
|
||||
setUserData(
|
||||
IS_STEWARD
|
||||
@@ -612,10 +596,10 @@ export const ProvinceLegalGuildsForm = ({
|
||||
first_name: values.first_name,
|
||||
last_name: values.last_name,
|
||||
national_id: values.national_id,
|
||||
province: values.province,
|
||||
province: provinceData?.find((p) => p?.key === values.province)?.name,
|
||||
address: values.address || "",
|
||||
mobile: values.mobile || "",
|
||||
city: values.city,
|
||||
city: cityData?.find((c) => c?.key === values.city)?.name,
|
||||
type_activity: typeActivityKey, // Send key instead of title
|
||||
...(item?.key && { guilds_key: item.key }), // Include guild key for editing
|
||||
};
|
||||
@@ -650,6 +634,26 @@ export const ProvinceLegalGuildsForm = ({
|
||||
},
|
||||
});
|
||||
|
||||
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]);
|
||||
|
||||
if (!userData && !item) {
|
||||
return (
|
||||
<InquiryForm
|
||||
@@ -666,6 +670,8 @@ export const ProvinceLegalGuildsForm = ({
|
||||
isAdmin={isAdmin}
|
||||
typeActivities={typeActivities}
|
||||
userType={userType}
|
||||
provinces={provinceData}
|
||||
cities={cityData}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -29,33 +29,28 @@ export const ProvinceLegalGuildsInProvince = ({ userType }) => {
|
||||
const handleTextChange = (e) => setTextValue(e.target.value);
|
||||
|
||||
const fetchApiData = async (pageNum) => {
|
||||
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,
|
||||
})
|
||||
);
|
||||
}
|
||||
const response = await dispatch(
|
||||
IS_STEWARD
|
||||
? provinceGetTotalStewardsService({
|
||||
search: "filter",
|
||||
value: textValue,
|
||||
page: page,
|
||||
page_size: perPage,
|
||||
is_real_person: false,
|
||||
role_key: checkPathStartsWith("province")
|
||||
? selectedSubUser?.key || ""
|
||||
: "",
|
||||
})
|
||||
: 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);
|
||||
@@ -90,7 +85,7 @@ export const ProvinceLegalGuildsInProvince = ({ userType }) => {
|
||||
const d = data.map((item, i) => {
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
item?.nationalId || "-",
|
||||
(IS_STEWARD ? item?.licenseNumber : item?.nationalId) || "-",
|
||||
(IS_STEWARD ? item?.name : item?.guildsName) || "-",
|
||||
`${item?.user?.fullname || "-"}`,
|
||||
item?.user?.mobile || "-",
|
||||
|
||||
@@ -36,6 +36,7 @@ export const ProvinceLegalGuildsOutProvince = ({ userType }) => {
|
||||
page: page,
|
||||
pageSize: perPage,
|
||||
searchValue: textValue,
|
||||
buyer_type: IS_STEWARD ? "Steward" : "Guilds",
|
||||
});
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
@@ -68,7 +69,9 @@ export const ProvinceLegalGuildsOutProvince = ({ userType }) => {
|
||||
return [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
item?.unitName || "-",
|
||||
item?.buyer?.parentLegalPersonNationalCode || "-",
|
||||
(IS_STEWARD
|
||||
? item?.buyer?.nationalId
|
||||
: item?.buyer?.parentLegalPersonNationalCode) || "-",
|
||||
killHouseInfo,
|
||||
item?.province || "-",
|
||||
item?.city || "-",
|
||||
@@ -79,6 +82,7 @@ export const ProvinceLegalGuildsOutProvince = ({ userType }) => {
|
||||
key={item?.unitName}
|
||||
item={item}
|
||||
updateTable={() => fetchApiData(1)}
|
||||
userType={userType}
|
||||
/>,
|
||||
];
|
||||
});
|
||||
|
||||
@@ -36,6 +36,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
||||
page: page,
|
||||
pageSize: perPage,
|
||||
searchValue: textValue,
|
||||
buyer_type: IS_STEWARD ? "Steward" : "Guilds",
|
||||
});
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
|
||||
@@ -37,9 +37,15 @@ export const ProvinceTrueGuildsOutProvinceOperations = ({
|
||||
const deleteGuild = () => {
|
||||
const buyerKey = item?.key;
|
||||
if (buyerKey)
|
||||
dispatch(deleteOutProvinceTrueGuilds({ buyer_key: buyerKey })).then(() =>
|
||||
dispatch(CLOSE_MODAL())
|
||||
);
|
||||
dispatch(
|
||||
deleteOutProvinceTrueGuilds({
|
||||
buyer_key: buyerKey,
|
||||
buyer_type: IS_STEWARD ? "Steward" : "Guilds",
|
||||
})
|
||||
).then(() => {
|
||||
updateTable();
|
||||
dispatch(CLOSE_MODAL());
|
||||
});
|
||||
};
|
||||
return (
|
||||
<Grid container>
|
||||
@@ -93,7 +99,12 @@ export const ProvinceTrueGuildsOutProvinceOperations = ({
|
||||
? "legal"
|
||||
: "real"
|
||||
}
|
||||
defaultNationalCode={item?.buyer?.nationalCode}
|
||||
defaultNationalCode={
|
||||
IS_STEWARD
|
||||
? item?.buyer?.nationalId
|
||||
: item?.buyer?.nationalCode
|
||||
}
|
||||
userType={userType}
|
||||
/>
|
||||
),
|
||||
})
|
||||
|
||||
@@ -7,6 +7,7 @@ import axios from "axios";
|
||||
* @param {number} params.page - Page number
|
||||
* @param {number} params.pageSize - Items per page
|
||||
* @param {string} params.searchValue - Search value
|
||||
* @param {string} params.buyerType - buyer type
|
||||
* @returns {Promise} Axios promise with buyers data
|
||||
*/
|
||||
export const fetchOutProvinceRealBuyers = async ({
|
||||
@@ -14,9 +15,12 @@ export const fetchOutProvinceRealBuyers = async ({
|
||||
page,
|
||||
pageSize,
|
||||
searchValue = "",
|
||||
buyer_type = "",
|
||||
}) => {
|
||||
const response = await axios.get(
|
||||
`out-province-carcasses-buyer/?search=filter&value=${searchValue}&role=${role}&page=${page}&page_size=${pageSize}&state=buyer-list&type=real`
|
||||
`out-province-carcasses-buyer/?search=filter&value=${searchValue}&role=${role}&page=${page}&page_size=${pageSize}&state=buyer-list&type=real${
|
||||
buyer_type ? "&buyer_type=" + buyer_type : ""
|
||||
}`
|
||||
);
|
||||
return response;
|
||||
};
|
||||
@@ -35,10 +39,12 @@ export const fetchOutProvinceLegalBuyers = async ({
|
||||
page,
|
||||
pageSize,
|
||||
searchValue = "",
|
||||
buyer_type = "",
|
||||
}) => {
|
||||
const response = await axios.get(
|
||||
`out-province-carcasses-buyer/?search=filter&value=${searchValue}&role=${role}&page=${page}&page_size=${pageSize}&state=buyer-list&type=legal`
|
||||
`out-province-carcasses-buyer/?search=filter&value=${searchValue}&role=${role}&page=${page}&page_size=${pageSize}&state=buyer-list&type=legal${
|
||||
buyer_type ? "&buyer_type=" + buyer_type : ""
|
||||
}`
|
||||
);
|
||||
return response;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,7 +35,9 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({
|
||||
data,
|
||||
defaultPersonType,
|
||||
defaultNationalCode,
|
||||
userType,
|
||||
}) => {
|
||||
const IS_STEWARD = userType === "steward";
|
||||
const [openNotif] = useContext(AppContext);
|
||||
const [userData, setUserData] = useState(null);
|
||||
const [notFound, setNotFound] = useState(false);
|
||||
@@ -131,7 +133,9 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({
|
||||
} else if (data.buyer.parentLegalPersonNationalCode) {
|
||||
formik2.setFieldValue(
|
||||
"nationalCode",
|
||||
data.buyer.parentLegalPersonNationalCode,
|
||||
IS_STEWARD
|
||||
? data?.buyer?.nationalId
|
||||
: data.buyer.parentLegalPersonNationalCode,
|
||||
false
|
||||
);
|
||||
}
|
||||
@@ -140,15 +144,17 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({
|
||||
|
||||
useEffect(() => {
|
||||
if (userData) {
|
||||
formik.setValues({
|
||||
const formData = {
|
||||
mobile: userData.mobile || "",
|
||||
firstName: userData.firstName || "",
|
||||
lastName: userData.lastName || "",
|
||||
unitName: userData.unitName || "",
|
||||
province: userData.province || "",
|
||||
city: userData.city || "",
|
||||
nationalId: userData.nationalId || "",
|
||||
});
|
||||
unitName: data?.unitName || "",
|
||||
};
|
||||
|
||||
formik.setValues(formData);
|
||||
|
||||
const fieldKeys = [
|
||||
"nationalId",
|
||||
@@ -174,15 +180,17 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({
|
||||
|
||||
useEffect(() => {
|
||||
if (isEdit) {
|
||||
formik.setValues({
|
||||
const formData = {
|
||||
mobile: data.mobile || "",
|
||||
firstName: data.firstName || "",
|
||||
lastName: data.lastName || "",
|
||||
unitName: data.unitName || "",
|
||||
province: data.province || "",
|
||||
city: data.city || "",
|
||||
nationalId: data.national_id || data.nationalId || "",
|
||||
});
|
||||
nationalId: (IS_STEWARD ? defaultNationalCode : data.nationalId) || "",
|
||||
unitName: data?.unitName || "",
|
||||
};
|
||||
|
||||
formik.setValues(formData);
|
||||
setLockedFields({});
|
||||
// formik2.setFieldValue(
|
||||
// "nationalCode",
|
||||
@@ -656,79 +664,85 @@ export const SlaughterSellCarcassOutProvinceAddBuyer = ({
|
||||
disabled={!formik.isValid}
|
||||
onClick={() => {
|
||||
if (isEdit) {
|
||||
dispatch(
|
||||
slaughterEditBuyerDataService({
|
||||
buyer_key: data?.key,
|
||||
mobile: formik.values.mobile,
|
||||
first_name: formik.values.firstName,
|
||||
last_name: formik.values.lastName,
|
||||
unit_name: formik.values.unitName,
|
||||
city: formik.values.city,
|
||||
province: formik.values.province,
|
||||
national_id: formik.values.nationalId,
|
||||
})
|
||||
).then((r) => {
|
||||
updateTable();
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
dispatch(
|
||||
DRAWER({ right: false, bottom: false, content: null })
|
||||
);
|
||||
const submitData = {
|
||||
buyer_type: IS_STEWARD ? "Steward" : "Guilds",
|
||||
buyer_key: data?.key,
|
||||
mobile: formik.values.mobile,
|
||||
first_name: formik.values.firstName,
|
||||
last_name: formik.values.lastName,
|
||||
city: formik.values.city,
|
||||
province: formik.values.province,
|
||||
national_id: formik.values.nationalId,
|
||||
unit_name: formik.values.unitName,
|
||||
};
|
||||
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(slaughterEditBuyerDataService(submitData)).then(
|
||||
(r) => {
|
||||
updateTable();
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
dispatch(
|
||||
DRAWER({ right: false, bottom: false, content: null })
|
||||
);
|
||||
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
} else {
|
||||
dispatch(
|
||||
slaughterSubmitBuyerDataService({
|
||||
mobile: formik.values.mobile,
|
||||
first_name: formik.values.firstName,
|
||||
last_name: formik.values.lastName,
|
||||
const submitData = {
|
||||
mobile: formik.values.mobile,
|
||||
buyer_type: IS_STEWARD ? "Steward" : "Guilds",
|
||||
first_name: formik.values.firstName,
|
||||
last_name: formik.values.lastName,
|
||||
city: formik.values.city,
|
||||
province: formik.values.province,
|
||||
national_id:
|
||||
formik2.values.personType === "legal"
|
||||
? null
|
||||
: formik.values.nationalId,
|
||||
...(formik2.values.personType === "legal" && {
|
||||
isRealPerson: false,
|
||||
info_value: formik2.values.nationalCode,
|
||||
unit_name: formik.values.unitName,
|
||||
city: formik.values.city,
|
||||
province: formik.values.province,
|
||||
national_id:
|
||||
formik2.values.personType === "legal"
|
||||
? null
|
||||
: formik.values.nationalId,
|
||||
...(formik2.values.personType === "legal" && {
|
||||
isRealPerson: false,
|
||||
info_value: formik2.values.nationalCode,
|
||||
}),
|
||||
})
|
||||
).then((r) => {
|
||||
updateTable();
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
dispatch(
|
||||
DRAWER({ right: false, bottom: false, content: null })
|
||||
);
|
||||
}),
|
||||
};
|
||||
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
dispatch(slaughterSubmitBuyerDataService(submitData)).then(
|
||||
(r) => {
|
||||
updateTable();
|
||||
if (r.payload.error) {
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: r.payload.error,
|
||||
severity: "error",
|
||||
});
|
||||
} else {
|
||||
dispatch(
|
||||
DRAWER({ right: false, bottom: false, content: null })
|
||||
);
|
||||
|
||||
openNotif({
|
||||
vertical: "top",
|
||||
horizontal: "center",
|
||||
msg: "عملیات با موفقیت انجام شد.",
|
||||
severity: "success",
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user