File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
09-17
import 'server-only';
import { cache } from 'react';
import type { SidebarMenu } from '@/lib/domain/sidebar-menu';
/**
* 사이드바 메뉴 Repository — 계정 권한에 맞는 메뉴 트리를 가져온다.
*
* **아직 백엔드 API가 없다.** 지금은 아래 mock을 돌려주지만, 호출부는 이미 "권한을 넘기면
* 트리가 온다"는 계약만 알고 있으므로 API가 생기면 이 파일의 함수 본문만 교체하면 된다
* (다른 Repository와 같은 자리·같은 모양이다).
*
* 권한을 인자로 받는 이유 — 메뉴는 계정마다 다르다. 인자로 두면 `cache()`가 권한별로 따로
* 기억해, 한 요청 안에서 여러 번 불러도 한 번만 조회하면서 다른 권한의 결과가 섞이지 않는다.
*
* 교체할 때는 다른 Repository처럼 `backendFetch` + `getSessionAccessToken`을 쓰고, 응답을
* `SidebarMenu`로 매핑하는 `toSidebarMenu`만 추가하면 된다.
*/
/**
* mock 메뉴 — 지금 실제로 존재하는 화면만 담는다. 갈 곳 없는 항목을 넣으면 눌러도 아무 일이
* 없어 고장으로 보이므로, 시안에 있는 통합플랫폼 메뉴(기관 관리·역할 관리 등)는 넣지 않았다.
*
* 라벨과 계층은 기획 시안의 화면경로를 그대로 따른다 — 「학생 회원/관리자 회원 < 회원관리」,
* 「금칙어관리/가맹점 관리 < 관리자관리」, 「아이템 관리 < 꾸미기아이템관리」,
* 「공지사항/1:1문의/FAQ < 게시판관리(고객센터)」.
*
* 각 화면의 breadcrumb이 이 경로를 그대로 되풀이하므로, 여기를 옮기면 그쪽도 같이 고친다.
*
* 아이콘은 시안 1depth가 쓰는 Phosphor 세트에서 골랐다.
*/
const MOCK_MENU: SidebarMenu = {
sections: [
{
id: 'operation',
label: '운영 관리',
items: [
{ id: 'home', label: '홈', icon: 'house', href: '/' },
{
id: 'members',
label: '회원관리',
icon: 'users-three',
children: [
{ id: 'students', label: '학생 회원', href: '/students' },
{ id: 'admin-members', label: '관리자 회원', href: '/admins' },
],
},
{
id: 'admins',
label: '관리자관리',
icon: 'user-square',
children: [
{ id: 'banned-words', label: '금칙어관리', href: '/system/banned-words' },
{ id: 'merchants', label: '가맹점 관리', href: '/system/merchants' },
{ id: 'merchant-details', label: '가맹몰 상세 관리', href: '/system/merchant-details' },
// TODO: 「메뉴관리」(/admins/menus)는 구현이 끝나면 다시 넣는다.
],
},
{
id: 'decoration',
label: '꾸미기아이템관리',
icon: 'potted-plant',
children: [
{ id: 'decoration-items', label: '아이템 관리', href: '/decoration-items' },
],
},
{
id: 'boards',
label: '게시판관리(고객센터)',
icon: 'pencil-simple',
children: [
{ id: 'notices', label: '공지사항', href: '/boards/notices' },
{ id: 'inquiries', label: '1:1문의', href: '/boards/inquiries' },
{ id: 'faqs', label: 'FAQ', href: '/boards/faqs' },
],
},
{
id: 'points',
label: '포인트관리',
icon: 'coins',
children: [
{ id: 'point-standards', label: '포인트 기준관리', href: '/points/standards' },
{ id: 'point-accounts', label: '누적포인트 관리', href: '/points/accumulated' },
],
},
{
id: 'contents',
label: '콘텐츠관리',
icon: 'image',
children: [
{ id: 'contents-shorts', label: '금융쇼츠', href: '/contents/shorts' },
{ id: 'contents-quizzes', label: '금융OX퀴즈', href: '/contents/quizzes' },
{ id: 'contents-comics', label: '4컷금융만화', href: '/contents/comics' },
],
},
{
id: 'system',
label: '시스템관리',
icon: 'wrench',
children: [
{ id: 'codes', label: '코드관리', href: '/system/codes' },
{ id: 'menus', label: '앱 메뉴관리', href: '/system/menus' },
],
},
],
},
],
};
/**
* 권한에 맞는 사이드바 메뉴를 가져온다.
*
* @param roleCode 세션의 `roleId`(예: `ROLE_SYSTEM`). 지금은 쓰이지 않지만 API가 붙으면
* 이 값으로 조회한다 — 인자를 미리 받아 두어야 호출부를 나중에 고치지 않는다.
*/
export const fetchSidebarMenu = cache(
async (roleCode: string): Promise<SidebarMenu> => {
// TODO(백엔드): 권한별 메뉴 API가 생기면 backendFetch 호출로 교체한다. roleCode를 그대로
// 넘기면 되고, 아래 mock 반환만 지우면 된다.
void roleCode;
return MOCK_MENU;
}
);