Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/role constansts로 빼기 #848 #852

Merged
merged 5 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/components/Layout/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { VscBug } from 'react-icons/vsc';
import { Role } from '@api/dto';
import CATEGORIES from '@constants/category';
import { KEEPER_COLOR, SIDEBAR_WIDTH } from '@constants/keeperTheme';
import { MEMBER_ROLE } from '@constants/member';
import useCheckAuth from '@hooks/useCheckAuth';
import CategoryNav from '@components/Navigation/CategoryNav';

Expand All @@ -13,7 +14,13 @@ interface SidebarProps {
}

const Sidebar = ({ mobileSidebarOpen, setMobileSidebarOpen }: SidebarProps) => {
const executiveRoles: Role[] = ['ROLE_회장', 'ROLE_부회장', 'ROLE_서기', 'ROLE_총무', 'ROLE_사서'];
const executiveRoles: Role[] = [
MEMBER_ROLE.회장,
MEMBER_ROLE.부회장,
MEMBER_ROLE.서기,
MEMBER_ROLE.총무,
MEMBER_ROLE.사서,
];
const { checkIncludeOneOfAuths } = useCheckAuth();

const theme = useTheme();
Expand Down
21 changes: 11 additions & 10 deletions src/constants/badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ import librarianBadge from '@assets/dutyManage/badge_8_librarian.gif';
import graduateBadge from '@assets/profileBadge/profile_badge_state_graduate.gif';
import regularBadge from '@assets/profileBadge/profile_badge_state_regular.gif';
import sleepBadge from '@assets/profileBadge/profile_badge_state_sleep.gif';
import { MEMBER_ROLE } from './member';

const roles = [
{ name: 'ROLE_회장', img: chairmanBadge },
{ name: 'ROLE_부회장', img: viceChairmanBadge },
{ name: 'ROLE_서기', img: clerkBadge },
{ name: 'ROLE_총무', img: administratorBadge },
{ name: 'ROLE_사서', img: librarianBadge },
{ name: 'ROLE_학술부장', img: studyManagerBadge },
{ name: 'ROLE_대외부장', img: externalManagerBadge },
{ name: 'ROLE_FRONT_전산관리자', img: ITManagerBadge },
{ name: 'ROLE_BACK_전산관리자', img: ITManagerBadge },
{ name: 'ROLE_INFRA_전산관리자', img: ITManagerBadge },
{ name: MEMBER_ROLE.회장, img: chairmanBadge },
{ name: MEMBER_ROLE.부회장, img: viceChairmanBadge },
{ name: MEMBER_ROLE.서기, img: clerkBadge },
{ name: MEMBER_ROLE.총무, img: administratorBadge },
{ name: MEMBER_ROLE.사서, img: librarianBadge },
{ name: MEMBER_ROLE.학술부장, img: studyManagerBadge },
{ name: MEMBER_ROLE.대외부장, img: externalManagerBadge },
{ name: MEMBER_ROLE.FRONT_전산관리자, img: ITManagerBadge },
{ name: MEMBER_ROLE.BACK_전산관리자, img: ITManagerBadge },
{ name: MEMBER_ROLE.INFRA_전산관리자, img: ITManagerBadge },
];

const types: { [key: string]: string } = { 정회원: regularBadge, 졸업: graduateBadge, 휴면회원: sleepBadge };
Expand Down
19 changes: 10 additions & 9 deletions src/constants/category.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Role } from '@api/dto';
import { MEMBER_ROLE } from '@constants/member';

