|
|
|
@@ -1,6 +1,8 @@ |
|
|
|
"use client"; |
|
|
|
|
|
|
|
import React, { useCallback, useMemo, useState } from "react"; |
|
|
|
import { useSession } from "next-auth/react"; |
|
|
|
import { AUTH, hasAbility } from "@/authorities"; |
|
|
|
import { |
|
|
|
Box, |
|
|
|
Typography, |
|
|
|
@@ -68,6 +70,9 @@ const defaultCriteria: Criteria = { |
|
|
|
|
|
|
|
/** FP-MTMS Version Checklist | Functions Ref. No. 61 | v1.0.0 | 2026-08-10 */ |
|
|
|
export default function DeliveryChartPage() { |
|
|
|
const { data: session } = useSession(); |
|
|
|
const abilities = session?.abilities ?? session?.user?.abilities ?? []; |
|
|
|
const canSeeStaffPerformance = hasAbility(abilities, AUTH.PERFORMANCE); |
|
|
|
const [criteria, setCriteria] = useState<Criteria>(defaultCriteria); |
|
|
|
const [topItemsSelected, setTopItemsSelected] = useState<TopDeliveryItemOption[]>([]); |
|
|
|
const [topItemOptions, setTopItemOptions] = useState<TopDeliveryItemOption[]>([]); |
|
|
|
@@ -132,6 +137,10 @@ export default function DeliveryChartPage() { |
|
|
|
}, [criteria.topItems, topItemsSelected, setChartLoading]); |
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
if (!canSeeStaffPerformance) { |
|
|
|
setChartData((prev) => ({ ...prev, staffPerf: [] })); |
|
|
|
return; |
|
|
|
} |
|
|
|
const s = criteria.staffPerf.startDate; |
|
|
|
const e = criteria.staffPerf.endDate; |
|
|
|
if (!s || !e) { |
|
|
|
@@ -161,13 +170,17 @@ export default function DeliveryChartPage() { |
|
|
|
) |
|
|
|
.catch((err) => setError(err instanceof Error ? err.message : "Request failed")) |
|
|
|
.finally(() => setChartLoading("staffPerf", false)); |
|
|
|
}, [criteria.staffPerf, staffSelected, setChartLoading]); |
|
|
|
}, [canSeeStaffPerformance, criteria.staffPerf, staffSelected, setChartLoading]); |
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
if (!canSeeStaffPerformance) { |
|
|
|
setStaffOptions([]); |
|
|
|
return; |
|
|
|
} |
|
|
|
fetchStaffDeliveryPerformanceHandlers() |
|
|
|
.then(setStaffOptions) |
|
|
|
.catch(() => setStaffOptions([])); |
|
|
|
}, []); |
|
|
|
}, [canSeeStaffPerformance]); |
|
|
|
React.useEffect(() => { |
|
|
|
const { startDate: s, endDate: e } = toDateRange(criteria.topItems.rangeDays); |
|
|
|
fetchTopDeliveryItemsItemOptions(s, e).then(setTopItemOptions).catch(() => setTopItemOptions([])); |
|
|
|
@@ -317,6 +330,7 @@ export default function DeliveryChartPage() { |
|
|
|
)} |
|
|
|
</ChartCard> |
|
|
|
|
|
|
|
{canSeeStaffPerformance && ( |
|
|
|
<ChartCard |
|
|
|
title="員工發貨績效(每日揀貨數量與耗時)" |
|
|
|
exportFilename="員工發貨績效" |
|
|
|
@@ -496,6 +510,7 @@ export default function DeliveryChartPage() { |
|
|
|
</> |
|
|
|
)} |
|
|
|
</ChartCard> |
|
|
|
)} |
|
|
|
</Box> |
|
|
|
); |
|
|
|
} |