diff --git a/src/Pages/TagDistribution.tsx b/src/Pages/TagDistribution.tsx index afb4869..034696d 100644 --- a/src/Pages/TagDistribution.tsx +++ b/src/Pages/TagDistribution.tsx @@ -1,220 +1,38 @@ -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 { SubmitTagDistribution } from "../partials/tagging/SubmitTagDistribution"; -import Typography from "../components/Typography/Typography"; -import ShowMoreInfo from "../components/ShowMoreInfo/ShowMoreInfo"; -import { formatJustDate } from "../utils/formatTime"; -import { Bars3Icon, CubeIcon, SparklesIcon } from "@heroicons/react/24/outline"; -import { DeleteButtonForPopOver } from "../components/PopOverButtons/PopOverButtons"; -import { Tooltip } from "../components/Tooltip/Tooltip"; -import { Popover } from "../components/PopOver/PopOver"; +import Tabs from "../components/Tab/Tab"; +import TagActiveDistributions from "../partials/tagging/TagActiveDistributions"; +import TagCanceledDistributions from "../partials/tagging/TagCanceledDistributions"; export default function TagDistribtution() { - const { openModal } = useModalStore(); - const [tableInfo, setTableInfo] = useState({ page: 1, page_size: 10 }); - const [tagsTableData, setTagsTableData] = useState([]); + const [selectedTab, setSelectedTab] = useState(0); + const handleTabChange = (index: number) => { + setSelectedTab(index); + }; - const { data: tagsData, refetch } = useApiRequest({ - api: "/tag/web/api/v1/tag_distribution_batch", - method: "get", - queryKey: ["tagsList", tableInfo], - params: { - ...tableInfo, + const tabItems = [ + { + label: "توزیع فعال", + page: "tag_distribution", + access: "Tag-Distribution-Actives", }, - }); - - const { data: tagDashboardData, refetch: updateDashboard } = useApiRequest({ - api: "/tag/web/api/v1/tag/tag_dashboard/", - method: "get", - queryKey: ["tagDashboard"], - }); - - const handleUpdate = () => { - refetch(); - updateDashboard(); - }; - const speciesMap: Record = { - 1: "گاو", - 2: "گاومیش", - 3: "شتر", - 4: "گوسفند", - 5: "بز", - }; - - useEffect(() => { - if (tagsData?.results) { - const formattedData = tagsData.results.map((item: any, index: number) => { - const dist = item?.distributions; - - return [ - tableInfo.page === 1 - ? index + 1 - : index + tableInfo.page_size * (tableInfo.page - 1) + 1, - item?.dist_batch_identity, - formatJustDate(item?.create_date), - item?.assigner_org?.name, - item?.assigned_org?.name, - item?.total_tag_count, - item?.distribution_type === "batch" ? "توزیع گروهی" : "توزیع تصادفی", - - - {dist?.map((opt: any, index: number) => ( - - {item?.distribution_type === "batch" && opt?.serial_from && ( - - - - بازه سریال: - - - از {opt?.serial_from ?? "-"} تا {opt?.serial_to ?? "-"} - - - )} - - - - - تعداد پلاک: - - - {opt?.distributed_number?.toLocaleString()} - - - - - - - گونه: - - - {speciesMap[opt?.species_code] ?? "-"} - - - - ))} - - , - - - + + + + {selectedTab === 0 ? ( + + ) : ( + + )} - - - - - -
); } diff --git a/src/partials/tagging/SubmitTagDistribution.tsx b/src/partials/tagging/SubmitTagDistribution.tsx index 230afc8..7f83998 100644 --- a/src/partials/tagging/SubmitTagDistribution.tsx +++ b/src/partials/tagging/SubmitTagDistribution.tsx @@ -9,18 +9,10 @@ import { RadioGroup } from "../../components/RadioButton/RadioGroup"; import { FormApiBasedAutoComplete } from "../../components/FormItems/FormApiBasedAutoComplete"; import AutoComplete from "../../components/AutoComplete/AutoComplete"; import { zValidateAutoComplete } from "../../data/getFormTypeErrors"; -import { useApiMutation } from "../../utils/useApiRequest"; +import { useApiMutation, useApiRequest } from "../../utils/useApiRequest"; import { useToast } from "../../hooks/useToast"; import { useModalStore } from "../../context/zustand-store/appStore"; -const speciesOptions = [ - { key: 1, value: "گاو" }, - { key: 2, value: "گاومیش" }, - { key: 3, value: "شتر" }, - { key: 4, value: "گوسفند" }, - { key: 5, value: "بز" }, -]; - const distributionTypeOptions = [ { label: "توزیع گروهی", value: "group" }, { label: "توزیع تصادفی", value: "random" }, @@ -74,6 +66,13 @@ export const SubmitTagDistribution = ({ item, getData }: any) => { method: isEdit ? "put" : "post", }); + const { data: speciesData } = useApiRequest({ + api: "/livestock/web/api/v1/livestock_species", + method: "get", + params: { page: 1, pageSize: 1000 }, + queryKey: ["species"], + }); + useEffect(() => { if (!item) return; @@ -129,6 +128,15 @@ export const SubmitTagDistribution = ({ item, getData }: any) => { } }; + const speciesOptions = () => { + return speciesData?.results?.map((opt: any) => { + return { + key: opt?.value, + value: opt?.name, + }; + }); + }; + return ( @@ -177,7 +185,7 @@ export const SubmitTagDistribution = ({ item, getData }: any) => { item?.distributions?.map((d: any) => d.batch_identity) || [] } groupFunction={(item) => - speciesOptions.find((s) => s.key === item)?.value || "نامشخص" + speciesOptions().find((s) => s.key === item)?.value || "نامشخص" } valueTemplateProps={[{ v1: "string" }, { v2: "string" }]} multiple @@ -207,9 +215,9 @@ export const SubmitTagDistribution = ({ item, getData }: any) => { /> )} - {distributionType === "random" && ( + {distributionType === "random" && speciesData?.results && ( b.species_code)} onChange={(keys: (string | number)[]) => { @@ -236,7 +244,7 @@ export const SubmitTagDistribution = ({ item, getData }: any) => { distributionType === "group" ? `تعداد (${batch.label})` : `تعداد ${ - speciesOptions.find((s) => s.key === batch.species_code) + speciesOptions().find((s) => s.key === batch.species_code) ?.value }` } diff --git a/src/partials/tagging/TagActiveDistributions.tsx b/src/partials/tagging/TagActiveDistributions.tsx new file mode 100644 index 0000000..006d604 --- /dev/null +++ b/src/partials/tagging/TagActiveDistributions.tsx @@ -0,0 +1,244 @@ +import { useEffect, useState } from "react"; +import { + Bars3Icon, + CubeIcon, + SparklesIcon, + StopCircleIcon, +} from "@heroicons/react/24/outline"; +import { useModalStore } from "../../context/zustand-store/appStore"; +import { useApiRequest } from "../../utils/useApiRequest"; +import { formatJustDate } from "../../utils/formatTime"; +import ShowMoreInfo from "../../components/ShowMoreInfo/ShowMoreInfo"; +import { Grid } from "../../components/Grid/Grid"; +import Typography from "../../components/Typography/Typography"; +import { Popover } from "../../components/PopOver/PopOver"; +import Button from "../../components/Button/Button"; +import { Tooltip } from "../../components/Tooltip/Tooltip"; +import { DeleteButtonForPopOver } from "../../components/PopOverButtons/PopOverButtons"; +import { SubmitTagDistribution } from "./SubmitTagDistribution"; +import Table from "../../components/Table/Table"; +import { BooleanQuestion } from "../../components/BooleanQuestion/BooleanQuestion"; + +export default function TagActiveDistributions() { + const { openModal } = useModalStore(); + const [tableInfo, setTableInfo] = useState({ page: 1, page_size: 10 }); + const [tagsTableData, setTagsTableData] = useState([]); + + const { data: tagsData, refetch } = useApiRequest({ + api: "/tag/web/api/v1/tag_distribution_batch", + method: "get", + queryKey: ["tagsList", tableInfo], + params: { + ...tableInfo, + }, + }); + + const { data: tagDashboardData, refetch: updateDashboard } = useApiRequest({ + api: "/tag/web/api/v1/tag_distribution_batch/main_dashboard/?is_closed=false", + method: "get", + queryKey: ["tagDistributionActivesDashboard"], + }); + + const handleUpdate = () => { + refetch(); + updateDashboard(); + }; + const speciesMap: Record = { + 1: "گاو", + 2: "گاومیش", + 3: "شتر", + 4: "گوسفند", + 5: "بز", + }; + + useEffect(() => { + if (tagsData?.results) { + const formattedData = tagsData.results.map((item: any, index: number) => { + const dist = item?.distributions; + + return [ + tableInfo.page === 1 + ? index + 1 + : index + tableInfo.page_size * (tableInfo.page - 1) + 1, + item?.dist_batch_identity, + formatJustDate(item?.create_date), + item?.assigner_org?.name, + item?.assigned_org?.name, + item?.total_tag_count, + item?.distribution_type === "batch" ? "توزیع گروهی" : "توزیع تصادفی", + + + {dist?.map((opt: any, index: number) => ( + + {item?.distribution_type === "batch" && opt?.serial_from && ( + + + + بازه سریال: + + + از {opt?.serial_from ?? "-"} تا {opt?.serial_to ?? "-"} + + + )} + + + + + تعداد پلاک: + + + {opt?.distributed_number?.toLocaleString()} + + + + + + + گونه: + + + {speciesMap[opt?.species_code] ?? "-"} + + + + ))} + + , + + + + + + +
+ + +
+ + ); +} diff --git a/src/partials/tagging/TagCanceledDistributions.tsx b/src/partials/tagging/TagCanceledDistributions.tsx new file mode 100644 index 0000000..fc0f471 --- /dev/null +++ b/src/partials/tagging/TagCanceledDistributions.tsx @@ -0,0 +1,208 @@ +import { useEffect, useState } from "react"; +import { + BackwardIcon, + Bars3Icon, + CubeIcon, + SparklesIcon, +} from "@heroicons/react/24/outline"; +import { useModalStore } from "../../context/zustand-store/appStore"; +import { useApiRequest } from "../../utils/useApiRequest"; +import { formatJustDate } from "../../utils/formatTime"; +import ShowMoreInfo from "../../components/ShowMoreInfo/ShowMoreInfo"; +import { Grid } from "../../components/Grid/Grid"; +import Typography from "../../components/Typography/Typography"; +import { Popover } from "../../components/PopOver/PopOver"; +import Button from "../../components/Button/Button"; +import { Tooltip } from "../../components/Tooltip/Tooltip"; +import { DeleteButtonForPopOver } from "../../components/PopOverButtons/PopOverButtons"; + +import Table from "../../components/Table/Table"; +import { BooleanQuestion } from "../../components/BooleanQuestion/BooleanQuestion"; + +export default function TagCanceledDistributions() { + const { openModal } = useModalStore(); + const [tableInfo, setTableInfo] = useState({ page: 1, page_size: 10 }); + const [tagsTableData, setTagsTableData] = useState([]); + + const { data: tagsData, refetch } = useApiRequest({ + api: "/tag/web/api/v1/tag_distribution_batch/closed_tag_dist_batch_list", + method: "get", + queryKey: ["tagsList", tableInfo], + params: { + ...tableInfo, + }, + }); + + const { data: tagDashboardData, refetch: updateDashboard } = useApiRequest({ + api: "/tag/web/api/v1/tag_distribution_batch/main_dashboard/?is_closed=true", + method: "get", + queryKey: ["tagDistributionCanceledDashboard"], + }); + + const handleUpdate = () => { + refetch(); + updateDashboard(); + }; + const speciesMap: Record = { + 1: "گاو", + 2: "گاومیش", + 3: "شتر", + 4: "گوسفند", + 5: "بز", + }; + + useEffect(() => { + if (tagsData?.results) { + const formattedData = tagsData.results.map((item: any, index: number) => { + const dist = item?.distributions; + + return [ + tableInfo.page === 1 + ? index + 1 + : index + tableInfo.page_size * (tableInfo.page - 1) + 1, + item?.dist_batch_identity, + formatJustDate(item?.create_date), + item?.assigner_org?.name, + item?.assigned_org?.name, + item?.total_tag_count, + item?.distribution_type === "batch" ? "توزیع گروهی" : "توزیع تصادفی", + + + {dist?.map((opt: any, index: number) => ( + + {item?.distribution_type === "batch" && opt?.serial_from && ( + + + + بازه سریال: + + + از {opt?.serial_from ?? "-"} تا {opt?.serial_to ?? "-"} + + + )} + + + + + تعداد پلاک: + + + {opt?.distributed_number?.toLocaleString()} + + + + + + + گونه: + + + {speciesMap[opt?.species_code] ?? "-"} + + + + ))} + + , + + +
+ +
+ + ); +}