import { useEffect, useState } from "react"; import { Link, useNavigate } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { Ban, CalendarX2, LoaderPinwheel, Smile, SquareSigma } from "lucide-react"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet"; import DeployProgress from "@/components/certimate/DeployProgress"; import DeployState from "@/components/certimate/DeployState"; import { convertZulu2Beijing } from "@/lib/time"; import { Statistic } from "@/domain/domain"; import { Deployment, DeploymentListReq, Log } from "@/domain/deployment"; import { statistics } from "@/repository/domains"; import { list } from "@/repository/deployment"; const Dashboard = () => { const [statistic, setStatistic] = useState(); const [deployments, setDeployments] = useState(); const navigate = useNavigate(); const { t } = useTranslation(); useEffect(() => { const fetchStatistic = async () => { const data = await statistics(); setStatistic(data); }; fetchStatistic(); }, []); useEffect(() => { const fetchData = async () => { const param: DeploymentListReq = { perPage: 8, }; const data = await list(param); setDeployments(data.items); }; fetchData(); }, []); return (
{t("dashboard.page.title")}
{t("dashboard.statistics.all")}
{statistic?.total ? ( {statistic?.total} ) : ( 0 )}
{t("dashboard.statistics.unit")}
{t("dashboard.statistics.near_expired")}
{statistic?.expired ? ( {statistic?.expired} ) : ( 0 )}
{t("dashboard.statistics.unit")}
{t("dashboard.statistics.enabled")}
{statistic?.enabled ? ( {statistic?.enabled} ) : ( 0 )}
{t("dashboard.statistics.unit")}
{t("dashboard.statistics.disabled")}
{statistic?.disabled ? ( {statistic?.disabled} ) : ( 0 )}
{t("dashboard.statistics.unit")}

{t("dashboard.history")}
{deployments?.length == 0 ? ( <> {t("common.text.nodata")}
{t("history.nodata")}
) : ( <>
{t("history.props.domain")}
{t("history.props.status")}
{t("history.props.stage")}
{t("history.props.last_execution_time")}
{t("common.text.operations")}
{deployments?.map((deployment) => (
{deployment.expand.domain?.domain.split(";").map((domain: string) => ( <> {domain}
))}
{convertZulu2Beijing(deployment.deployedAt)}
{deployment.expand.domain?.domain}-{deployment.id} {t("history.log")}
{deployment.log.check && ( <> {deployment.log.check.map((item: Log) => { return (
[{item.time}]
{item.message}
{item.error &&
{item.error}
}
); })} )} {deployment.log.apply && ( <> {deployment.log.apply.map((item: Log) => { return (
[{item.time}]
{item.message}
{item.info && item.info.map((info: string) => { return
{info}
; })} {item.error &&
{item.error}
}
); })} )} {deployment.log.deploy && ( <> {deployment.log.deploy.map((item: Log) => { return (
[{item.time}]
{item.message}
{item.error &&
{item.error}
}
); })} )}
))} )}
); }; export default Dashboard;