Skip to content

Commit 38ac4f2

Browse files
[dev] [carhartlewis] lewis/comp-join-date-calendar-cs-68 (#2112)
* feat(context): resolve framework IDs to human-readable names in context entries * refactor(auditor): exclude framework selection and auditor sections from context * feat(people): enhance JoinDate component with date parsing and dropdown * refactor(people): simplify JoinDate component by removing date parsing logic * refactor(people): update label in JoinDate component to 'Join Date' * fix(people): add button type to Done button in JoinDate component --------- Co-authored-by: Lewis Carhart <lewis@trycomp.ai>
1 parent d5d7ba1 commit 38ac4f2

1 file changed

Lines changed: 54 additions & 37 deletions

File tree

  • apps/app/src/app/(app)/[orgId]/people/[employeeId]/components/Fields
Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
'use client';
2+
13
import { Button } from '@comp/ui/button';
2-
import { Calendar } from '@comp/ui/calendar';
3-
import { cn } from '@comp/ui/cn';
44
import { FormControl, FormField, FormItem, FormLabel, FormMessage } from '@comp/ui/form';
55
import { Popover, PopoverContent, PopoverTrigger } from '@comp/ui/popover';
6+
import { Calendar } from '@trycompai/design-system';
67
import { format } from 'date-fns';
7-
import { CalendarIcon } from 'lucide-react';
8+
import { ChevronDown } from 'lucide-react';
9+
import { useState } from 'react';
810
import type { Control } from 'react-hook-form';
911
import type { EmployeeFormValues } from '../EmployeeDetails';
1012

@@ -15,45 +17,60 @@ export const JoinDate = ({
1517
control: Control<EmployeeFormValues>;
1618
disabled: boolean;
1719
}) => {
20+
const [open, setOpen] = useState(false);
21+
1822
return (
1923
<FormField
2024
control={control}
2125
name="createdAt"
22-
render={({ field }) => (
23-
<FormItem className="flex flex-col">
24-
<FormLabel className="text-muted-foreground text-xs font-medium uppercase">
25-
Join Date
26-
</FormLabel>
27-
<Popover>
28-
<PopoverTrigger asChild disabled={disabled}>
29-
<FormControl>
30-
<Button
31-
variant={'outline'}
32-
className={cn(
33-
'h-10 pl-3 text-left font-normal', // Use h-10 for consistency
34-
!field.value && 'text-muted-foreground',
35-
)}
26+
render={({ field }) => {
27+
return (
28+
<FormItem className="flex flex-col">
29+
<FormControl>
30+
<Popover open={disabled ? false : open} onOpenChange={disabled ? undefined : setOpen}>
31+
<FormLabel
32+
htmlFor="date-picker-with-dropdowns-desktop"
33+
className="text-muted-foreground text-xs font-medium uppercase"
3634
>
37-
{field.value ? format(field.value, 'PPP') : <span>Pick a date</span>}
38-
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
39-
</Button>
40-
</FormControl>
41-
</PopoverTrigger>
42-
<PopoverContent className="w-auto p-0" align="start">
43-
<Calendar
44-
mode="single"
45-
selected={field.value}
46-
onSelect={field.onChange}
47-
disabled={
48-
(date: Date) => date > new Date() // Explicitly type the date argument
49-
}
50-
initialFocus
51-
/>
52-
</PopoverContent>
53-
</Popover>
54-
<FormMessage />
55-
</FormItem>
56-
)}
35+
Join Date
36+
</FormLabel>
37+
<PopoverTrigger asChild>
38+
<Button
39+
variant="outline"
40+
id="date-picker-with-dropdowns-desktop"
41+
className="justify-start px-2.5 font-normal"
42+
disabled={disabled}
43+
>
44+
{field.value ? format(field.value, 'PPP') : <span>Pick a date</span>}
45+
<ChevronDown className="ml-auto font-light size-4 opacity-50" />
46+
</Button>
47+
</PopoverTrigger>
48+
<PopoverContent className="w-auto p-0" align="start">
49+
<Calendar
50+
mode="single"
51+
selected={field.value}
52+
onSelect={(date) => date && field.onChange(date)}
53+
captionLayout="dropdown"
54+
disabled={(date) => date > new Date()}
55+
/>
56+
<div className="flex gap-2 border-t p-2">
57+
<Button
58+
variant="outline"
59+
size="sm"
60+
className="w-full"
61+
type="button"
62+
onClick={() => setOpen(false)}
63+
>
64+
Done
65+
</Button>
66+
</div>
67+
</PopoverContent>
68+
</Popover>
69+
</FormControl>
70+
<FormMessage />
71+
</FormItem>
72+
);
73+
}}
5774
/>
5875
);
5976
};

0 commit comments

Comments
 (0)