export interface CategoryMenu {
id: number;
Expand Down Expand Up @@ -152,19 +153,19 @@ const CATEGORIES: Category[] = [
id: 605,
name: '문제관리',
path: 'admin/challengeManage',
roles: ['ROLE_회장', 'ROLE_출제자'],
roles: [MEMBER_ROLE.회장, MEMBER_ROLE.출제자],
},
{
id: 606,
name: '제출로그',
path: 'admin/submissions',
roles: ['ROLE_회장', 'ROLE_출제자'],
roles: [MEMBER_ROLE.회장, MEMBER_ROLE.출제자],
},
{
id: 607,
name: '대회운영',
path: 'admin/operation',
roles: ['ROLE_회장'],
roles: [MEMBER_ROLE.회장],
},
],
}, */
Expand All @@ -177,37 +178,37 @@ const CATEGORIES: Category[] = [
id: 701,
name: '직책관리',
path: 'dutyManage',
roles: ['ROLE_회장', 'ROLE_부회장'],
roles: [MEMBER_ROLE.회장, MEMBER_ROLE.부회장],
},
/* {
id: 702,
name: '선거관리',
path: 'electionManage',
roles: ['ROLE_회장'],
roles: [MEMBER_ROLE.회장],
}, */
{
id: 703,
name: '도서관리',
path: 'libraryManage',
roles: ['ROLE_회장', 'ROLE_부회장', 'ROLE_사서'],
roles: [MEMBER_ROLE.회장, MEMBER_ROLE.부회장, MEMBER_ROLE.사서],
},
{
id: 704,
name: '세미나관리',
path: 'seminarManage',
roles: ['ROLE_회장', 'ROLE_부회장', 'ROLE_서기'],
roles: [MEMBER_ROLE.회장, MEMBER_ROLE.부회장, MEMBER_ROLE.서기],
},
{
id: 705,
name: '활동인원관리',
path: 'activeMemberManage',
roles: ['ROLE_회장', 'ROLE_부회장', 'ROLE_서기'],
roles: [MEMBER_ROLE.회장, MEMBER_ROLE.부회장, MEMBER_ROLE.서기],
},
{
id: 706,
name: '상벌점관리',
path: 'meritManage',
roles: ['ROLE_회장', 'ROLE_부회장', 'ROLE_서기'],
roles: [MEMBER_ROLE.회장, MEMBER_ROLE.부회장, MEMBER_ROLE.서기],
},
],
},
Expand Down
32 changes: 32 additions & 0 deletions src/constants/member.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export const MEMBER_ROLE_PREFIX = 'ROLE_';

// 1.
export const MEMBER_ROLE = {
회장: 'ROLE_회장',
부회장: 'ROLE_부회장',
서기: 'ROLE_서기',
총무: 'ROLE_총무',
사서: 'ROLE_사서',
학술부장: 'ROLE_학술부장',
대외부장: 'ROLE_대외부장',
전산관리자: 'ROLE_전산관리자',
FRONT_전산관리자: 'ROLE_FRONT_전산관리자',
BACK_전산관리자: 'ROLE_BACK_전산관리자',
INFRA_전산관리자: 'ROLE_INFRA_전산관리자',
회원: 'ROLE_회원',
출제자: 'ROLE_출제자',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상수를 선언할 때, chairman 이 아닌 한글로 회장으로 선언해줬습니다! 영어로 하면 오히려 코드읽기가 어려울 것 같아서 입니다..! 그런데 한글의 경우, FRONT_전산관리자같은 경우 어떻게 선언해줘야할지(카멜케이스, _ 등등) 고민입니다..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한글 섞여있는 경우 _ 좋은 것 같아요!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 영어랑 한글이 섞여있다면 언더바로 구분하는게 좋은 것 같습니다~!!

} as const;

// 2.
export const MEMBER_ROLE2 = {
회장: `${MEMBER_ROLE_PREFIX}회장`,
부회장: `${MEMBER_ROLE_PREFIX}부회장`,
} as const;

// 3.
const prefix = (detail: string) => `${MEMBER_ROLE_PREFIX}${detail}`;

export const MEMBER_ROLE3 = {
회장: prefix('회장'),
부회장: prefix('부회장'),
} as const;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEMBER_ROLE 상수를 선언하는 방식이 3가지인데, 어느게 좋을지 고민이 됩니다..

  1. ROLE_회장과 같이 바로 텍스트로 넣어주기 -> 해당 방식이 간단하지만, ROLE_ 부분이 중복되는데 이걸 바로 박아버리기 애매했습니다.
  2. prefix 변수 백틱안에 같이 넣어주기
  3. prefix 함수 만들어서 사용하기

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2222

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

왜죠!!!!!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 1번도 괜찮을 것 같긴 합니다!

  • 이유
  1. 에러 메시지를 상수로 바꾸는 과정에서는 (중복되더라도) 그냥 텍스트로 사용합니다.
  2. prefix() 가 어떤 형태인지 알고 있다면 이해할 수 있겠지만, 모른다면 해당 함수를 타고 들어가서 확인을 해야할 것 같습니다

근데 공통되는걸 묶으려면 백틱을 사용하는게 조금 더 전달력이 좋을 것 같습니당

Copy link
Contributor

@publdaze publdaze Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

왜죠!!!!!

