bugfix: selecting past dates is now possible in appointment and treatment features. bur, add, edit and delete actions are disabled for past dates.
This commit is contained in:
@@ -12,8 +12,6 @@ interface AppointmentsStripProps {
|
||||
onToggleStripHidden: () => void;
|
||||
selectedDay: Date;
|
||||
onSelectDay: (day: Date) => void;
|
||||
/** Same lower bound as Appointments schedule (cannot pick days before this). */
|
||||
minScheduleDate: Date;
|
||||
appointments: TreatmentAppointment[];
|
||||
selectedAppointmentId: string | null;
|
||||
onSelectAppointment: (id: string) => void;
|
||||
@@ -25,7 +23,6 @@ export function AppointmentsStrip({
|
||||
onToggleStripHidden,
|
||||
selectedDay,
|
||||
onSelectDay,
|
||||
minScheduleDate,
|
||||
appointments,
|
||||
selectedAppointmentId,
|
||||
onSelectAppointment,
|
||||
@@ -65,7 +62,6 @@ export function AppointmentsStrip({
|
||||
<div className="flex flex-col sm:flex-row sm:items-end gap-4 sm:justify-between">
|
||||
<ScheduleDayPicker
|
||||
value={selectedDay}
|
||||
minDate={minScheduleDate}
|
||||
onChange={(d) => onSelectDay(startOfLocalDay(d))}
|
||||
/>
|
||||
{loading && (
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Button } from '@/components/ui/shared/Button';
|
||||
import { Dropdown } from '@/components/ui/shared/Dropdown';
|
||||
import { SearchBar } from '@/components/ui/shared/SearchBar';
|
||||
import { Toast } from '@/components/ui/shared/Toast';
|
||||
import { isSameLocalCalendarDay, startOfLocalDay } from '@/lib/appointmentTime';
|
||||
import { compareLocalDayStart, isSameLocalCalendarDay, startOfLocalDay } from '@/lib/appointmentTime';
|
||||
import {
|
||||
fetchLinkedOrganizations,
|
||||
fetchMyAppointmentsForDay,
|
||||
@@ -54,7 +54,7 @@ export function TreatmentWorkspace({ userId, currentOrganization }: TreatmentWor
|
||||
|
||||
const [stripHidden, setStripHidden] = useState(false);
|
||||
|
||||
const scheduleMinDate = useMemo(() => startOfLocalDay(new Date()), []);
|
||||
const todayStart = useMemo(() => startOfLocalDay(new Date()), []);
|
||||
|
||||
const [selectedDay, setSelectedDay] = useState(() => startOfLocalDay(new Date()));
|
||||
const [appointments, setAppointments] = useState<TreatmentAppointment[]>([]);
|
||||
@@ -87,6 +87,13 @@ export function TreatmentWorkspace({ userId, currentOrganization }: TreatmentWor
|
||||
[appointments, selectedAppointmentId],
|
||||
);
|
||||
|
||||
const isViewingPastDay = useMemo(
|
||||
() => compareLocalDayStart(selectedDay, todayStart) < 0,
|
||||
[selectedDay, todayStart],
|
||||
);
|
||||
|
||||
const canEditTreatmentForDay = Boolean(selectedAppointment) && !isViewingPastDay;
|
||||
|
||||
const activeRecord = useMemo(
|
||||
() => records.find((r) => r.clientId === activeRecordId) ?? records[0],
|
||||
[records, activeRecordId],
|
||||
@@ -339,13 +346,19 @@ export function TreatmentWorkspace({ userId, currentOrganization }: TreatmentWor
|
||||
onToggleStripHidden={() => setStripHidden((s) => !s)}
|
||||
selectedDay={selectedDay}
|
||||
onSelectDay={setSelectedDay}
|
||||
minScheduleDate={scheduleMinDate}
|
||||
appointments={appointments}
|
||||
selectedAppointmentId={selectedAppointmentId}
|
||||
onSelectAppointment={onPickAppointment}
|
||||
loading={apptsLoading}
|
||||
/>
|
||||
|
||||
{isViewingPastDay && (
|
||||
<p className="text-sm text-text-secondary rounded-[var(--radius-md)] border border-border/60 bg-background-secondary/50 px-3 py-2">
|
||||
Past days are view-only. You can review appointments and history, but treatment records
|
||||
cannot be added or changed.
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-1 xl:grid-cols-[minmax(280px,380px)_minmax(0,1fr)] gap-6 items-start">
|
||||
<div className="space-y-4">
|
||||
{selectedAppointment ? (
|
||||
@@ -423,7 +436,7 @@ export function TreatmentWorkspace({ userId, currentOrganization }: TreatmentWor
|
||||
<FdiToothChart
|
||||
selected={selectedTeethSet}
|
||||
onToggle={toggleTooth}
|
||||
disabled={!selectedAppointment}
|
||||
disabled={!canEditTreatmentForDay}
|
||||
/>
|
||||
|
||||
<div className="surface-card p-4 space-y-4">
|
||||
@@ -437,7 +450,7 @@ export function TreatmentWorkspace({ userId, currentOrganization }: TreatmentWor
|
||||
<Button
|
||||
type="button"
|
||||
variant="primary"
|
||||
disabled={!selectedAppointment}
|
||||
disabled={!canEditTreatmentForDay}
|
||||
onClick={() => {
|
||||
const nr = newRecord();
|
||||
fixActiveAfterRecordsChange([...records, nr]);
|
||||
@@ -486,7 +499,7 @@ export function TreatmentWorkspace({ userId, currentOrganization }: TreatmentWor
|
||||
}}
|
||||
placeholder="Write clinical notes for this record…"
|
||||
rows={5}
|
||||
disabled={!selectedAppointment}
|
||||
disabled={!canEditTreatmentForDay}
|
||||
className="mt-1.5 w-full rounded-[var(--radius-md)] border border-border bg-background-secondary/90 text-text-primary text-sm px-3 py-2 placeholder:text-text-muted focus:outline-none focus:ring-2 focus:ring-primary/35 resize-y min-h-[120px]"
|
||||
/>
|
||||
</label>
|
||||
@@ -503,7 +516,7 @@ export function TreatmentWorkspace({ userId, currentOrganization }: TreatmentWor
|
||||
),
|
||||
);
|
||||
}}
|
||||
disabled={!selectedAppointment}
|
||||
disabled={!canEditTreatmentForDay}
|
||||
className="capitalize"
|
||||
style={{ color: treatmentTypeTextColor }}
|
||||
>
|
||||
@@ -522,7 +535,7 @@ export function TreatmentWorkspace({ userId, currentOrganization }: TreatmentWor
|
||||
id="treatment-record-attachments"
|
||||
type="file"
|
||||
multiple
|
||||
disabled={!selectedAppointment}
|
||||
disabled={!canEditTreatmentForDay}
|
||||
onChange={(e) => {
|
||||
addAttachments(e.target.files);
|
||||
e.target.value = '';
|
||||
@@ -533,7 +546,7 @@ export function TreatmentWorkspace({ userId, currentOrganization }: TreatmentWor
|
||||
<Button
|
||||
type="button"
|
||||
variant="primary"
|
||||
disabled={!selectedAppointment}
|
||||
disabled={!canEditTreatmentForDay}
|
||||
onClick={() => attachmentInputRef.current?.click()}
|
||||
aria-controls="treatment-record-attachments"
|
||||
>
|
||||
@@ -589,7 +602,7 @@ export function TreatmentWorkspace({ userId, currentOrganization }: TreatmentWor
|
||||
<Checkbox
|
||||
key={o.id}
|
||||
checked={activeRecord.sendToOrganizationIds.includes(o.id)}
|
||||
disabled={!selectedAppointment || Boolean(activeRecord.sentAt)}
|
||||
disabled={!canEditTreatmentForDay || Boolean(activeRecord.sentAt)}
|
||||
onChange={(checked) => {
|
||||
setRecords((prev) =>
|
||||
prev.map((r) => {
|
||||
@@ -614,7 +627,7 @@ export function TreatmentWorkspace({ userId, currentOrganization }: TreatmentWor
|
||||
<Button
|
||||
type="button"
|
||||
variant="primary"
|
||||
disabled={!selectedAppointment || Boolean(activeRecord.sentAt) || sendBusyId === activeRecord.clientId}
|
||||
disabled={!canEditTreatmentForDay || Boolean(activeRecord.sentAt) || sendBusyId === activeRecord.clientId}
|
||||
isLoading={sendBusyId === activeRecord.clientId}
|
||||
onClick={() => void handleSendRecord(activeRecord)}
|
||||
>
|
||||
@@ -633,7 +646,7 @@ export function TreatmentWorkspace({ userId, currentOrganization }: TreatmentWor
|
||||
<Button
|
||||
type="button"
|
||||
variant="primary"
|
||||
disabled={!selectedAppointment || saveBusy}
|
||||
disabled={!canEditTreatmentForDay || saveBusy}
|
||||
isLoading={saveBusy}
|
||||
onClick={() => void handleSaveAll()}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user