-
-
-
-
-
-
-
-
-
+
+
+ {
+ console.log(label)
+ }}
+ />
+
+
+
+
+
+
+
+
- >
+
)
}
diff --git a/apps/web/app/[locale]/timesheet/components/TimesheetFilterDate.tsx b/apps/web/app/[locale]/timesheet/components/TimesheetFilterDate.tsx
new file mode 100644
index 000000000..f6532210c
--- /dev/null
+++ b/apps/web/app/[locale]/timesheet/components/TimesheetFilterDate.tsx
@@ -0,0 +1,197 @@
+import { cn } from "@/lib/utils"
+import { DatePicker } from "@components/ui/DatePicker"
+import { Button } from "@components/ui/button"
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@components/ui/popover"
+import { CalendarIcon } from "@radix-ui/react-icons"
+import { format } from "date-fns"
+import React from "react"
+import { MdKeyboardArrowRight } from "react-icons/md"
+import { PiCalendarDotsThin } from "react-icons/pi"
+
+interface DatePickerInputProps {
+ date: Date | null;
+ label: string;
+}
+interface TimesheetFilterDateProps {
+ onChange?: (range: { from: Date | null; to: Date | null }) => void;
+ initialRange?: { from: Date | null; to: Date | null };
+ minDate?: Date;
+ maxDate?: Date;
+}
+
+export function TimesheetFilterDate({
+ onChange,
+ initialRange,
+ minDate,
+ maxDate
+}: TimesheetFilterDateProps) {
+
+ const [dateRange, setDateRange] = React.useState<{ from: Date | null; to: Date | null }>({
+ from: initialRange?.from ?? new Date(),
+ to: initialRange?.to ?? new Date(),
+ });
+
+ const handleFromChange = (fromDate: Date | null) => {
+ if (maxDate && fromDate && fromDate > maxDate) {
+ return;
+ }
+ setDateRange((prev) => ({ ...prev, from: fromDate }));
+ onChange?.({ ...dateRange, from: fromDate });
+ };
+
+ const handleToChange = (toDate: Date | null) => {
+ if (dateRange.from && toDate && toDate < dateRange.from) {
+ return;
+ }
+ setDateRange((prev) => ({ ...prev, to: toDate }));
+ };
+
+ const handlePresetClick = (preset: string) => {
+ const today = new Date();
+ switch (preset) {
+ case 'Today':
+ setDateRange({ from: today, to: today });
+ break;
+ case 'Last 7 days':
+ setDateRange({
+ from: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7),
+ to: today
+ });
+ break;
+ case 'Last 30 days':
+ setDateRange({
+ from: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 30),
+ to: today
+ });
+ break;
+ case `This year (${today.getFullYear()})`:
+ setDateRange({
+ from: new Date(today.getFullYear(), 0, 1),
+ to: today
+ });
+ break;
+ case 'Custom Date Range':
+ setDateRange({ from: null, to: null });
+ break;
+ default:
+ break;
+ }
+ };
+
+
+ return (<>
+
+
+
+
+
+
+
+
+
+
+ {["Today", "Last 7 days", "Last 30 days", `This year (${new Date().getFullYear()})`, "Custom Date Range"].map((label, index) => (
+
+ ))}
+
+
+
+ >
+ )
+}
+
+
+const DatePickerInput: React.FC
= ({ date, label }) => (
+ <>
+
+
+ >
+);
+
+export function DatePickerFilter({
+ label,
+ date,
+ setDate,
+ minDate,
+ maxDate
+}: {
+ label: string;
+ date: Date | null;
+ setDate: (date: Date | null) => void;
+ minDate?: Date | null;
+ maxDate?: Date | null
+
+}) {
+ const isDateDisabled = React.useCallback((date: Date) => {
+ if (minDate && date < minDate) return true;
+ if (maxDate && date > maxDate) return true;
+ return false;
+ }, [minDate, maxDate]);
+
+ return (
+
+ }
+ mode="single"
+ numberOfMonths={1}
+ initialFocus
+ defaultMonth={date ?? new Date()}
+ selected={date ?? new Date()}
+ onSelect={(selectedDate) => {
+ if (selectedDate && !isDateDisabled(selectedDate)) {
+ setDate(selectedDate);
+ }
+ }}
+ modifiersClassNames={{
+ disabled: 'text-gray-300 cursor-not-allowed',
+ }}
+ disabled={[
+ ...(minDate ? [{ before: minDate }] : []),
+ ...(maxDate ? [{ after: maxDate }] : [])
+ ]}
+ />
+
+ );
+}
diff --git a/apps/web/app/[locale]/timesheet/components/index.tsx b/apps/web/app/[locale]/timesheet/components/index.tsx
index 12cf616a7..ed9e14172 100644
--- a/apps/web/app/[locale]/timesheet/components/index.tsx
+++ b/apps/web/app/[locale]/timesheet/components/index.tsx
@@ -4,3 +4,4 @@ export * from './CalendarView';
export * from './TimesheetFilter';
export * from './FrequencySelect';
export * from './FilterWithStatus';
+export * from './TimesheetFilterDate';