1. ROLE_이라는 prefix를 백엔드와 공통적으로 사용하고 있는데, 직책을 어떻게 표기할 지에 따라서 충분히 변경 가능한 부분으로 보입니다. 1번으로 가게되면 변경될 경우 수동으로 업데이트 해주어야 하는 게 번거로울 것 같아요!

3. 사실 이게 제일 깔끔해보이지는 한데, 단순한 텍스트에 함수 실행문이 들어가는 게 조금 과한 것 같다는 생각도 들더라구요!

그래서 최종적으로 prefix 변수를 사용하지만 템플릿 리터럴로 표현된 2번으로 선택하였습니다! 하지만 prefix로 사용되는 ROLE_이 크게 변동이 많을 것 같은 부분은 아니라서 1번도 괜찮을 것 같아요!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 2번이 좋아보입니다.
Prefix는 공통이라 추후에 바뀔때 처리도 쉬울듯 하고,
실제 사용하는 입장에서는 1번과 2번 모두 똑같이 보여서
코드쪽 처리가 쉬운 2번이 좋을거 같습니다.
밑에는 참고 이미지 입니다!

1번
스크린샷 2023-12-11 오후 7 40 07

2번
스크린샷 2023-12-11 오후 7 40 15

19 changes: 11 additions & 8 deletions src/mocks/DutyManageApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ITManagerBadge from '@assets/dutyManage/badge_5_it_manager.gif';
import clerkBadge from '@assets/dutyManage/badge_6_clerk.gif';
import administratorBadge from '@assets/dutyManage/badge_7_administrator.gif';
import librarianBadge from '@assets/dutyManage/badge_8_librarian.gif';
import { MEMBER_ROLE } from '@constants/member';

