feat: add quick duration selectors (+15 min, +30 min, +1h, +3h) in event dialog
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { addHours, addMinutes, isValid, parseISO } from "date-fns";
|
||||||
import { LucideMapPin } from "lucide-react";
|
import { LucideMapPin } from "lucide-react";
|
||||||
import { DateTimePicker } from "@/components/date-time-picker";
|
import { DateTimePicker } from "@/components/date-time-picker";
|
||||||
import { RecurrencePicker } from "@/components/recurrence-picker";
|
import { RecurrencePicker } from "@/components/recurrence-picker";
|
||||||
@@ -68,6 +69,26 @@ export const EventDialog = ({
|
|||||||
onOpenChange(val);
|
onOpenChange(val);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DURATIONS = [
|
||||||
|
{ label: "+15 min", minutes: 15 },
|
||||||
|
{ label: "+30 min", minutes: 30 },
|
||||||
|
{ label: "+1 hour", minutes: 60 },
|
||||||
|
{ label: "+3 hours", minutes: 180 },
|
||||||
|
];
|
||||||
|
|
||||||
|
const handleApplyDuration = (minutes: number) => {
|
||||||
|
if (!start) return;
|
||||||
|
const base = parseISO(start);
|
||||||
|
if (!isValid(base)) return;
|
||||||
|
const next =
|
||||||
|
minutes < 60 ? addMinutes(base, minutes) : addHours(base, minutes / 60);
|
||||||
|
const pad = (n: number) => String(n).padStart(2, "0");
|
||||||
|
const result = allDay
|
||||||
|
? `${next.getFullYear()}-${pad(next.getMonth() + 1)}-${pad(next.getDate())}`
|
||||||
|
: `${next.getFullYear()}-${pad(next.getMonth() + 1)}-${pad(next.getDate())}T${pad(next.getHours())}:${pad(next.getMinutes())}:00`;
|
||||||
|
setEnd(result);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={handleOpenChange}>
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||||
<DialogContent className="glass-strong max-w-md">
|
<DialogContent className="glass-strong max-w-md">
|
||||||
@@ -146,6 +167,21 @@ export const EventDialog = ({
|
|||||||
allDay={allDay}
|
allDay={allDay}
|
||||||
placeholder="Start date"
|
placeholder="Start date"
|
||||||
/>
|
/>
|
||||||
|
{!allDay && (
|
||||||
|
<div className="flex gap-1 pl-0.5">
|
||||||
|
{DURATIONS.map(({ label, minutes }) => (
|
||||||
|
<button
|
||||||
|
key={label}
|
||||||
|
type="button"
|
||||||
|
disabled={!start}
|
||||||
|
onClick={() => handleApplyDuration(minutes)}
|
||||||
|
className="rounded-md px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-40"
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<DateTimePicker
|
<DateTimePicker
|
||||||
value={end}
|
value={end}
|
||||||
onChange={setEnd}
|
onChange={setEnd}
|
||||||
|
|||||||
Reference in New Issue
Block a user