feat: enhance ReassignSheet component with dynamic title and improved accessibility
- Added logic to dynamically set the sheet title based on the selected duty date, improving user context. - Updated the description to be visually hidden while maintaining accessibility for screen readers. - Refactored user selection display to enhance clarity and organization, ensuring a better user experience.
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import type { DutyWithUser } from "@/types";
|
import type { DutyWithUser } from "@/types";
|
||||||
import type { UserForAdmin } from "@/lib/api";
|
import type { UserForAdmin } from "@/lib/api";
|
||||||
import { localDateString, formatHHMM } from "@/lib/date-utils";
|
import { localDateString, formatHHMM, dateKeyToDDMM } from "@/lib/date-utils";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Sheet,
|
Sheet,
|
||||||
@@ -56,6 +56,16 @@ export function ReassignSheet({
|
|||||||
onCloseAnimationEnd,
|
onCloseAnimationEnd,
|
||||||
t,
|
t,
|
||||||
}: ReassignSheetProps) {
|
}: ReassignSheetProps) {
|
||||||
|
const todayKey = localDateString(new Date());
|
||||||
|
const dateKey = selectedDuty
|
||||||
|
? localDateString(new Date(selectedDuty.start_at))
|
||||||
|
: "";
|
||||||
|
const sheetTitle = selectedDuty
|
||||||
|
? dateKey === todayKey
|
||||||
|
? t("duty.today") + ", " + dateKeyToDDMM(dateKey)
|
||||||
|
: dateKeyToDDMM(dateKey)
|
||||||
|
: t("admin.reassign_duty");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sheet open={open} onOpenChange={(isOpen) => !isOpen && onRequestClose()}>
|
<Sheet open={open} onOpenChange={(isOpen) => !isOpen && onRequestClose()}>
|
||||||
<SheetContent
|
<SheetContent
|
||||||
@@ -96,13 +106,14 @@ export function ReassignSheet({
|
|||||||
aria-hidden
|
aria-hidden
|
||||||
/>
|
/>
|
||||||
<SheetHeader className="p-0">
|
<SheetHeader className="p-0">
|
||||||
<SheetTitle>{t("admin.reassign_duty")}</SheetTitle>
|
<SheetTitle>{sheetTitle}</SheetTitle>
|
||||||
<SheetDescription>{t("admin.select_user")}</SheetDescription>
|
<SheetDescription className="sr-only">
|
||||||
|
{t("admin.select_user")}
|
||||||
|
</SheetDescription>
|
||||||
</SheetHeader>
|
</SheetHeader>
|
||||||
{selectedDuty && (
|
{selectedDuty && (
|
||||||
<div className="flex flex-col gap-4 pt-2 pb-4">
|
<div className="flex flex-col gap-4 pt-2 pb-4">
|
||||||
<p className="text-sm text-muted-foreground">
|
<p className="text-sm text-muted-foreground">
|
||||||
{localDateString(new Date(selectedDuty.start_at))}{" "}
|
|
||||||
{formatHHMM(selectedDuty.start_at)} – {formatHHMM(selectedDuty.end_at)}
|
{formatHHMM(selectedDuty.start_at)} – {formatHHMM(selectedDuty.end_at)}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-xs text-muted-foreground">
|
<p className="text-xs text-muted-foreground">
|
||||||
@@ -113,11 +124,15 @@ export function ReassignSheet({
|
|||||||
{t("admin.no_users_for_assign")}
|
{t("admin.no_users_for_assign")}
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<div
|
<div className="flex flex-col gap-1">
|
||||||
className="flex flex-col gap-1 max-h-[40vh] overflow-y-auto rounded-lg border border-border py-1"
|
<p className="text-sm text-muted-foreground">
|
||||||
role="radiogroup"
|
{t("admin.select_user")}
|
||||||
aria-label={t("admin.select_user")}
|
</p>
|
||||||
>
|
<div
|
||||||
|
className="flex flex-col gap-1 max-h-[40vh] overflow-y-auto rounded-lg border border-border py-1"
|
||||||
|
role="radiogroup"
|
||||||
|
aria-label={t("admin.select_user")}
|
||||||
|
>
|
||||||
{users.map((u) => {
|
{users.map((u) => {
|
||||||
const isCurrent = u.id === selectedDuty.user_id;
|
const isCurrent = u.id === selectedDuty.user_id;
|
||||||
const isSelected = selectedUserId === u.id;
|
const isSelected = selectedUserId === u.id;
|
||||||
@@ -150,6 +165,7 @@ export function ReassignSheet({
|
|||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{reassignErrorKey && (
|
{reassignErrorKey && (
|
||||||
|
|||||||
Reference in New Issue
Block a user