interface RoleDutyList {
jobName: string;
Expand Down Expand Up @@ -82,14 +83,16 @@ const roleDutyListInfo: RoleDutyList[] = [
];

const roles = [
{ name: 'ROLE_회장', img: chairmanBadge },
{ name: 'ROLE_부회장', img: viceChairmanBadge },
{ name: 'ROLE_대외부장', img: externalManagerBadge },
{ name: 'ROLE_학술부장', img: studyManagerBadge },
{ name: 'ROLE_전산관리자', img: ITManagerBadge },
{ name: 'ROLE_서기', img: clerkBadge },
{ name: 'ROLE_총무', img: administratorBadge },
{ name: 'ROLE_사서', img: librarianBadge },
{ name: MEMBER_ROLE.회장, img: chairmanBadge },
{ name: MEMBER_ROLE.부회장, img: viceChairmanBadge },
{ name: MEMBER_ROLE.대외부장, img: externalManagerBadge },
{ name: MEMBER_ROLE.학술부장, img: studyManagerBadge },
{ name: MEMBER_ROLE.FRONT_전산관리자, img: ITManagerBadge },
{ name: MEMBER_ROLE.BACK_전산관리자, img: ITManagerBadge },
{ name: MEMBER_ROLE.INFRA_전산관리자, img: ITManagerBadge },
{ name: MEMBER_ROLE.서기, img: clerkBadge },
{ name: MEMBER_ROLE.총무, img: administratorBadge },
{ name: MEMBER_ROLE.사서, img: librarianBadge },
];

export type JobInfoType = {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Library/Library.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Typography from '@mui/material/Typography';
import { BookListSearch } from '@api/dto';
import { useGetExecutiveInfoQuery } from '@api/dutyManageApi';
import { useGetBookListQuery, useRequestBorrowBookMutation, useGetBookBorrowsQuery } from '@api/libraryApi';
import { MEMBER_ROLE } from '@constants/member';
import usePagination from '@hooks/usePagination';
import StandardTablePagination from '@components/Pagination/StandardTablePagination';
import PageTitle from '@components/Typography/PageTitle';
Expand All @@ -28,7 +29,7 @@ const Library = () => {
const { data: executiveInfos } = useGetExecutiveInfoQuery();
const { mutate: RequestBorrowBook } = useRequestBorrowBookMutation();

const librarian = executiveInfos?.find((role) => role.jobName === 'ROLE_사서')?.realName || '';
const librarian = executiveInfos?.find((role) => role.jobName === MEMBER_ROLE.사서)?.realName || '';

const handleRequestBook = (bookId: number) => {
RequestBorrowBook(bookId, {
Expand Down
5 changes: 3 additions & 2 deletions src/pages/Profile/Section/BadgeSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';
import { Tooltip } from '@mui/material';
import { Role, RoleInfo } from '@api/dto';
import { roles, types } from '@constants/badge';
import { MEMBER_ROLE_PREFIX, MEMBER_ROLE } from '@constants/member';

interface FollowListProps {
memberType: string;
Expand All @@ -13,7 +14,7 @@ const BadgeSection = ({ memberType, memberJobs }: FollowListProps) => {

useEffect(() => {
const updatedMemberJobInfo = memberJobs
.filter((job) => job !== 'ROLE_회원' && job !== 'ROLE_출제자')
.filter((job) => job !== MEMBER_ROLE.회원 && job !== MEMBER_ROLE.출제자)
.map((job) => {
const filteredRole = roles.find((role) => role.name === job);
return {
Expand All @@ -27,7 +28,7 @@ const BadgeSection = ({ memberType, memberJobs }: FollowListProps) => {
return (
<div className="flex h-8 flex-wrap items-center space-x-2 overflow-y-auto md:h-10">
{MemberJobInfo.map((job: RoleInfo) => (
<Tooltip key={job.name} title={job.name.replace('ROLE_', '')} placement="top">
<Tooltip key={job.name} title={job.name.replace(MEMBER_ROLE_PREFIX, '')} placement="top">
<img src={job.img} alt="" className="h-8 w-8 md:h-10 md:w-10" />
</Tooltip>
))}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Profile/Tab/BookTab/BookTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useCancleReturnBookMutation,
useCancleBorrowBookMutation,
} from '@api/libraryApi';
import { MEMBER_ROLE } from '@constants/member';
import BookCard from './Card/BookCard';
import BookGuide from './Guide/BookGuide';

Expand All @@ -20,7 +21,7 @@ const BookTab = () => {
const { mutate: cancleReturnBookMutation } = useCancleReturnBookMutation();
const { mutate: cancleBorrowBookMutation } = useCancleBorrowBookMutation();

const librarian = executiveInfos?.find((role) => role.jobName === 'ROLE_사서')?.realName || '';
const librarian = executiveInfos?.find((role) => role.jobName === MEMBER_ROLE.사서)?.realName || '';

const borrowLength = borrowedBookListData?.content?.filter((bookInfo) => bookInfo.status === '대출대기').length;
const returnLength = borrowedBookListData?.content?.filter((bookInfo) => bookInfo.status === '반납대기').length;
Expand Down
3 changes: 2 additions & 1 deletion src/pages/admin/DutyManage/Button/DutyProfileButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Button, Typography } from '@mui/material';
import { useGetExecutiveInfoQuery } from '@api/dutyManageApi';
import { MEMBER_ROLE } from '@constants/member';
import muiTheme from '@constants/muiTheme';
import { convertJobName } from '@mocks/DutyManageApi';

Expand All @@ -21,7 +22,7 @@ const DutyProfileButton = ({ jobName, badgeImage, setTooltipOpen, toggleModalOpe
toggleModalOpen();
};

if (jobName === 'ROLE_전산관리자') {
if (jobName === MEMBER_ROLE.전산관리자) {
return (
<div className="flex w-[120px] flex-col items-center">
<Typography variant="h3" sx={{ fontWeight: 600, color: 'white' }}>
Expand Down
24 changes: 12 additions & 12 deletions src/pages/admin/DutyManage/DutyManage.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import React from 'react';
import { MEMBER_ROLE } from '@constants/member';
import PageTitle from '@components/Typography/PageTitle';

import DutyProfileTooltip from './Tooltip/DutyProfileTooltip';

const jobNameArray = [
{ key: 1, jobName: 'ROLE_학술부장' },
{ key: 2, jobName: 'ROLE_대외부장' },
{ key: 3, jobName: 'ROLE_전산관리자' },
{ key: 4, jobName: 'ROLE_서기' },
{ key: 5, jobName: 'ROLE_사서' },
{ key: 6, jobName: 'ROLE_총무' },
{ key: 1, jobName: MEMBER_ROLE.학술부장 },
{ key: 2, jobName: MEMBER_ROLE.대외부장 },
{ key: 3, jobName: MEMBER_ROLE.전산관리자 },
{ key: 4, jobName: MEMBER_ROLE.서기 },
{ key: 5, jobName: MEMBER_ROLE.사서 },
{ key: 6, jobName: MEMBER_ROLE.총무 },
];

const ITjobNameArray = [
{ key: 1, jobName: 'ROLE_FRONT_전산관리자' },
{ key: 2, jobName: 'ROLE_BACK_전산관리자' },
{ key: 3, jobName: 'ROLE_INFRA_전산관리자' },
{ key: 1, jobName: MEMBER_ROLE.FRONT_전산관리자 },
{ key: 2, jobName: MEMBER_ROLE.BACK_전산관리자 },
{ key: 3, jobName: MEMBER_ROLE.INFRA_전산관리자 },
];

const MiddleBar = () => {
Expand Down Expand Up @@ -66,7 +66,7 @@ const ViceChairman = () => {
</div>
</div>
<div className="absolute left-[40%] translate-y-2">
<DutyProfileTooltip jobName="ROLE_부회장" />
<DutyProfileTooltip jobName={MEMBER_ROLE.부회장} />
</div>
</div>
</div>
Expand All @@ -78,7 +78,7 @@ const DutyManage = () => {
<div>
<PageTitle>직책관리</PageTitle>
<div className="flex flex-col items-center">
<DutyProfileTooltip jobName="ROLE_회장" />
<DutyProfileTooltip jobName={MEMBER_ROLE.회장} />
<ViceChairman />

<MiddleBar />
Expand Down
14 changes: 5 additions & 9 deletions src/pages/admin/DutyManage/Tooltip/DutyProfileTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Typography } from '@mui/material';
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
import { VscSearch } from 'react-icons/vsc';
import { MEMBER_ROLE } from '@constants/member';
import muiTheme from '@constants/muiTheme';
import { roleDutyListInfo, roles } from '@mocks/DutyManageApi';

Expand Down Expand Up @@ -50,13 +51,8 @@ const DutyProfileTooltip = ({ jobName }: DutyProfileTooltipProps) => {
const [tooltipOpen, setTooltipOpen] = useState(false);
const [modalOpen, toggleModalOpen] = useReducer((prev) => !prev, false);

let badgeImage;
if (jobName.search('전산관리자') !== -1) {
badgeImage = roles.find((role) => role.name === 'ROLE_전산관리자')?.img;
} else {
badgeImage = roles.find((role) => role.name === jobName)?.img;
}

const badgeImage = roles.find((role) => role.name === jobName)?.img;
// NOTE jobName으로는 "ROLE_전산관리자" 내려오지만, roles에는 존재하지 않습니다! 세부적인 전산관리자(프론트, 백, 인프라)만 존재합니다
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오옹 이런 주석 좋은것같슴당

return (
<div className="relative z-10">
<DutyProfileButton
Expand All @@ -65,7 +61,7 @@ const DutyProfileTooltip = ({ jobName }: DutyProfileTooltipProps) => {
setTooltipOpen={setTooltipOpen}
toggleModalOpen={toggleModalOpen}
/>
{jobName !== 'ROLE_전산관리자' ? (
{jobName !== MEMBER_ROLE.전산관리자 && (
Comment on lines -68 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굿!!

<>
<DescriptionRoleDutyTooltip
title={tooltipContent(jobName)}
Expand All @@ -85,7 +81,7 @@ const DutyProfileTooltip = ({ jobName }: DutyProfileTooltipProps) => {
badgeImage={badgeImage}
/>
</>
) : null}
)}
</div>
);
};
Expand Down
3 changes: 2 additions & 1 deletion src/pages/senimarAttend/SenimarAttend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
useGetRecentlyDoneSeminarInfoQuery,
useGetRecentlyUpcomingSeminarInfoQuery,
} from '@api/seminarApi';
import { MEMBER_ROLE } from '@constants/member';
import useCheckAuth from '@hooks/useCheckAuth';
import memberState from '@recoil/member.recoil';
import starterState from '@recoil/seminarStarter.recoil';
Expand All @@ -30,7 +31,7 @@ const SeminarAttend = () => {
const { data: availableSeminarData } = useGetAvailableSeminarInfoQuery();

const { checkIncludeOneOfAuths } = useCheckAuth();
const authorizedMember = checkIncludeOneOfAuths(['ROLE_회장', 'ROLE_부회장', 'ROLE_서기']);
const authorizedMember = checkIncludeOneOfAuths([MEMBER_ROLE.회장, MEMBER_ROLE.부회장, MEMBER_ROLE.서기]);
const startMember: number | undefined = useRecoilValue(starterState);
const member: MemberInfo | null = useRecoilValue(memberState);

Expand Down
Loading