Skip to content

Commit

Permalink
feat: display day and time of shift in dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
seandreassen committed Oct 29, 2024
1 parent fb846a8 commit 8e4944d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 19 deletions.
1 change: 0 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
"onShift": "{count, plural, =0 {Closed} =1 {1 person on shift} other {# people on shift}}"
},
"scheduleCellDialog": {
"onShift": "On shift",
"empty": "No-one on shift",
"registerSection": {
"recurring": "Recurring",
Expand Down
1 change: 0 additions & 1 deletion messages/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
"onShift": "{count, plural, =0 {Stengt} =1 {1 person på vakt} other {# personer på vakt}}"
},
"scheduleCellDialog": {
"onShift": "På vakt",
"empty": "Ingen på vakt",
"registerSection": {
"recurring": "Gjentagende",
Expand Down
15 changes: 12 additions & 3 deletions src/components/shift-schedule/ScheduleCell.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { ScheduleCellContent } from '@/components/shift-schedule/ScheduleCellContent';
import { ScheduleCellDialog } from '@/components/shift-schedule/ScheduleCellDialog';
import type { ScheduleCellProps } from '@/components/shift-schedule/ScheduleTable';
import { Dialog, DialogContent, DialogTrigger } from '@/components/ui/Dialog';
import React from 'react';

function ScheduleCell({ members }: ScheduleCellProps) {
type ScheduleCellProps = {
messages: {
day: string;
time: string;
};
members: {
name: string;
}[];
};

function ScheduleCell({ messages, members }: ScheduleCellProps) {
return (
<Dialog>
<DialogTrigger asChild>
<ScheduleCellContent members={members} />
</DialogTrigger>
<DialogContent className='w-1/3 min-w-80 p-3'>
<ScheduleCellDialog members={members} />
<ScheduleCellDialog messages={messages} members={members} />
</DialogContent>
</Dialog>
);
Expand Down
11 changes: 8 additions & 3 deletions src/components/shift-schedule/ScheduleCellContent.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import type { ScheduleCellProps } from '@/components/shift-schedule/ScheduleTable';
import { TableCell } from '@/components/ui/Table';
import { cx } from '@/lib/utils';
import { UserIcon, UsersIcon } from 'lucide-react';
import { useTranslations } from 'next-intl';
import type React from 'react';

function ScheduleCellContent({ members }: ScheduleCellProps) {
type ScheduleCellContentProps = {
members: {
name: string;
}[];
};

function ScheduleCellContent({ members }: ScheduleCellContentProps) {
const t = useTranslations('shiftSchedule.scheduleTable.scheduleCellContent');

const colorStyle =
Expand All @@ -26,7 +31,7 @@ function ScheduleCellContent({ members }: ScheduleCellProps) {
let memberCountIcon: React.ReactNode;
if (members.length === 1) {
memberCountIcon = <UserIcon className={memberCountIconStyle} />;
} else if (members.length >= 1) {
} else if (members.length > 1) {
memberCountIcon = <UsersIcon className={memberCountIconStyle} />;
}

Expand Down
18 changes: 14 additions & 4 deletions src/components/shift-schedule/ScheduleCellDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { RegisterSection } from '@/components/shift-schedule/RegisterSection';
import type { ScheduleCellProps } from '@/components/shift-schedule/ScheduleTable';
import { DialogHeader, DialogTitle } from '@/components/ui/Dialog';
import { useTranslations } from 'next-intl';

function ScheduleCellDialog({ members }: ScheduleCellProps) {
type ScheduleCellDialogProps = {
messages: {
day: string;
time: string;
};
members: {
name: string;
}[];
};

function ScheduleCellDialog({ messages, members }: ScheduleCellDialogProps) {
const t = useTranslations('shiftSchedule.scheduleTable.scheduleCellDialog');

let membersDisplay: React.ReactNode;
Expand All @@ -26,8 +35,9 @@ function ScheduleCellDialog({ members }: ScheduleCellProps) {
return (
<>
<DialogHeader>
<DialogTitle className='font-semibold text-3xl'>
{t('onShift')}
<DialogTitle className='space-x-5'>
<span className='font-semibold text-3xl'>{messages.day}</span>
<span className='font-semibold text-lg'>{messages.time}</span>
</DialogTitle>
</DialogHeader>
<section className='flex justify-between gap-8 px-1.5 pb-1.5'>
Expand Down
27 changes: 20 additions & 7 deletions src/components/shift-schedule/ScheduleTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import {
} from '@/components/ui/Table';
import { useTranslations } from 'next-intl';

export type ScheduleCellProps = {
export type ScheduleEntryProps = {
members: {
name: string;
}[];
};

type ScheduleDayProps = {
'10:15 - 12:07': ScheduleCellProps;
'12:07 - 14:07': ScheduleCellProps;
'14:07 - 16:07': ScheduleCellProps;
'16:07 - 18:00': ScheduleCellProps;
'10:15 - 12:07': ScheduleEntryProps;
'12:07 - 14:07': ScheduleEntryProps;
'14:07 - 16:07': ScheduleEntryProps;
'16:07 - 18:00': ScheduleEntryProps;
};

type ScheduleTableProps = {
Expand Down Expand Up @@ -66,7 +66,13 @@ function ScheduleTable({ week }: ScheduleTableProps) {
{times.map((time) => (
<TableRow key={time}>
<TableCell className='border-y'>{time}</TableCell>
<ScheduleCell members={week[day][time].members} />
<ScheduleCell
messages={{
day: t(day),
time: time,
}}
members={week[day][time].members}
/>
</TableRow>
))}
</TableBody>
Expand Down Expand Up @@ -94,7 +100,14 @@ function ScheduleTable({ week }: ScheduleTableProps) {
<TableRow key={time}>
<TableCell className='min-w-32 border-y'>{time}</TableCell>
{days.map((day) => (
<ScheduleCell key={day} members={week[day][time].members} />
<ScheduleCell
key={day}
messages={{
day: t(day),
time: time,
}}
members={week[day][time].members}
/>
))}
</TableRow>
))}
Expand Down

0 comments on commit 8e4944d

Please sign in to comment.