feat(ticket): use grid picker for extension due date
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
import { Clock3, Loader2, Send } from 'lucide-react';
|
import { Clock3, Loader2, Send } from 'lucide-react';
|
||||||
|
|
||||||
import { DatePicker } from '@/components/form/DatePicker';
|
import { DatePicker } from '@/components/form/DatePicker';
|
||||||
|
import { DatePickerSimple } from '@/components/form/DatePickerSimple';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
@@ -22,9 +23,21 @@ export function RequestExtensionForm({
|
|||||||
ticket,
|
ticket,
|
||||||
onCancel,
|
onCancel,
|
||||||
}: RequestExtensionFormProps) {
|
}: RequestExtensionFormProps) {
|
||||||
const currentDueDate = ticket.worker?.due_at
|
const currentDueAt = ticket.worker?.due_at;
|
||||||
? new Date(ticket.worker.due_at)
|
const currentDueDate = useMemo(
|
||||||
: undefined;
|
() => (currentDueAt ? new Date(currentDueAt) : undefined),
|
||||||
|
[currentDueAt],
|
||||||
|
);
|
||||||
|
const earliestRequestedDate = useMemo(() => {
|
||||||
|
const date = currentDueDate ? new Date(currentDueDate) : new Date();
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
if (currentDueDate) date.setDate(date.getDate() + 1);
|
||||||
|
return date;
|
||||||
|
}, [currentDueDate]);
|
||||||
|
const latestRequestedMonth = useMemo(
|
||||||
|
() => new Date(earliestRequestedDate.getFullYear() + 5, 11),
|
||||||
|
[earliestRequestedDate],
|
||||||
|
);
|
||||||
const [requestedDueDate, setRequestedDueDate] = useState<Date>();
|
const [requestedDueDate, setRequestedDueDate] = useState<Date>();
|
||||||
const [reason, setReason] = useState('');
|
const [reason, setReason] = useState('');
|
||||||
const assignmentId = ticket.worker?.assignment_id;
|
const assignmentId = ticket.worker?.assignment_id;
|
||||||
@@ -81,12 +94,17 @@ export function RequestExtensionForm({
|
|||||||
<Label>
|
<Label>
|
||||||
Requested Due Date <span className="text-destructive">*</span>
|
Requested Due Date <span className="text-destructive">*</span>
|
||||||
</Label>
|
</Label>
|
||||||
<DatePicker
|
<DatePickerSimple
|
||||||
|
id="requested-due-date"
|
||||||
value={requestedDueDate}
|
value={requestedDueDate}
|
||||||
onChange={setRequestedDueDate}
|
onChange={setRequestedDueDate}
|
||||||
showTimeZone={false}
|
showLabel={false}
|
||||||
|
placeholder="Select requested due date"
|
||||||
disabled={isPending}
|
disabled={isPending}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
|
startMonth={earliestRequestedDate}
|
||||||
|
endMonth={latestRequestedMonth}
|
||||||
|
disabledDates={{ before: earliestRequestedDate }}
|
||||||
/>
|
/>
|
||||||
{requestedDueDate && !isRequestedDateValid ? (
|
{requestedDueDate && !isRequestedDateValid ? (
|
||||||
<p className="text-xs text-destructive">
|
<p className="text-xs text-destructive">
|
||||||
|
|||||||
Reference in New Issue
Block a user