[st] - fix: 메뉴 권한체크 로직 수정
This commit is contained in:
@@ -6,7 +6,8 @@ export { useGlobalProgressStore } from "./use-global-progress-store";
|
||||
export { useMenuStore } from "./use-menu-store";
|
||||
export { useUserStore } from "./use-user-store";
|
||||
export {
|
||||
useStatisticsInputStatusConfirmGroupGate,
|
||||
isRegAuthorityAllowed,
|
||||
useActiveTabRegAuthorityAllowed,
|
||||
useStatisticsInputToolbarGroupGate,
|
||||
} from "./use-statistics-input-toolbar-group-gate";
|
||||
export { usePrompt } from "./use-prompt";
|
||||
|
||||
@@ -1,68 +1,28 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTabStore } from "@/store/tab-store";
|
||||
|
||||
import {
|
||||
checkStatisticsInputStatusConfirmGroupMembership,
|
||||
checkStatisticsInputToolbarGroupMembership,
|
||||
} from "@/entities/group-user/lib/check-statistics-input-toolbar-group-membership";
|
||||
export function isRegAuthorityAllowed(
|
||||
pageMenuAuthority: { regAuthrtYn: string } | null | undefined,
|
||||
): boolean {
|
||||
return pageMenuAuthority?.regAuthrtYn === "Y";
|
||||
}
|
||||
|
||||
import { useUserStore } from "./use-user-store";
|
||||
/**
|
||||
* 활성 탭의 `getPageMenuAuthority` 결과에서 `regAuthrtYn === "Y"`일 때만 true.
|
||||
* 권한은 탭 추가·활성화 시 tab-store에서 조회합니다.
|
||||
*/
|
||||
export function useActiveTabRegAuthorityAllowed(): boolean {
|
||||
const activeTabId = useTabStore((s) => s.activeTabId);
|
||||
const pageMenuAuthority = useTabStore((s) => {
|
||||
if (!activeTabId) return undefined;
|
||||
return s.tabs.find((tab) => tab.id === activeTabId)?.pageMenuAuthority;
|
||||
});
|
||||
|
||||
/** 통계 입력 상단 툴바(저장·제출·검증결과 등) — 그룹 멤버십 만족 시에만 true */
|
||||
return isRegAuthorityAllowed(pageMenuAuthority);
|
||||
}
|
||||
|
||||
/** 통계 입력 화면 상단 툴바용 — {@link useActiveTabRegAuthorityAllowed}와 동일 */
|
||||
export function useStatisticsInputToolbarGroupGate(): boolean {
|
||||
const userInfo = useUserStore((s) => s.userInfo);
|
||||
const [allowed, setAllowed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
const name = userInfo?.userName?.trim() ?? "";
|
||||
const uid = userInfo?.userUnqId?.trim() ?? "";
|
||||
if (!name || !uid) {
|
||||
setAllowed(false);
|
||||
return;
|
||||
}
|
||||
void (async () => {
|
||||
try {
|
||||
const ok = await checkStatisticsInputToolbarGroupMembership(name, uid);
|
||||
if (!cancelled) setAllowed(ok);
|
||||
} catch {
|
||||
if (!cancelled) setAllowed(false);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [userInfo?.userName, userInfo?.userUnqId]);
|
||||
|
||||
return allowed;
|
||||
}
|
||||
|
||||
/** 통계 입력 현황 — `GRP_ST_CONFIRM` / `GRP_ADMIN` 멤버일 때만 true */
|
||||
export function useStatisticsInputStatusConfirmGroupGate(): boolean {
|
||||
const userInfo = useUserStore((s) => s.userInfo);
|
||||
const [allowed, setAllowed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
const name = userInfo?.userName?.trim() ?? "";
|
||||
const uid = userInfo?.userUnqId?.trim() ?? "";
|
||||
if (!name || !uid) {
|
||||
setAllowed(false);
|
||||
return;
|
||||
}
|
||||
void (async () => {
|
||||
try {
|
||||
const ok = await checkStatisticsInputStatusConfirmGroupMembership(name, uid);
|
||||
if (!cancelled) setAllowed(ok);
|
||||
} catch {
|
||||
if (!cancelled) setAllowed(false);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [userInfo?.userName, userInfo?.userUnqId]);
|
||||
|
||||
return allowed;
|
||||
return useActiveTabRegAuthorityAllowed();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user