diff --git a/src/admin/components/dashboard/DashTodayPlan.tsx b/src/admin/components/dashboard/DashTodayPlan.tsx new file mode 100644 index 0000000..25e7d19 --- /dev/null +++ b/src/admin/components/dashboard/DashTodayPlan.tsx @@ -0,0 +1,110 @@ +import Box from "@mui/material/Box"; +import Typography from "@mui/material/Typography"; +import { Card } from "../../ui"; +import { formatDate } from "../../utils/formatters"; + +/** The logged-in user's resolved work plan for today (see GET /api/admin/dashboard). */ +export interface TodayPlan { + shift_date: string; + category: string; + category_label: string; + category_color: string | null; + project_id: number | null; + project_number: string | null; + project_name: string | null; + note: string; + source: "entry" | "override"; + rangeFrom: string | null; + rangeTo: string | null; +} + +function projectLabel(p: TodayPlan): string { + const parts = [p.project_number, p.project_name].filter(Boolean); + return parts.length > 0 ? parts.join(" — ") : "Bez projektu"; +} + +/** + * "Můj plán na dnešek" — shows the logged-in user's work-plan entry for today + * (category + project/site + note, with a range badge when the day is part of a + * multi-day range). `plan === null` = the user has plan access but nothing is + * scheduled today (muted empty state). Rendered near the clock-in on the + * dashboard; the caller gates it on the plan permission. + */ +export default function DashTodayPlan({ plan }: { plan: TodayPlan | null }) { + const color = plan?.category_color || "var(--mui-palette-primary-main)"; + return ( + + + Můj plán na dnešek + + + {plan ? ( + + + + + + {plan.category_label} + + + {plan.rangeFrom && + plan.rangeTo && + plan.rangeFrom !== plan.rangeTo && ( + + součást rozsahu {formatDate(plan.rangeFrom)} –{" "} + {formatDate(plan.rangeTo)} + + )} + + + + {projectLabel(plan)} + + + {plan.note && ( + + {plan.note} + + )} + + ) : ( + + Pro dnešek nemáte naplánováno. + + )} + + ); +} diff --git a/src/admin/pages/Dashboard.tsx b/src/admin/pages/Dashboard.tsx index 4c268c2..206a798 100644 --- a/src/admin/pages/Dashboard.tsx +++ b/src/admin/pages/Dashboard.tsx @@ -19,6 +19,9 @@ import DashActivityFeed from "../components/dashboard/DashActivityFeed"; import DashAttendanceToday from "../components/dashboard/DashAttendanceToday"; import DashProfile from "../components/dashboard/DashProfile"; import DashSessions from "../components/dashboard/DashSessions"; +import DashTodayPlan, { + type TodayPlan, +} from "../components/dashboard/DashTodayPlan"; const API_BASE = "/api/admin"; @@ -69,6 +72,7 @@ interface DashData { pending_orders?: number; unpaid_invoices?: number; pending_leave_requests?: number; + today_plan?: TodayPlan | null; [key: string]: unknown; } @@ -317,6 +321,13 @@ export default function Dashboard() { )} + {/* My work plan for today — paired with the clock-in below */} + {!dashLoading && + (hasPermission("attendance.record") || + hasPermission("attendance.manage")) && ( + + )} + {/* Quick actions */} {!dashLoading && (