138 lines
3.9 KiB
TypeScript
138 lines
3.9 KiB
TypeScript
export const INSTL_SNCN_VIEW_BUTTON_ACTION = {
|
|
strg: "strg",
|
|
aply: "aply",
|
|
del: "del",
|
|
instlSncnAncmnt: "instlSncnAncmnt",
|
|
rjct: "rjct",
|
|
sncnAprv: "sncnAprv",
|
|
rvwRply: "rvwRply",
|
|
rqstTechRvw: "rqstTechRvw",
|
|
dsgntRvwr: "dsgntRvwr",
|
|
rvwStrg: "rvwStrg",
|
|
rvwCmptn: "rvwCmptn",
|
|
dmndSplmnt: "dmndSplmnt",
|
|
atrzAprv: "atrzAprv",
|
|
atrzRply: "atrzRply",
|
|
} as const;
|
|
|
|
export type InstlSncnViewButtonAction =
|
|
(typeof INSTL_SNCN_VIEW_BUTTON_ACTION)[keyof typeof INSTL_SNCN_VIEW_BUTTON_ACTION];
|
|
|
|
const ROLE_STATUS_BUTTON_ACTIONS: Record<string, Record<string, InstlSncnViewButtonAction[]>> = {
|
|
ROLE_USER05: {
|
|
"": [
|
|
INSTL_SNCN_VIEW_BUTTON_ACTION.strg,
|
|
INSTL_SNCN_VIEW_BUTTON_ACTION.aply,
|
|
INSTL_SNCN_VIEW_BUTTON_ACTION.del,
|
|
],
|
|
SV: [
|
|
INSTL_SNCN_VIEW_BUTTON_ACTION.strg,
|
|
INSTL_SNCN_VIEW_BUTTON_ACTION.aply,
|
|
INSTL_SNCN_VIEW_BUTTON_ACTION.del,
|
|
],
|
|
TA: [INSTL_SNCN_VIEW_BUTTON_ACTION.instlSncnAncmnt],
|
|
},
|
|
// 환경청 단계 제거: 기존 환경청(LE·TP) 기능을 광역자치단체가 수행
|
|
ROLE_USER04: {
|
|
ST: [
|
|
INSTL_SNCN_VIEW_BUTTON_ACTION.rvwRply,
|
|
INSTL_SNCN_VIEW_BUTTON_ACTION.rqstTechRvw,
|
|
INSTL_SNCN_VIEW_BUTTON_ACTION.rjct,
|
|
],
|
|
TP: [INSTL_SNCN_VIEW_BUTTON_ACTION.rvwRply],
|
|
EP: [INSTL_SNCN_VIEW_BUTTON_ACTION.sncnAprv],
|
|
},
|
|
};
|
|
|
|
const ROLE_USER01_ATRZ_STATUS_CODES = ["ER", "TE"] as const;
|
|
|
|
const ROLE_USER01_ATRZ_STATUS_ACTIONS: Record<
|
|
string,
|
|
Record<string, InstlSncnViewButtonAction[]>
|
|
> = {
|
|
ER: {
|
|
ATRZ01: [INSTL_SNCN_VIEW_BUTTON_ACTION.dsgntRvwr],
|
|
},
|
|
TE: {
|
|
ATRZ02: [
|
|
INSTL_SNCN_VIEW_BUTTON_ACTION.rvwStrg,
|
|
INSTL_SNCN_VIEW_BUTTON_ACTION.rvwCmptn,
|
|
INSTL_SNCN_VIEW_BUTTON_ACTION.dmndSplmnt,
|
|
],
|
|
ATRZ03: [INSTL_SNCN_VIEW_BUTTON_ACTION.atrzAprv],
|
|
ATRZ99: [INSTL_SNCN_VIEW_BUTTON_ACTION.atrzRply],
|
|
},
|
|
};
|
|
|
|
function resolveButtonConfigs(actions: InstlSncnViewButtonAction[]): InstlSncnViewButtonAction[] {
|
|
return actions.map((action) => INSTL_SNCN_VIEW_BUTTON_ACTION[action]);
|
|
}
|
|
|
|
interface GetButtonConfigsOptions {
|
|
hasPendingApprovalRequest?: boolean;
|
|
}
|
|
|
|
function resolveRoleUser01AtrzButtonActions(
|
|
prgrsSttsComCd: string,
|
|
atrzSeComCdList: string[],
|
|
options?: GetButtonConfigsOptions,
|
|
): InstlSncnViewButtonAction[] {
|
|
if (prgrsSttsComCd === "TE" && options?.hasPendingApprovalRequest === false) {
|
|
return [];
|
|
}
|
|
|
|
const atrzStatusMap = ROLE_USER01_ATRZ_STATUS_ACTIONS[prgrsSttsComCd];
|
|
if (!atrzStatusMap || atrzSeComCdList.length === 0) return [];
|
|
|
|
const seen = new Set<InstlSncnViewButtonAction>();
|
|
const actions: InstlSncnViewButtonAction[] = [];
|
|
|
|
for (const atrzSeComCd of atrzSeComCdList) {
|
|
const mappedActions = atrzStatusMap[atrzSeComCd];
|
|
if (!mappedActions) continue;
|
|
|
|
for (const action of mappedActions) {
|
|
if (seen.has(action)) continue;
|
|
seen.add(action);
|
|
actions.push(action);
|
|
}
|
|
}
|
|
|
|
return actions;
|
|
}
|
|
|
|
export function needsRoleUser01AtrzResolve(
|
|
dtlInstCd: string | undefined,
|
|
prgrsSttsComCd: string,
|
|
): boolean {
|
|
return (
|
|
dtlInstCd === "ROLE_USER01" &&
|
|
ROLE_USER01_ATRZ_STATUS_CODES.includes(
|
|
prgrsSttsComCd as (typeof ROLE_USER01_ATRZ_STATUS_CODES)[number],
|
|
)
|
|
);
|
|
}
|
|
|
|
export function getButtonConfigs(
|
|
dtlInstCd: string | undefined,
|
|
prgrsSttsComCd: string,
|
|
atrzSeComCdList?: string[],
|
|
options?: GetButtonConfigsOptions,
|
|
): InstlSncnViewButtonAction[] {
|
|
if (!dtlInstCd) return [];
|
|
|
|
if (needsRoleUser01AtrzResolve(dtlInstCd, prgrsSttsComCd)) {
|
|
return resolveButtonConfigs(
|
|
resolveRoleUser01AtrzButtonActions(prgrsSttsComCd, atrzSeComCdList ?? [], options),
|
|
);
|
|
}
|
|
|
|
const statusMap = ROLE_STATUS_BUTTON_ACTIONS[dtlInstCd];
|
|
if (!statusMap) return [];
|
|
|
|
const actions = statusMap[prgrsSttsComCd];
|
|
if (!actions) return [];
|
|
|
|
return resolveButtonConfigs(actions);
|
|
}
|