From 225b2d874de45e9573e806dd3e10b33c2c1f6e04 Mon Sep 17 00:00:00 2001 From: wixarm Date: Mon, 16 Feb 2026 10:57:25 +0330 Subject: [PATCH] update: move tagging pages in one page --- src/Pages/Tagging.tsx | 371 +---------------------- src/partials/tagging/Taggings.tsx | 369 ++++++++++++++++++++++ src/{Pages => partials/tagging}/Tags.tsx | 46 +-- src/routes/paths.ts | 3 +- src/utils/getCategoryParameters.ts | 9 +- src/utils/getFaPermissions.ts | 4 +- 6 files changed, 410 insertions(+), 392 deletions(-) create mode 100644 src/partials/tagging/Taggings.tsx rename src/{Pages => partials/tagging}/Tags.tsx (92%) diff --git a/src/Pages/Tagging.tsx b/src/Pages/Tagging.tsx index 733206d..ca16bd3 100644 --- a/src/Pages/Tagging.tsx +++ b/src/Pages/Tagging.tsx @@ -1,369 +1,24 @@ -import { useEffect, useState } from "react"; -import { useApiRequest } from "../utils/useApiRequest"; +import { useState } from "react"; import { Grid } from "../components/Grid/Grid"; -import Table from "../components/Table/Table"; -import Button from "../components/Button/Button"; -import { useModalStore } from "../context/zustand-store/appStore"; -import { Popover } from "../components/PopOver/PopOver"; -import { Tooltip } from "../components/Tooltip/Tooltip"; -import { SubmitNewTags } from "../partials/tagging/SubmitNewTags"; -import { useNavigate } from "@tanstack/react-router"; -import { TAGS } from "../routes/paths"; -import { DeleteButtonForPopOver } from "../components/PopOverButtons/PopOverButtons"; -import { TableButton } from "../components/TableButton/TableButton"; -import AutoComplete from "../components/AutoComplete/AutoComplete"; +import Tabs from "../components/Tab/Tab"; +import Taggings from "../partials/tagging/Taggings"; +import Tags from "../partials/tagging/Tags"; -const speciesMap: Record = { - 1: "گاو", - 2: "گاومیش", - 3: "شتر", - 4: "گوسفند", - 5: "بز", -}; +const tabItems = [{ label: "ثبت پلاک" }, { label: "پلاک ها" }]; export default function Tagging() { - const { openModal } = useModalStore(); - const [tableInfo, setTableInfo] = useState({ page: 1, page_size: 10 }); - const [tagsTableData, setTagsTableData] = useState([]); - const [selectedSpecie, setSelectedSpecie] = useState< - (string | number)[] | any - >([]); - - const navigate = useNavigate(); - - const { data: tagsData, refetch } = useApiRequest({ - api: `/tag/web/api/v1/tag_batch/?species_code=${ - selectedSpecie.length ? selectedSpecie[0] : "" - }`, - method: "get", - queryKey: ["tagsList", tableInfo, selectedSpecie], - params: { ...tableInfo }, - }); - - const { data: tagDashboardData, refetch: updateDashboard } = useApiRequest({ - api: "/tag/web/api/v1/tag_batch/main_dashboard/", - method: "get", - queryKey: ["tagDashboard"], - }); - - const handleUpdate = () => { - refetch(); - updateDashboard(); - }; - - useEffect(() => { - if (tagsData?.results) { - const formattedData = tagsData.results.map((item: any, index: number) => { - return [ - tableInfo.page === 1 - ? index + 1 - : index + tableInfo.page_size * (tableInfo.page - 1) + 1, - item?.organization?.name || "بدون سازمان", - item?.species_code === 1 - ? "گاو" - : item?.species_code === 2 - ? "گاومیش" - : item?.species_code === 3 - ? "شتر" - : item?.species_code === 4 - ? "گوسفند" - : item?.species_code === 5 - ? "بز" - : "نامشخص", - item?.serial_from || "-", - item?.serial_to || "-", - item?.total_distributed_tags || 0, - item?.total_remaining_tags || 0, - - - + + + + {selectedTab === 0 && } + {selectedTab === 1 && } - - - - openModal({ - title: "آمار گونه‌ای", - isFullSize: true, - content: ( - { - openModal({ - title: `جزئیات ${ - speciesMap[row?.species_code] ?? "-" - }`, - content: ( -
-
- - تعداد بچ - - - {row?.batch_count?.toLocaleString?.() ?? 0} - -
-
- - پلاک تولید شده - - - {row?.tag_count_created_by_batch?.toLocaleString?.() ?? - 0} - -
-
- - پلاک توزیع شده - - - {row?.total_distributed_tags?.toLocaleString?.() ?? - 0} - -
-
- - پلاک باقی‌مانده - - - {row?.total_remaining_tags?.toLocaleString?.() ?? - 0} - -
-
- - بچ‌های توزیع‌شده - - - {row?.has_distributed_batches_number?.toLocaleString?.() ?? - 0} - -
-
- ), - }); - }} - /> - ), - }) - } - > - مشاهده - , - ], - ]} - /> - - - - {speciesOptions() && ( - - )} - - -
); } - -function BatchBySpeciesModal({ - batchData = [], -}: { - batchData: Array; - onRowAction?: (row: any, index: number) => void; -}) { - return ( -
-
- {batchData?.map((row, idx) => { - const speciesName = speciesMap[row?.species_code] ?? "-"; - return ( -
-
-
-
- - {speciesName} - -
-
-
-
- - تعداد گروه پلاک - - - {row?.batch_count?.toLocaleString?.() ?? 0} - -
-
- - گروه پلاک های توزیع‌شده - - - {row?.has_distributed_batches_number?.toLocaleString?.() ?? - 0} - -
-
- - پلاک تولید شده - - - {row?.tag_count_created_by_batch?.toLocaleString?.() ?? 0} - -
-
- - پلاک توزیع شده - - - {row?.total_distributed_tags?.toLocaleString?.() ?? 0} - -
-
- - پلاک باقی‌مانده - - - {row?.total_remaining_tags?.toLocaleString?.() ?? 0} - -
-
-
- ); - })} -
-
- ); -} diff --git a/src/partials/tagging/Taggings.tsx b/src/partials/tagging/Taggings.tsx new file mode 100644 index 0000000..d592d2e --- /dev/null +++ b/src/partials/tagging/Taggings.tsx @@ -0,0 +1,369 @@ +import { useEffect, useState } from "react"; +import { useApiRequest } from "../../utils/useApiRequest"; +import { Grid } from "../../components/Grid/Grid"; +import Table from "../../components/Table/Table"; +import Button from "../../components/Button/Button"; +import { useModalStore } from "../../context/zustand-store/appStore"; +import { Popover } from "../../components/PopOver/PopOver"; +import { Tooltip } from "../../components/Tooltip/Tooltip"; +import { SubmitNewTags } from "../../partials/tagging/SubmitNewTags"; +import { useNavigate } from "@tanstack/react-router"; +import { TAGGING } from "../../routes/paths"; +import { DeleteButtonForPopOver } from "../../components/PopOverButtons/PopOverButtons"; +import { TableButton } from "../../components/TableButton/TableButton"; +import AutoComplete from "../../components/AutoComplete/AutoComplete"; + +const speciesMap: Record = { + 1: "گاو", + 2: "گاومیش", + 3: "شتر", + 4: "گوسفند", + 5: "بز", +}; + +export default function Taggings() { + const { openModal } = useModalStore(); + const [tableInfo, setTableInfo] = useState({ page: 1, page_size: 10 }); + const [tagsTableData, setTagsTableData] = useState([]); + const [selectedSpecie, setSelectedSpecie] = useState< + (string | number)[] | any + >([]); + + const navigate = useNavigate(); + + const { data: tagsData, refetch } = useApiRequest({ + api: `/tag/web/api/v1/tag_batch/?species_code=${ + selectedSpecie.length ? selectedSpecie[0] : "" + }`, + method: "get", + queryKey: ["tagsList", tableInfo, selectedSpecie], + params: { ...tableInfo }, + }); + + const { data: tagDashboardData, refetch: updateDashboard } = useApiRequest({ + api: "/tag/web/api/v1/tag_batch/main_dashboard/", + method: "get", + queryKey: ["tagDashboard"], + }); + + const handleUpdate = () => { + refetch(); + updateDashboard(); + }; + + useEffect(() => { + if (tagsData?.results) { + const formattedData = tagsData.results.map((item: any, index: number) => { + return [ + tableInfo.page === 1 + ? index + 1 + : index + tableInfo.page_size * (tableInfo.page - 1) + 1, + item?.organization?.name || "بدون سازمان", + item?.species_code === 1 + ? "گاو" + : item?.species_code === 2 + ? "گاومیش" + : item?.species_code === 3 + ? "شتر" + : item?.species_code === 4 + ? "گوسفند" + : item?.species_code === 5 + ? "بز" + : "نامشخص", + item?.serial_from || "-", + item?.serial_to || "-", + item?.total_distributed_tags || 0, + item?.total_remaining_tags || 0, + + + + + + +
+ openModal({ + title: "آمار گونه‌ای", + isFullSize: true, + content: ( + { + openModal({ + title: `جزئیات ${ + speciesMap[row?.species_code] ?? "-" + }`, + content: ( +
+
+ + تعداد بچ + + + {row?.batch_count?.toLocaleString?.() ?? 0} + +
+
+ + پلاک تولید شده + + + {row?.tag_count_created_by_batch?.toLocaleString?.() ?? + 0} + +
+
+ + پلاک توزیع شده + + + {row?.total_distributed_tags?.toLocaleString?.() ?? + 0} + +
+
+ + پلاک باقی‌مانده + + + {row?.total_remaining_tags?.toLocaleString?.() ?? + 0} + +
+
+ + بچ‌های توزیع‌شده + + + {row?.has_distributed_batches_number?.toLocaleString?.() ?? + 0} + +
+
+ ), + }); + }} + /> + ), + }) + } + > + مشاهده + , + ], + ]} + /> + + + + {speciesOptions() && ( + + )} + + +
+ + ); +} + +function BatchBySpeciesModal({ + batchData = [], +}: { + batchData: Array; + onRowAction?: (row: any, index: number) => void; +}) { + return ( +
+
+ {batchData?.map((row, idx) => { + const speciesName = speciesMap[row?.species_code] ?? "-"; + return ( +
+
+
+
+ + {speciesName} + +
+
+
+
+ + تعداد گروه پلاک + + + {row?.batch_count?.toLocaleString?.() ?? 0} + +
+
+ + گروه پلاک های توزیع‌شده + + + {row?.has_distributed_batches_number?.toLocaleString?.() ?? + 0} + +
+
+ + پلاک تولید شده + + + {row?.tag_count_created_by_batch?.toLocaleString?.() ?? 0} + +
+
+ + پلاک توزیع شده + + + {row?.total_distributed_tags?.toLocaleString?.() ?? 0} + +
+
+ + پلاک باقی‌مانده + + + {row?.total_remaining_tags?.toLocaleString?.() ?? 0} + +
+
+
+ ); + })} +
+
+ ); +} diff --git a/src/Pages/Tags.tsx b/src/partials/tagging/Tags.tsx similarity index 92% rename from src/Pages/Tags.tsx rename to src/partials/tagging/Tags.tsx index 62db8b3..52b164a 100644 --- a/src/Pages/Tags.tsx +++ b/src/partials/tagging/Tags.tsx @@ -1,16 +1,16 @@ import { useEffect, useState } from "react"; -import { useApiRequest } from "../utils/useApiRequest"; -import { Grid } from "../components/Grid/Grid"; -import Table from "../components/Table/Table"; -import Button from "../components/Button/Button"; -import { useModalStore } from "../context/zustand-store/appStore"; -import { Popover } from "../components/PopOver/PopOver"; -import { Tooltip } from "../components/Tooltip/Tooltip"; -import { DeleteButtonForPopOver } from "../components/PopOverButtons/PopOverButtons"; -import { TagDetails } from "../partials/tagging/TagDetails"; +import { useApiRequest } from "../../utils/useApiRequest"; +import { Grid } from "../../components/Grid/Grid"; +import Table from "../../components/Table/Table"; +import Button from "../../components/Button/Button"; +import { useModalStore } from "../../context/zustand-store/appStore"; +import { Popover } from "../../components/PopOver/PopOver"; +import { Tooltip } from "../../components/Tooltip/Tooltip"; +import { DeleteButtonForPopOver } from "../../components/PopOverButtons/PopOverButtons"; +import { TagDetails } from "../../partials/tagging/TagDetails"; import { useParams } from "@tanstack/react-router"; -import { TableButton } from "../components/TableButton/TableButton"; -import AutoComplete from "../components/AutoComplete/AutoComplete"; +import { TableButton } from "../../components/TableButton/TableButton"; +import AutoComplete from "../../components/AutoComplete/AutoComplete"; const speciesMap: Record = { 1: "گاو", @@ -63,21 +63,21 @@ export default function Tags() { item?.species_code === 1 ? "گاو" : item?.species_code === 2 - ? "گاومیش" - : item?.species_code === 3 - ? "شتر" - : item?.species_code === 4 - ? "گوسفند" - : item?.species_code === 5 - ? "بز" - : "نامشخص", + ? "گاومیش" + : item?.species_code === 3 + ? "شتر" + : item?.species_code === 4 + ? "گوسفند" + : item?.species_code === 5 + ? "بز" + : "نامشخص", item?.status === "F" ? "آزاد" : item?.status === "A" - ? "پلاک شده" - : item?.status === "R" - ? "رزرو" - : "-", + ? "پلاک شده" + : item?.status === "R" + ? "رزرو" + : "-", item?.ownership_code || "-", diff --git a/src/routes/paths.ts b/src/routes/paths.ts index 8ef97f8..97b9a00 100644 --- a/src/routes/paths.ts +++ b/src/routes/paths.ts @@ -52,7 +52,6 @@ export const UNITS_SETTINGS = "/unit-settings"; //TAGGING export const TAGGING = "/tagging"; -export const TAGS = "/tags"; +export const TAGS_BATCH = "/tagging/$id/$from/$to"; export const TAG_DISTRIBUTION = "/tag-distribution"; export const TAG_DISTRIBUTION_DETAIL = "/tag-distribution/$identity/$id"; -export const TAGS_BATCH = "/tags/$id/$from/$to"; diff --git a/src/utils/getCategoryParameters.ts b/src/utils/getCategoryParameters.ts index f75ae03..62ca8d8 100644 --- a/src/utils/getCategoryParameters.ts +++ b/src/utils/getCategoryParameters.ts @@ -23,9 +23,9 @@ import Cooperatives from "../Pages/Cooperatives"; import CooperativeRanchers from "../Pages/CooperativeRanchers"; import SettingsOfUnits from "../Pages/SettingsOfUnits"; import Tagging from "../Pages/Tagging"; -import Tags from "../Pages/Tags"; import TagDistribtution from "../Pages/TagDistribution"; import TagDistribtutionDetails from "../Pages/TagDistributionDetails"; +import Tags from "../partials/tagging/Tags"; export const managementCategoryItems = [ { @@ -175,12 +175,7 @@ export const taggingCategoryItems = [ component: Tagging, }, { - name: "tags", - path: R.TAGS, - component: Tags, - }, - { - name: "tags", + name: "tagging_detail", path: R.TAGS_BATCH, component: Tags, }, diff --git a/src/utils/getFaPermissions.ts b/src/utils/getFaPermissions.ts index 7d5b875..802ee85 100644 --- a/src/utils/getFaPermissions.ts +++ b/src/utils/getFaPermissions.ts @@ -97,8 +97,8 @@ export function getFaPermissions(permission: string) { case "tagging": faPermission = "پلاک ها"; break; - case "tags": - faPermission = "انبار پلاک"; + case "tagging_detail": + faPermission = "جزئیات پلاک های گروه پلاک"; break; case "tag_distribution": faPermission = "توزیع پلاک";