diff --git a/src/utils/permitStatus.ts b/src/utils/permitStatus.ts new file mode 100644 index 0000000..4504009 --- /dev/null +++ b/src/utils/permitStatus.ts @@ -0,0 +1,68 @@ +//Code to infer Internal stage from Status + +const stagesMap = { + Submitted: ["Submitted", "New", "Plans Received"], + "In Review": [ + "In Process", + "In Progress", + "In Review", + "Plan Review In Process", + ], + "Awaiting Client Reply": [ + "Rejected", + "Revision", + "Revision Required", + "Revisions Required", + "Review Verification", + "Awaiting Revisions", + "Pending Client Input", + "Pending Additional Review", + "Awaiting Client Reply", + "Ready to Issue", + "Pending Permit Issuance", + "Approved with Conditions", + ], + Issued: ["Permit Issued", "Issued"], + Completed: [ + "Approved", + "Administrative Close", + "Closed", + "Closed - Supp-Rev Approved", + "Closed - Void", + "Closed - Finaled", + "Closed - COC Issued", + "Closed - Withdrawn", + "Closed - CO Issued", + "Complete", + "CO Approved", + ], + Expired: ["Expired"], + "Cancel/Void": ["Cancel", "Canceled", "Withdrawn"], +}; + +export async function getStage( + status: string, + internalStage: { pipeline: Array<{ name: string }>; currentStage: number } +) { + let newStage = ""; + for (let [stage, statuses] of Object.entries(stagesMap)) { + if (statuses.includes(status)) { + newStage = stage; + break; + } + } + const currentStageIndex = internalStage.currentStage; + const newStageIndex = internalStage.pipeline.findIndex( + (stage) => stage.name === newStage + ); + + if (newStageIndex !== -1 && newStageIndex !== currentStageIndex) { + if (currentStageIndex >= 11 && newStageIndex < currentStageIndex) { + console.log("No change"); + return internalStage.currentStage; + } else { + console.log("Current stage changed to:", newStageIndex, newStage); + return newStageIndex; + } + } +}