refactor: update application locking logic to handle staff remarks and itemized rounds

This commit is contained in:
estifanos
2026-08-27 12:37:04 +00:00
parent 88a1caa52b
commit e86375e761

View File

@@ -352,14 +352,18 @@ export function LicenseApplicationPage() {
),
[roundRemarks],
);
const hasSectionRemarks = Object.keys(flaggedSections).length > 0;
const hasDocRemarks = Object.keys(flaggedDocuments).length > 0;
const hasStaffRemarks = roundRemarks.some((r) => r.targetType === "STAFF");
// Nothing at all came back for this round (a detail response that predates
// the remarks, say) — lock nothing rather than freeze the whole application
// with no way forward. Any remark present means the round is itemised, so
// only what the officer flagged opens: a documents-only round leaves every
// form section frozen, and a sections-only round leaves every document as
// filed.
const roundIsItemised = isAdjusting && roundRemarks.length > 0;
// A round that flagged no form sections carries no section locks — mirror of
// the server's fallback, without which a documents-only correction round
// froze every field and the applicant could not edit anything at all.
const isSectionLocked = (sectionKey: string) =>
isAdjusting && hasSectionRemarks && !flaggedSections[sectionKey];
roundIsItemised && !flaggedSections[sectionKey];
const staffLocked = roundIsItemised && !hasStaffRemarks;
// Sections that share a group collapse onto one step, so the stepper stays
// short instead of showing a page per section.
@@ -862,7 +866,7 @@ export function LicenseApplicationPage() {
complete
</Badge>
)}
{!readOnly && (
{!readOnly && !staffLocked && (
<Button
size="xs"
variant="light"
@@ -898,7 +902,7 @@ export function LicenseApplicationPage() {
: ""}
</Text>
</div>
{!readOnly && (
{!readOnly && !staffLocked && (
<ActionIcon
variant="subtle"
color="red"
@@ -917,7 +921,7 @@ export function LicenseApplicationPage() {
<StaffEvidence
staffId={member.id}
evidence={role.requiredEvidence}
readOnly={readOnly}
readOnly={readOnly || staffLocked}
onUploaded={refetch}
/>
</Card>
@@ -937,7 +941,7 @@ export function LicenseApplicationPage() {
ownerType="APPLICATION"
ownerId={appId}
flagged={flaggedDocuments}
restrictToFlagged={isAdjusting && hasDocRemarks}
restrictToFlagged={roundIsItemised}
readOnly={readOnly}
onUploaded={() => {
refetchAttachments();