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

마스터 계정의 자주 묻는 질문 플랫폼 선택 권한 변경 #294

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
36 changes: 19 additions & 17 deletions src/pages/FaqPage/FaqPage.page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useMemo, useState } from 'react';
import { useRecoilValue } from 'recoil';
import { OutputData } from '@editorjs/editorjs';
import { Editor, EditorAside } from '@/components';
import * as Styled from './FaqPage.styled';
import { $teams, $profile } from '@/store';
import { $teams, $profile, $isMaster } from '@/store';
import { SelectSize } from '@/components/common/Select/Select.component';
import {
decodeHTMLEntities,
Expand All @@ -28,22 +28,26 @@ const FaqPage = () => {

const { handleAddToast } = useToast();
const teams = useRecoilValue($teams);
const teamOptions = teams.map(({ teamId, name }) => ({
value: teamId.toString(),
label: name,
}));
const teamOptions = useMemo(() => {
return teams.map(({ name }) => ({
value: name.toLowerCase(),
label: name,
}));
}, [teams]);

const myTeamName = useRecoilValue($profile)[0];
const isMaster = useRecoilValue($isMaster);
const isStaffUser = myTeamName === Team.mashUp || myTeamName === Team.branding;

const getTeamSelectOptions = () => {
const teamSelectOptions = useMemo(() => {
if (isMaster) {
return [commonSelectOption, ...teamOptions];
}
const myTeamOptionObject = teamOptions.find(
({ label }) => label.toUpperCase() === myTeamName.toUpperCase(),
);
return [myTeamOptionObject ?? commonSelectOption];
};

const teamSelectOptions = getTeamSelectOptions();
}, [teamOptions, myTeamName, isMaster]);

const handleUpdateButtonClick = async () => {
const originalOutputData = getLocalStorageData(EDITOR_ID);
Expand Down Expand Up @@ -84,13 +88,8 @@ const FaqPage = () => {
};

useEffect(() => {
const myTeamSelectOptions = teamSelectOptions[0] ?? commonSelectOption;

if (myTeamSelectOptions.value === commonSelectOption.value) {
setSelectedPlatform(commonSelectOption.value);
} else {
setSelectedPlatform(myTeamSelectOptions.label.toLowerCase());
}
const myTeamSelectOption = teamSelectOptions[0] ?? commonSelectOption;
setSelectedPlatform(myTeamSelectOption.value);
}, [teamSelectOptions]);

useEffect(() => {
Expand Down Expand Up @@ -126,6 +125,9 @@ const FaqPage = () => {
defaultValue={teamSelectOptions[0]}
size={SelectSize.sm}
options={teamSelectOptions}
onChangeOption={(option) => {
setSelectedPlatform(option.value);
}}
/>
}
rightActionButton={{
Expand Down
10 changes: 7 additions & 3 deletions src/store/login.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { atom } from 'recoil';
import { LoginResponse, MemberPositionType } from '@/types/dto';
import { LoginResponse, MemberPosition, MemberPositionType } from '@/types/dto';
import { TeamType, RoleType } from '@/components/common/UserProfile/UserProfile.component';
import { selectorWithRefresher } from './recoil';
import { ScoreType } from '@/components/ActivityScore';

export const $me = atom<LoginResponse>({
key: 'me',
Expand Down Expand Up @@ -38,7 +37,12 @@ export const $profile = selectorWithRefresher<[string, string, MemberPositionTyp
},
});

const MASTER_SCORE_TYPES = [ScoreType.MASHUP_LEADER, ScoreType.MASHUP_SUBLEADER] as string[];
const MASTER_SCORE_TYPES = [
MemberPosition.mashupLeader,
MemberPosition.mashupSubLeader,
MemberPosition.brandingLeader,
MemberPosition.brandingSubLeader,
] as string[];

export const $isMaster = selectorWithRefresher<boolean>({
key: 'isMaster',
Expand Down
3 changes: 2 additions & 1 deletion src/types/dto/adminMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export const MemberPosition = {
mashupSubLeader: 'MASHUP_SUBLEADER',
brandingLeader: 'BRANDING_LEADER',
brandingSubLeader: 'BRANDING_SUBLEADER',
brandingMember: 'BRANDING_MEMBER',
brandingHelper: 'BRANDING_HELPER',
brandingMember: 'BRANDING_MEMBER', // deprecated
springLeader: 'SPRING_LEADER',
springSubLeader: 'SPRING_SUBLEADER',
springHelper: 'SPRING_HELPER',
Expand Down
Loading