"use client" import { getProjectDetailById } from "@/components/label/api/project" import { ProjectDetail } from "@/components/label/api/project/typing" import { useAllUserStore, useBackUrlStore } from "@/components/label/store/auth" import { Breadcrumbs, Button, Group, Paper, SegmentedControl, Stack, Text, UnstyledButton, } from "@mantine/core" import { IconChevronLeft } from "@tabler/icons-react" import { useRouter, useSearchParams } from "next/navigation" import { useEffect, useMemo, useState } from "react" import InfoSettingContainer from "./InfoSettingContainer" import OwnTaskTableContainer from "./OwnTaskTableContainer" import TaskBoardContainer from "./TaskBoardContainer" import TaskTableContainer from "./TaskTableContainer" type TabKey = "own" | "all" | "setting" | "board" export default function CollectionDetailPage() { const router = useRouter() const urlParams = useSearchParams() const type = urlParams.get("type") const id = urlParams.get("id") const projectId = typeof id === "string" && !isNaN(Number(id)) ? Number(id) : -1 const { backTitle, setBackProps } = useBackUrlStore() const { userOpts } = useAllUserStore() const [selectKey, setSelectedKey] = useState( (backTitle as TabKey) || "own" ) const [info, setInfo] = useState() const [userEnums, setUserEnums] = useState<{ allEnum: Map labelEnum: Map review1Enum: Map review2Enum: Map }>({ allEnum: new Map(), labelEnum: new Map(), review1Enum: new Map(), review2Enum: new Map(), }) useEffect(() => { if (projectId === -1) return const getProjectInfo = async () => { const res = await getProjectDetailById(projectId) setInfo(res) } getProjectInfo() }, [projectId]) const updateProjectInfo = async () => { if (projectId === -1) return const res = await getProjectDetailById(projectId) setInfo(res) } useEffect(() => { if (!info?.label_process) return const { step_detail } = info.label_process let label: number[] = [] let review1: number[] = [] let review2: number[] = [] step_detail.forEach(({ action, user_list }: any) => { if (action === 1) label = user_list else if (action === 2) review1 = user_list else if (action === 3) review2 = user_list }) const all = Array.from(new Set([...label, ...review1, ...review2])) const toLabelMap = (uids: number[]) => new Map( uids.map((uid) => { const opt = userOpts.find((o) => o.value === uid) return [uid, opt?.label ?? String(uid)] }) ) queueMicrotask(() => { setUserEnums({ allEnum: toLabelMap(all), labelEnum: toLabelMap(label), review1Enum: toLabelMap(review1), review2Enum: toLabelMap(review2), }) }) }, [info, userOpts]) const breadcrumbsItems = useMemo(() => { return [ { title: type ? type === "collect" ? "我的收藏" : type === "dynamic" ? "动态项目" : "全部项目" : "我的收藏", href: type ? `/management/person/collection?type=${type}` : "/management/person/collection?type=collect", }, { title: info?.name || "项目名称", href: "", }, ].map((item) => ( { if (!item.href) return router.push(item.href) }}> {item.title} )) }, [info?.name, router, type]) return ( {breadcrumbsItems} { const next = v as TabKey setSelectedKey(next) const backUrl = type ? `/management/person/collection/detail?id=${projectId}&type=${type}` : `/management/person/collection/detail?id=${projectId}` setBackProps(backUrl, next) }} /> {selectKey === "own" ? ( ) : null} {selectKey === "all" ? ( ) : null} {selectKey === "board" ? : null} {selectKey === "setting" ? ( ) : null} ) }