Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | 11x 1x 1x 1x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 264x 1056x 11x 11x 185x 185x 185x 185x 185x 185x 185x 5x 5x 5x 5x 5x 185x 5x 5x 185x 2x 2x 2x 2x 2x 1x 1x 2x 185x 5x 5x 5x 5x 5x 5x 1x 1x 4x 5x 185x 5x 5x 5x 1x 1x 4x 1x 1x 3x 3x 1x 1x 2x 185x 185x 44x 4x 4x 176x 5x 3x 3x 1x 4224x 1x | import { useMutation, useQueryClient } from "@tanstack/react-query";
import { AlertCircle, X } from "lucide-react";
import { useCallback, useState } from "react";
import { crmApi } from "../../lib/api";
import { queryKeys } from "../../lib/query-keys";
import { Button } from "../ui/button";
// ─── Constants ───────────────────────────────────────────────────────────────
const QUICK_SHORTCUTS = [
{
label: "In 1 hour",
getDate: () => {
const d = new Date();
d.setMinutes(d.getMinutes() + 60);
return d;
},
},
{
label: "Tomorrow 10 AM",
getDate: () => {
const d = new Date();
d.setDate(d.getDate() + 1);
d.setHours(10, 0, 0, 0);
return d;
},
},
{
label: "In 3 days",
getDate: () => {
const d = new Date();
d.setDate(d.getDate() + 3);
d.setHours(10, 0, 0, 0);
return d;
},
},
{
label: "Next week",
getDate: () => {
const d = new Date();
d.setDate(d.getDate() + 7);
d.setHours(10, 0, 0, 0);
return d;
},
},
];
function generateTimeOptions(): string[] {
const options: string[] = [];
for (let h = 0; h < 24; h++) {
for (let m = 0; m < 60; m += 15) {
options.push(
`${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}`,
);
}
}
return options;
}
const TIME_OPTIONS = generateTimeOptions();
// ─── Component ───────────────────────────────────────────────────────────────
type SetReminderDialogProps = {
proId: string;
leadId: number;
open: boolean;
onClose: () => void;
additionalInvalidations?: readonly (readonly string[])[];
};
export function SetReminderDialog({
proId,
leadId,
open,
onClose,
additionalInvalidations,
}: SetReminderDialogProps) {
const queryClient = useQueryClient();
const [title, setTitle] = useState("");
const [date, setDate] = useState("");
const [time, setTime] = useState("10:00");
const [notes, setNotes] = useState("");
const [error, setError] = useState<string | null>(null);
const reset = useCallback(() => {
setTitle("");
setDate("");
setTime("10:00");
setNotes("");
setError(null);
}, []);
const handleClose = useCallback(() => {
reset();
onClose();
}, [reset, onClose]);
const createMutation = useMutation({
mutationFn: async (data: {
title: string;
dueAt: number;
notes?: string;
}) => crmApi.createReminder(proId, leadId, data),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: queryKeys.crm.reminders(proId, String(leadId)),
});
queryClient.invalidateQueries({
queryKey: queryKeys.crm.reminderCounts(proId),
});
queryClient.invalidateQueries({
queryKey: queryKeys.crm.activities(proId, String(leadId)),
});
if (additionalInvalidations) {
for (const key of additionalInvalidations) {
queryClient.invalidateQueries({ queryKey: key });
}
}
handleClose();
},
onError: (err: Error) => {
setError(err.message || "Failed to create reminder");
},
});
const applyShortcut = useCallback(
(shortcut: (typeof QUICK_SHORTCUTS)[number]) => {
const d = shortcut.getDate();
setDate(d.toISOString().slice(0, 10));
const hh = String(d.getHours()).padStart(2, "0");
const roundedMin = Math.ceil(d.getMinutes() / 15) * 15;
const mm = String(roundedMin % 60).padStart(2, "0");
// If rounding pushes past 60, bump hour
if (roundedMin >= 60) {
const adjustedH = String(d.getHours() + 1).padStart(2, "0");
setTime(`${adjustedH}:00`);
} else {
setTime(`${hh}:${mm}`);
}
setError(null);
},
[],
);
const handleSubmit = useCallback(
(e: React.FormEvent) => {
e.preventDefault();
setError(null);
if (!title.trim()) {
setError("Title is required");
return;
}
if (!date) {
setError("Date is required");
return;
}
const dueAt = Math.floor(
new Date(`${date}T${time}`).getTime() / 1000,
);
if (dueAt <= Math.floor(Date.now() / 1000)) {
setError("Reminder must be in the future");
return;
}
createMutation.mutate({
title: title.trim(),
dueAt,
notes: notes.trim() || undefined,
});
},
[title, date, time, notes, createMutation],
);
const today = new Date().toISOString().split("T")[0];
if (!open) return null;
return (
<div
role="dialog"
className="fixed inset-0 z-[62] flex flex-col justify-end sm:flex-row sm:items-center sm:justify-center"
>
<button
type="button"
aria-label="Close"
className="fixed inset-0 bg-black/50 cursor-default"
onClick={handleClose}
tabIndex={-1}
/>
<div className="relative z-10 bg-background-base rounded-t-2xl sm:rounded-lg sm:shadow-xl w-full sm:max-w-md mx-2 sm:mx-4 animate-slide-up sm:animate-none max-h-[85vh] flex flex-col">
<div className="flex items-center justify-between border-b border-border-default bg-background-elevated px-4 py-3 rounded-t-2xl flex-shrink-0">
<h2 className="text-lg font-semibold text-foreground-default">
Set Reminder
</h2>
<button
type="button"
onClick={handleClose}
className="p-1.5 text-foreground-subtle hover:text-foreground-default rounded-md"
aria-label="Close"
>
<X className="h-5 w-5" />
</button>
</div>
<form onSubmit={handleSubmit} className="flex-1 overflow-y-auto p-4 space-y-4">
{/* Title */}
<div>
<label
htmlFor="reminder-title"
className="block text-sm font-medium text-foreground-default mb-1"
>
Title <span className="text-error">*</span>
</label>
<input
id="reminder-title"
type="text"
value={title}
onChange={(e) => {
setTitle(e.target.value);
setError(null);
}}
className="w-full h-10 px-3 rounded-md border border-border-default bg-background-elevated text-foreground-default focus:ring-2 focus:ring-primary-500"
placeholder="e.g., Follow up on quote"
/>
</div>
{/* Quick shortcuts */}
<div>
<span className="block text-xs font-medium text-foreground-subtle mb-2">
Quick set
</span>
<div className="flex flex-wrap gap-2">
{QUICK_SHORTCUTS.map((shortcut) => (
<button
key={shortcut.label}
type="button"
onClick={() => applyShortcut(shortcut)}
className="px-3 py-1.5 text-xs font-medium rounded-full border border-border-default text-foreground-default hover:bg-primary-100 hover:text-primary-700 hover:border-primary-300 transition-colors"
>
{shortcut.label}
</button>
))}
</div>
</div>
<div className="relative">
<div className="absolute inset-0 flex items-center">
<div className="w-full border-t border-border-default" />
</div>
<div className="relative flex justify-center text-xs">
<span className="px-2 bg-background-elevated text-foreground-subtle">
or set specific time
</span>
</div>
</div>
{/* Date + Time */}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label
htmlFor="reminder-date"
className="block text-sm font-medium text-foreground-default mb-1"
>
Date
</label>
<input
id="reminder-date"
type="date"
value={date}
onChange={(e) => {
setDate(e.target.value);
setError(null);
}}
min={today}
className="w-full h-10 px-3 rounded-md border border-border-default bg-background-elevated text-foreground-default focus:ring-2 focus:ring-primary-500"
/>
</div>
<div>
<label
htmlFor="reminder-time"
className="block text-sm font-medium text-foreground-default mb-1"
>
Time
</label>
<select
id="reminder-time"
value={time}
onChange={(e) => setTime(e.target.value)}
className="w-full h-10 px-3 rounded-md border border-border-default bg-background-elevated text-foreground-default focus:ring-2 focus:ring-primary-500"
>
{TIME_OPTIONS.map((t) => (
<option key={t} value={t}>
{t}
</option>
))}
</select>
</div>
</div>
{/* Notes */}
<div>
<label
htmlFor="reminder-notes"
className="block text-sm font-medium text-foreground-default mb-1"
>
Notes
</label>
<textarea
id="reminder-notes"
value={notes}
onChange={(e) => setNotes(e.target.value)}
rows={2}
className="w-full px-3 py-2 text-sm rounded-md border border-border-default bg-background-elevated text-foreground-default focus:ring-2 focus:ring-primary-500 resize-none"
placeholder="Optional notes..."
/>
</div>
{error && (
<div className="flex items-center gap-2 text-sm text-error">
<AlertCircle className="h-4 w-4 flex-shrink-0" />
{error}
</div>
)}
<div className="flex justify-end gap-3 pt-2">
<Button type="button" variant="outline" onClick={handleClose}>
Cancel
</Button>
<Button type="submit" isLoading={createMutation.isPending}>
Set Reminder
</Button>
</div>
</form>
</div>
</div>
);
}
|