add: buttons for showing stewards and killHouses of table
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
DRAWER,
|
||||
LOADING_END,
|
||||
LOADING_START,
|
||||
OPEN_MODAL
|
||||
} from "../../../../lib/redux/slices/appSlice";
|
||||
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
|
||||
import { Grid } from "../../../../components/grid/Grid";
|
||||
@@ -39,7 +40,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
||||
page: page,
|
||||
pageSize: perPage,
|
||||
searchValue: textValue,
|
||||
buyer_type: IS_STEWARD ? "Steward" : "Guilds",
|
||||
buyer_type: IS_STEWARD ? "Steward" : "Guilds"
|
||||
});
|
||||
setData(response.data.results);
|
||||
setTotalRows(response.data.count);
|
||||
@@ -60,31 +61,216 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
||||
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(() => {
|
||||
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 =
|
||||
item?.KillHouse?.killHouseOperator?.user?.fullname || "";
|
||||
const killHouseInfo = killHouseOperator
|
||||
firstKillHouse?.fullname ??
|
||||
item?.KillHouse?.killHouseOperator?.user?.fullname ??
|
||||
"";
|
||||
const killHouseDisplay =
|
||||
killHouseOperator && killHouseOperator !== "-"
|
||||
? `${killHouseName} (${killHouseOperator})`
|
||||
: 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 [
|
||||
page === 1 ? i + 1 : i + perPage * (page - 1) + 1,
|
||||
`${item?.fullname} (${item?.mobile})`,
|
||||
item?.unitName || "-",
|
||||
killHouseInfo,
|
||||
item?.province || "-",
|
||||
item?.city || "-",
|
||||
item?.requestsInfo?.numberOfRequests?.toLocaleString() || "0",
|
||||
item?.requestsInfo?.totalQuantity?.toLocaleString() || "0",
|
||||
item?.requestsInfo?.totalWeight?.toLocaleString() || "0",
|
||||
`${item?.fullname ?? ""} (${item?.mobile ?? ""})`,
|
||||
item?.unit_name ?? item?.unitName ?? "-",
|
||||
killHouseDisplay,
|
||||
item?.province ?? "-",
|
||||
item?.city ?? "-",
|
||||
listButtons,
|
||||
(requestsNum ?? 0).toLocaleString(),
|
||||
(requestsQty ?? 0).toLocaleString(),
|
||||
(requestsWt ?? 0).toLocaleString(),
|
||||
<ProvinceTrueGuildsOutProvinceOperations
|
||||
key={item?.unitName}
|
||||
key={item?.key ?? item?.unit_name ?? item?.unitName ?? i}
|
||||
userType={userType}
|
||||
item={item}
|
||||
updateTable={() => fetchApiData(1)}
|
||||
/>,
|
||||
updateTable={() => fetchApiData(page)}
|
||||
/>
|
||||
];
|
||||
});
|
||||
|
||||
@@ -115,7 +301,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
||||
<Button
|
||||
variant="contained"
|
||||
sx={{
|
||||
mr: SPACING.SMALL,
|
||||
mr: SPACING.SMALL
|
||||
}}
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
@@ -135,7 +321,7 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
||||
),
|
||||
title: `افزودن ${
|
||||
IS_STEWARD ? "مباشر" : "صنف"
|
||||
} خارج از استان`,
|
||||
} خارج از استان`
|
||||
})
|
||||
);
|
||||
}}
|
||||
@@ -171,10 +357,11 @@ export const ProvinceTrueGuildsOutProvince = ({ userType }) => {
|
||||
"کشتارگاه",
|
||||
"استان",
|
||||
"شهر",
|
||||
"کشتارگاه ها / مباشرین",
|
||||
"تعداد درخواست ها",
|
||||
"حجم تقریبی (قطعه)",
|
||||
"وزن (کیلوگرم)",
|
||||
"عملیات",
|
||||
"عملیات"
|
||||
]}
|
||||
handlePageChange={handlePageChange}
|
||||
totalRows={totalRows}
|
||||
|
||||
Reference in New Issue
Block a user