add: buttons for showing stewards and killHouses of table
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
|||||||
DRAWER,
|
DRAWER,
|
||||||
LOADING_END,
|
LOADING_END,
|
||||||
LOADING_START,
|
LOADING_START,
|
||||||
|
OPEN_MODAL
|
||||||
} from "../../../../lib/redux/slices/appSlice";
|
} from "../../../../lib/redux/slices/appSlice";
|
||||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||||
import { Grid } from "../../../../components/grid/Grid";
|
import { Grid } from "../../../../components/grid/Grid";
|
||||||
@@ -39,7 +40,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
|||||||
page: page,
|
page: page,
|
||||||
pageSize: perPage,
|
pageSize: perPage,
|
||||||
searchValue: textValue,
|
searchValue: textValue,
|
||||||
buyer_type: IS_STEWARD ? "Steward" : "Guilds",
|
buyer_type: IS_STEWARD ? "Steward" : "Guilds"
|
||||||
});
|
});
|
||||||
setData(response.data.results);
|
setData(response.data.results);
|
||||||
setTotalRows(response.data.count);
|
setTotalRows(response.data.count);
|
||||||
@@ -60,31 +61,216 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
|||||||
setPage(1);
|
setPage(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const killHouseList = (item) =>
|
||||||
|
item?.kill_house_info ?? item?.killHouseInfo ?? [];
|
||||||
|
const stewardList = (item) => item?.steward_info ?? item?.stewardInfo ?? [];
|
||||||
|
|
||||||
|
const openKillHousesModal = (list) => {
|
||||||
|
const rows =
|
||||||
|
list?.map((entry, idx) => {
|
||||||
|
const kh = entry?.Kill_house ?? entry?.KillHouse ?? {};
|
||||||
|
const req = entry?.requests_info ?? entry?.requestsInfo ?? {};
|
||||||
|
return [
|
||||||
|
idx + 1,
|
||||||
|
kh?.name ?? "-",
|
||||||
|
entry?.fullname ?? "-",
|
||||||
|
entry?.mobile ?? "-",
|
||||||
|
entry?.unit_name ?? entry?.unitName ?? "-",
|
||||||
|
entry?.province ?? "-",
|
||||||
|
entry?.city ?? "-",
|
||||||
|
(
|
||||||
|
req?.number_of_requests ??
|
||||||
|
req?.numberOfRequests ??
|
||||||
|
0
|
||||||
|
).toLocaleString(),
|
||||||
|
(req?.total_quantity ?? req?.totalQuantity ?? 0).toLocaleString(),
|
||||||
|
(req?.total_weight ?? req?.totalWeight ?? 0).toLocaleString()
|
||||||
|
];
|
||||||
|
}) ?? [];
|
||||||
|
dispatch(
|
||||||
|
OPEN_MODAL({
|
||||||
|
title: "لیست کشتارگاه ها",
|
||||||
|
size: "auto",
|
||||||
|
content: (
|
||||||
|
<ResponsiveTable
|
||||||
|
noPagination
|
||||||
|
data={rows}
|
||||||
|
columns={[
|
||||||
|
"ردیف",
|
||||||
|
"نام کشتارگاه",
|
||||||
|
"نام و نام خانوادگی",
|
||||||
|
"موبایل",
|
||||||
|
"نام واحد",
|
||||||
|
"استان",
|
||||||
|
"شهر",
|
||||||
|
"تعداد درخواست",
|
||||||
|
"حجم (قطعه)",
|
||||||
|
"وزن (کیلوگرم)"
|
||||||
|
]}
|
||||||
|
customWidth={"80vw"}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const openStewardsModal = (list) => {
|
||||||
|
const rows =
|
||||||
|
list?.map((entry, idx) => {
|
||||||
|
const req = entry?.requests_info ?? entry?.requestsInfo ?? {};
|
||||||
|
return [
|
||||||
|
idx + 1,
|
||||||
|
entry?.fullname ?? "-",
|
||||||
|
entry?.mobile ?? "-",
|
||||||
|
entry?.unit_name ?? entry?.unitName ?? "-",
|
||||||
|
entry?.province ?? "-",
|
||||||
|
entry?.city ?? "-",
|
||||||
|
(
|
||||||
|
req?.number_of_requests ??
|
||||||
|
req?.numberOfRequests ??
|
||||||
|
0
|
||||||
|
).toLocaleString(),
|
||||||
|
(req?.total_quantity ?? req?.totalQuantity ?? 0).toLocaleString(),
|
||||||
|
(req?.total_weight ?? req?.totalWeight ?? 0).toLocaleString()
|
||||||
|
];
|
||||||
|
}) ?? [];
|
||||||
|
dispatch(
|
||||||
|
OPEN_MODAL({
|
||||||
|
title: "لیست مباشرین",
|
||||||
|
size: "auto",
|
||||||
|
content: (
|
||||||
|
<ResponsiveTable
|
||||||
|
noPagination
|
||||||
|
data={rows}
|
||||||
|
columns={[
|
||||||
|
"ردیف",
|
||||||
|
"نام و نام خانوادگی",
|
||||||
|
"موبایل",
|
||||||
|
"نام واحد",
|
||||||
|
"استان",
|
||||||
|
"شهر",
|
||||||
|
"تعداد درخواست",
|
||||||
|
"حجم (قطعه)",
|
||||||
|
"وزن (کیلوگرم)"
|
||||||
|
]}
|
||||||
|
customWidth={"80vw"}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const d = data?.map((item, i) => {
|
const d = data?.map((item, i) => {
|
||||||
const killHouseName = item?.KillHouse?.name || "-";
|
const khList = killHouseList(item);
|
||||||
|
const stList = stewardList(item);
|
||||||
|
const firstKillHouse = khList?.[0];
|
||||||
|
const kh = firstKillHouse?.Kill_house ?? firstKillHouse?.KillHouse ?? {};
|
||||||
|
const killHouseName = kh?.name ?? item?.KillHouse?.name ?? "-";
|
||||||
const killHouseOperator =
|
const killHouseOperator =
|
||||||
item?.KillHouse?.killHouseOperator?.user?.fullname || "";
|
firstKillHouse?.fullname ??
|
||||||
const killHouseInfo = killHouseOperator
|
item?.KillHouse?.killHouseOperator?.user?.fullname ??
|
||||||
|
"";
|
||||||
|
const killHouseDisplay =
|
||||||
|
killHouseOperator && killHouseOperator !== "-"
|
||||||
? `${killHouseName} (${killHouseOperator})`
|
? `${killHouseName} (${killHouseOperator})`
|
||||||
: killHouseName;
|
: killHouseName;
|
||||||
|
|
||||||
|
const totalRequests = khList.reduce(
|
||||||
|
(acc, entry) => {
|
||||||
|
const r = entry?.requests_info ?? entry?.requestsInfo ?? {};
|
||||||
|
return {
|
||||||
|
numberOfRequests:
|
||||||
|
acc.numberOfRequests +
|
||||||
|
(r?.number_of_requests ?? r?.numberOfRequests ?? 0),
|
||||||
|
totalQuantity:
|
||||||
|
acc.totalQuantity + (r?.total_quantity ?? r?.totalQuantity ?? 0),
|
||||||
|
totalWeight:
|
||||||
|
acc.totalWeight + (r?.total_weight ?? r?.totalWeight ?? 0)
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{ numberOfRequests: 0, totalQuantity: 0, totalWeight: 0 }
|
||||||
|
);
|
||||||
|
|
||||||
|
const requestsNum =
|
||||||
|
khList.length > 0
|
||||||
|
? totalRequests.numberOfRequests
|
||||||
|
: item?.requestsInfo?.numberOfRequests ??
|
||||||
|
item?.requests_info?.number_of_requests ??
|
||||||
|
0;
|
||||||
|
const requestsQty =
|
||||||
|
khList.length > 0
|
||||||
|
? totalRequests.totalQuantity
|
||||||
|
: item?.requestsInfo?.totalQuantity ??
|
||||||
|
item?.requests_info?.total_quantity ??
|
||||||
|
0;
|
||||||
|
const requestsWt =
|
||||||
|
khList.length > 0
|
||||||
|
? totalRequests.totalWeight
|
||||||
|
: item?.requestsInfo?.totalWeight ??
|
||||||
|
item?.requests_info?.total_weight ??
|
||||||
|
0;
|
||||||
|
|
||||||
|
const hasKillHouses = khList?.length > 0;
|
||||||
|
const hasStewards = stList?.length > 0;
|
||||||
|
const listButtons =
|
||||||
|
hasKillHouses || hasStewards ? (
|
||||||
|
<Grid container gap={0.5} wrap="nowrap" key={i}>
|
||||||
|
{hasKillHouses && (
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
sx={{
|
||||||
|
minWidth: "fit-content",
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
fontSize: "0.8125rem"
|
||||||
|
}}
|
||||||
|
variant="outlined"
|
||||||
|
onClick={() => openKillHousesModal(khList)}
|
||||||
|
>
|
||||||
|
کشتارگاه ها ({khList.length})
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{hasStewards && (
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
sx={{
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
fontSize: "0.8125rem",
|
||||||
|
color: "#008f6b",
|
||||||
|
borderColor: "#008f6b",
|
||||||
|
"&:hover": {
|
||||||
|
borderColor: "#006b52",
|
||||||
|
backgroundColor: "rgba(0, 143, 107, 0.08)"
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
variant="outlined"
|
||||||
|
onClick={() => openStewardsModal(stList)}
|
||||||
|
>
|
||||||
|
مباشرین ({stList.length})
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Grid>
|
||||||
|
) : (
|
||||||
|
"-"
|
||||||
|
);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||||
`${item?.fullname} (${item?.mobile})`,
|
`${item?.fullname ?? ""} (${item?.mobile ?? ""})`,
|
||||||
item?.unitName || "-",
|
item?.unit_name ?? item?.unitName ?? "-",
|
||||||
killHouseInfo,
|
killHouseDisplay,
|
||||||
item?.province || "-",
|
item?.province ?? "-",
|
||||||
item?.city || "-",
|
item?.city ?? "-",
|
||||||
item?.requestsInfo?.numberOfRequests?.toLocaleString() || "0",
|
listButtons,
|
||||||
item?.requestsInfo?.totalQuantity?.toLocaleString() || "0",
|
(requestsNum ?? 0).toLocaleString(),
|
||||||
item?.requestsInfo?.totalWeight?.toLocaleString() || "0",
|
(requestsQty ?? 0).toLocaleString(),
|
||||||
|
(requestsWt ?? 0).toLocaleString(),
|
||||||
<ProvinceTrueGuildsOutProvinceOperations
|
<ProvinceTrueGuildsOutProvinceOperations
|
||||||
key={item?.unitName}
|
key={item?.key ?? item?.unit_name ?? item?.unitName ?? i}
|
||||||
userType={userType}
|
userType={userType}
|
||||||
item={item}
|
item={item}
|
||||||
updateTable={() => fetchApiData(1)}
|
updateTable={() => fetchApiData(page)}
|
||||||
/>,
|
/>
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -115,7 +301,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
|||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
sx={{
|
sx={{
|
||||||
mr: SPACING.SMALL,
|
mr: SPACING.SMALL
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
dispatch(
|
dispatch(
|
||||||
@@ -135,7 +321,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
|||||||
),
|
),
|
||||||
title: `افزودن ${
|
title: `افزودن ${
|
||||||
IS_STEWARD ? "مباشر" : "صنف"
|
IS_STEWARD ? "مباشر" : "صنف"
|
||||||
} خارج از استان`,
|
} خارج از استان`
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
@@ -171,10 +357,11 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
|||||||
"کشتارگاه",
|
"کشتارگاه",
|
||||||
"استان",
|
"استان",
|
||||||
"شهر",
|
"شهر",
|
||||||
|
"کشتارگاه ها / مباشرین",
|
||||||
"تعداد درخواست ها",
|
"تعداد درخواست ها",
|
||||||
"حجم تقریبی (قطعه)",
|
"حجم تقریبی (قطعه)",
|
||||||
"وزن (کیلوگرم)",
|
"وزن (کیلوگرم)",
|
||||||
"عملیات",
|
"عملیات"
|
||||||
]}
|
]}
|
||||||
handlePageChange={handlePageChange}
|
handlePageChange={handlePageChange}
|
||||||
totalRows={totalRows}
|
totalRows={totalRows}
|
||||||
|
|||||||
Reference in New Issue
Block a user