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 | 105x 105x 105x 105x 105x 105x 105x 8x 105x 5x 105x 398x 274x 105x 105x 13x 105x 111x 105x 3x 3x 105x 10x 10x 10x 10x 2x 10x 105x 138x 138x 138x 247x 247x 111x 136x 136x 105x 105x 1557x 42x 23x 23x 23x 23x 23x 105x 41x 41x 35x 6x | import { Authority, opensearch, SEATOOL_STATUS } from "shared-types";
import { getDashboardTabForAuthority } from "./crumbs";
export const DRAFT_CONTINUE_ACTION_LABEL = "Continue Package";
export const DRAFT_DELETE_ACTION_LABEL = "Delete Package";
export const DRAFT_DELETE_MODAL_HEADER = "Confirm delete";
export const DRAFT_DELETE_MODAL_BODY =
"This action cannot be undone. Are you sure you want to delete this draft package?";
export const DRAFT_ID_CONFLICT_MESSAGE =
"This package ID is already in use. Update the ID before saving or submitting.";
const DRAFT_ID_CONFLICT_FIELD_MESSAGES: Record<string, string> = {
"new-medicaid-submission":
"According to our records, this SPA ID already exists. Please check the SPA ID and try entering it again.",
"new-chip-submission":
"According to our records, this SPA ID already exists. Please check the SPA ID and try entering it again.",
"new-chip-details-submission":
"According to our records, this SPA ID already exists. Please check the SPA ID and try entering it again.",
"capitated-initial":
"According to our records, this 1915(b) Waiver Number already exists. Please check the 1915(b) Waiver Number and try entering it again.",
"contracting-initial":
"According to our records, this 1915(b) Waiver Number already exists. Please check the 1915(b) Waiver Number and try entering it again.",
"capitated-renewal":
"According to our records, this 1915(b) Waiver Renewal Number already exists. Please check the 1915(b) Waiver Renewal Number and try entering it again.",
"contracting-renewal":
"According to our records, this 1915(b) Waiver Renewal Number already exists. Please check the 1915(b) Waiver Renewal Number and try entering it again.",
"capitated-amendment":
"According to our records, this 1915(b) Waiver Amendment Number already exists. Please check the 1915(b) Waiver Amendment Number and try entering it again.",
"contracting-amendment":
"According to our records, this 1915(b) Waiver Amendment Number already exists. Please check the 1915(b) Waiver Amendment Number and try entering it again.",
"temporary-extension":
"According to our records, this Temporary Extension Request Number already exists. Please check the Temporary Extension Request Number and try entering it again.",
"app-k":
"According to our records, this Waiver Amendment Number already exists. Please check the Waiver Amendment Number and try entering it again.",
};
export const getNonOwnerDraftWarningModalBody = (packageId: string) =>
`Since you are not the creator or most recent editor, are you sure you want to take this action on ${packageId}?`;
export const getNonOwnerDraftDeleteModalBody = (packageId: string) =>
`Since you are not the creator or most recent editor, are you sure you want to delete draft package ${packageId}? This action cannot be undone.`;
const DRAFT_CONTINUE_CONFIRMATION_STORAGE_KEY_PREFIX = "onemac:draft-continue-confirmed";
type DraftActorIdentity = {
email?: string | null;
name?: string | null;
};
type CurrentUserIdentity = {
email?: string | null;
fullName?: string | null;
name?: string | null;
given_name?: string | null;
family_name?: string | null;
};
const normalizeEmail = (email?: string | null) => email?.trim().toLowerCase() || "";
const normalizeName = (name?: string | null) => name?.trim().toLowerCase() || "";
const normalizePackageId = (packageId?: string | null) => packageId?.trim().toUpperCase() || "";
const getDraftContinueConfirmationKey = (packageId: string, email?: string | null) =>
`${DRAFT_CONTINUE_CONFIRMATION_STORAGE_KEY_PREFIX}:${normalizePackageId(packageId)}:${normalizeEmail(email)}`;
export const getDraftIdConflictFieldMessage = (event?: string | null) =>
(event && DRAFT_ID_CONFLICT_FIELD_MESSAGES[event]) ||
"According to our records, this ID already exists. Please check the ID and try entering it again.";
export const markDraftContinueConfirmed = (packageId: string, email?: string | null) => {
try {
sessionStorage.setItem(getDraftContinueConfirmationKey(packageId, email), "true");
} catch {
// Ignore storage failures; the save/submit prompt remains as a fallback.
}
};
export const consumeDraftContinueConfirmed = (packageId: string, email?: string | null) => {
try {
const key = getDraftContinueConfirmationKey(packageId, email);
const wasConfirmed = sessionStorage.getItem(key) === "true";
if (wasConfirmed) {
sessionStorage.removeItem(key);
}
return wasConfirmed;
} catch {
return false;
}
};
export const isCurrentUserDraftActor = (
currentUser: CurrentUserIdentity | null | undefined,
actors: DraftActorIdentity[],
) => {
const currentEmail = normalizeEmail(currentUser?.email);
const currentName = normalizeName(
currentUser?.fullName ??
currentUser?.name ??
[currentUser?.given_name, currentUser?.family_name].filter(Boolean).join(" "),
);
return actors.some((actor) => {
const actorEmail = normalizeEmail(actor.email);
if (currentEmail && actorEmail) {
return currentEmail === actorEmail;
}
// Legacy draft records may only have an owner name. Only fall back to name
// matching when the actor email is absent so explicit email ownership wins.
const actorName = normalizeName(actor.name);
return !actorEmail && currentName && actorName === currentName;
});
};
const EVENT_TO_DRAFT_PATH: Record<string, string> = {
"new-medicaid-submission": "/new-submission/spa/medicaid/create",
"new-chip-submission": "/new-submission/spa/chip/create",
"new-chip-details-submission": "/new-submission/spa/chip/create/chip-details",
"capitated-initial": "/new-submission/waiver/b/capitated/initial/create",
"capitated-renewal": "/new-submission/waiver/b/capitated/renewal/create",
"capitated-amendment": "/new-submission/waiver/b/capitated/amendment/create",
"contracting-initial": "/new-submission/waiver/b/b4/initial/create",
"contracting-renewal": "/new-submission/waiver/b/b4/renewal/create",
"contracting-amendment": "/new-submission/waiver/b/b4/amendment/create",
"temporary-extension": "/new-submission/waiver/temporary-extensions",
"app-k": "/new-submission/waiver/app-k",
};
export const getDraftEditLink = (record: opensearch.main.Document) => {
if (record.seatoolStatus !== SEATOOL_STATUS.DRAFT) return null;
if (!record.event || !(record.event in EVENT_TO_DRAFT_PATH)) return null;
const searchParams = new URLSearchParams({
draftId: record.id,
});
try {
const origin = getDashboardTabForAuthority(record.authority as Authority);
searchParams.set("origin", origin);
} catch {
// If authority is missing/invalid, omit origin and default back to dashboard.
}
return {
pathname: EVENT_TO_DRAFT_PATH[record.event],
search: searchParams.toString(),
};
};
export const getDraftDashboardLink = (record: opensearch.main.Document) => {
try {
const tab = getDashboardTabForAuthority(record.authority as Authority);
return `/dashboard?tab=${tab}`;
} catch {
return "/dashboard";
}
};
|