From 90f51c68994b07f5211f382bd9880f9f2625945a Mon Sep 17 00:00:00 2001 From: wixarm Date: Sun, 8 Feb 2026 11:20:10 +0330 Subject: [PATCH] feat: edit distribution from distribution --- src/Pages/TagDistributionDetails.tsx | 187 +++++++++++++++++- .../tagging/DistributeFromDistribution.tsx | 58 ++++-- 2 files changed, 233 insertions(+), 12 deletions(-) diff --git a/src/Pages/TagDistributionDetails.tsx b/src/Pages/TagDistributionDetails.tsx index bc0ab5b..ea1097e 100644 --- a/src/Pages/TagDistributionDetails.tsx +++ b/src/Pages/TagDistributionDetails.tsx @@ -1,11 +1,17 @@ +import { useEffect, useState } from "react"; import { useParams } from "@tanstack/react-router"; import { Bars3Icon, CubeIcon, SparklesIcon } from "@heroicons/react/24/outline"; import { useApiRequest } from "../utils/useApiRequest"; +import { useModalStore } from "../context/zustand-store/appStore"; import { formatJustDate, formatJustTime } from "../utils/formatTime"; import ShowMoreInfo from "../components/ShowMoreInfo/ShowMoreInfo"; import { Grid } from "../components/Grid/Grid"; import Typography from "../components/Typography/Typography"; import Table from "../components/Table/Table"; +import { Popover } from "../components/PopOver/PopOver"; +import Button from "../components/Button/Button"; +import { Tooltip } from "../components/Tooltip/Tooltip"; +import { DistributeFromDistribution } from "../partials/tagging/DistributeFromDistribution"; const speciesMap: Record = { 1: "گاو", @@ -17,14 +23,171 @@ const speciesMap: Record = { export default function TagDistribtutionDetails() { const { id } = useParams({ strict: false }); + const { openModal } = useModalStore(); + const [childTableInfo, setChildTableInfo] = useState({ + page: 1, + page_size: 10, + }); + const [childTableData, setChildTableData] = useState([]); - const { data } = useApiRequest({ + const { data, refetch: refetchData } = useApiRequest({ api: `/tag/web/api/v1/tag_distribution_batch/${id}/`, method: "get", queryKey: ["tagBatchInnerDashboard", id], enabled: !!id, }); + const { data: childData, refetch: refetchChildList } = useApiRequest({ + api: `/tag/web/api/v1/tag_distribution_batch/${id}/child_list/`, + method: "get", + queryKey: ["tagDistributionChildList", id, childTableInfo], + params: { + ...childTableInfo, + }, + enabled: !!id, + }); + + const handleUpdate = () => { + refetchData(); + refetchChildList(); + }; + + useEffect(() => { + if (childData?.results) { + const formattedData = childData.results.map( + (item: any, index: number) => { + const dist = item?.distributions; + + return [ + childTableInfo.page === 1 + ? index + 1 + : index + + childTableInfo.page_size * (childTableInfo.page - 1) + + 1, + item?.dist_batch_identity ?? "-", + `${formatJustDate(item?.create_date) ?? "-"} (${ + formatJustDate(item?.create_date) + ? (formatJustTime(item?.create_date) ?? "-") + : "-" + })`, + item?.assigner_org?.name ?? "-", + item?.assigned_org?.name ?? "-", + item?.total_tag_count?.toLocaleString() ?? "-", + item?.total_distributed_tag_count?.toLocaleString() ?? "-", + item?.remaining_tag_count?.toLocaleString() ?? "-", + item?.distribution_type === "batch" + ? "توزیع گروهی" + : "توزیع تصادفی", + + + {dist?.map((opt: any, idx: number) => ( + + + + + گونه: + + + {speciesMap[opt?.species_code] ?? "-"} + + + + {item?.distribution_type === "batch" && + opt?.serial_from != null && ( + + + + بازه سریال: + + + از {opt?.serial_from ?? "-"} تا{" "} + {opt?.serial_to ?? "-"} + + + )} + + + + + تعداد پلاک: + + + {opt?.total_tag_count?.toLocaleString() ?? "-"} + + + + + + پلاک های توزیع شده: + + + {opt?.distributed_number?.toLocaleString() ?? "-"} + + + + + + پلاک های باقیمانده: + + + {opt?.remaining_number?.toLocaleString() ?? "-"} + + + + ))} + + , + + +