improvement: delete action added for unsent treatment details. some edit controls added to details and shipments.

This commit is contained in:
2026-07-16 22:45:37 +03:30
parent 334b7841ae
commit cf07b4d8a8
7 changed files with 82 additions and 1 deletions

View File

@@ -1249,6 +1249,8 @@ export function TreatmentWorkspace({
const uploadForDetail = useCallback(
async (detailClientId: string, files: FileList | File[]) => {
if (!canEditTreatmentForDay || !selectedAppointment) return;
const target = detailsRef.current.find((d) => d.clientId === detailClientId);
if (target && isDetailLocked(target)) return;
const list = files instanceof FileList ? Array.from(files) : files;
if (!list.length) return;
@@ -1273,7 +1275,7 @@ export function TreatmentWorkspace({
setUploadBusyDetailId(null);
}
},
[canEditTreatmentForDay, selectedAppointment, showSuccess, showError, t],
[canEditTreatmentForDay, isDetailLocked, selectedAppointment, showSuccess, showError, t, tErrors],
);
const persistLabCases = useCallback(
@@ -1373,9 +1375,40 @@ export function TreatmentWorkspace({
selectedAppointment,
showError,
t,
tErrors,
],
);
const handleRemoveActiveDetail = useCallback(() => {
if (!canEditTreatmentForDay) return;
const idx = details.findIndex((d) => d.clientId === activeDetailId);
if (idx < 0) return;
const active = details[idx];
if (!active || isDetailLocked(active) || details.length <= 1) return;
if (!window.confirm(t('confirmRemoveDetail'))) return;
const removedId = active.clientId;
const nextDetails = details.filter((d) => d.clientId !== removedId);
const nextActive =
nextDetails[Math.min(idx, nextDetails.length - 1)]?.clientId ?? nextDetails[0]?.clientId;
setDetails(nextDetails);
if (nextActive) setActiveDetailId(nextActive);
if (labCaseDrafts.some((lc) => lc.detailClientId === removedId)) {
handleLabCasesChange(
withoutEmptyLabCaseDrafts(labCaseDrafts.filter((lc) => lc.detailClientId !== removedId)),
);
}
}, [
activeDetailId,
canEditTreatmentForDay,
details,
handleLabCasesChange,
isDetailLocked,
labCaseDrafts,
t,
]);
const handleAddLabCase = useCallback(async () => {
if (!canEditTreatmentForDay || !selectedAppointment) return;
@@ -1779,6 +1812,7 @@ export function TreatmentWorkspace({
setDetails((prev) => [...prev, next]);
setActiveDetailId(next.clientId);
}}
onRemoveDetail={handleRemoveActiveDetail}
onUploadFiles={(files) => void uploadForDetail(activeDetailId, files ?? [])}
/>