From 4bc203907c080909f6055cbb4d986ebd60999618 Mon Sep 17 00:00:00 2001 From: seungchanwoo Date: Wed, 6 Nov 2024 23:58:31 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20#261=20=EC=9C=A0=EC=A0=80=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EA=B2=80=EC=83=89=20mswHandler=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20&=20=ED=8C=80=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=20HE?= =?UTF-8?q?AD=20=EA=B6=8C=ED=95=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/UserRoleSelectBox.tsx | 4 +-- src/components/modal/team/ModalTeamForm.tsx | 4 +-- src/constants/role.ts | 1 + src/mocks/services/userServiceHandler.ts | 31 ++++++++++++++++++++- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/components/common/UserRoleSelectBox.tsx b/src/components/common/UserRoleSelectBox.tsx index 7dc86d8a..85e98ea8 100644 --- a/src/components/common/UserRoleSelectBox.tsx +++ b/src/components/common/UserRoleSelectBox.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { IoMdCloseCircle } from 'react-icons/io'; -import { PROJECT_ROLES, TEAM_ROLES } from '@constants/role'; +import { PROJECT_ROLES, TEAM_CREATE_ROLES, TEAM_ROLES } from '@constants/role'; import type { User } from '@/types/UserType'; import type { RoleName } from '@/types/RoleType'; @@ -8,7 +8,7 @@ type UserRoleSelectBoxProps = { userId: User['userId']; nickname: User['nickname']; defaultValue: RoleName; - roles: typeof TEAM_ROLES | typeof PROJECT_ROLES; + roles: typeof TEAM_CREATE_ROLES | typeof TEAM_ROLES | typeof PROJECT_ROLES; onRoleChange: (userId: number, roleName: T) => void; onRemoveUser: (userId: number) => void; }; diff --git a/src/components/modal/team/ModalTeamForm.tsx b/src/components/modal/team/ModalTeamForm.tsx index faa61ca1..84168f75 100644 --- a/src/components/modal/team/ModalTeamForm.tsx +++ b/src/components/modal/team/ModalTeamForm.tsx @@ -3,7 +3,7 @@ import { FormProvider, useForm } from 'react-hook-form'; import useAxios from '@hooks/useAxios'; import useToast from '@hooks/useToast'; import { useReadTeams } from '@hooks/query/useTeamQuery'; -import { TEAM_DEFAULT_ROLE, TEAM_ROLE_INFO, TEAM_ROLES } from '@constants/role'; +import { TEAM_CREATE_ROLES, TEAM_DEFAULT_ROLE, TEAM_ROLE_INFO } from '@constants/role'; import { TEAM_VALIDATION_RULES } from '@constants/formValidationRules'; import { findUser } from '@services/userService'; import Spinner from '@components/common/Spinner'; @@ -150,7 +150,7 @@ export default function ModalTeamForm({ formId, onSubmit }: ModalTeamFormProps) key={userId} userId={userId} nickname={nickname} - roles={TEAM_ROLES} + roles={TEAM_CREATE_ROLES} defaultValue={TEAM_DEFAULT_ROLE} onRoleChange={handleRoleChange} onRemoveUser={handleRemoveUser} diff --git a/src/constants/role.ts b/src/constants/role.ts index ed241b68..946ff680 100644 --- a/src/constants/role.ts +++ b/src/constants/role.ts @@ -2,6 +2,7 @@ import { deepFreeze } from '@utils/deepFreeze'; import type { RoleInfo } from '@/types/RoleType'; export const TEAM_ROLES = deepFreeze(['HEAD', 'LEADER', 'MATE'] as const); +export const TEAM_CREATE_ROLES = deepFreeze(['LEADER', 'MATE'] as const); export const PROJECT_ROLES = deepFreeze(['ADMIN', 'LEADER', 'ASSIGNEE'] as const); export const PROJECT_DEFAULT_ROLE = 'ASSIGNEE'; diff --git a/src/mocks/services/userServiceHandler.ts b/src/mocks/services/userServiceHandler.ts index 36719709..8ab93473 100644 --- a/src/mocks/services/userServiceHandler.ts +++ b/src/mocks/services/userServiceHandler.ts @@ -5,7 +5,7 @@ import { convertTokenToUserId } from '@utils/converter'; import { fileNameParser } from '@utils/fileNameParser'; import type { Team } from '@/types/TeamType'; import type { Role } from '@/types/RoleType'; -import type { EditUserInfoForm, EditUserLinksForm, User } from '@/types/UserType'; +import type { EditUserInfoForm, EditUserLinksForm, SearchUser, User } from '@/types/UserType'; const BASE_URL = import.meta.env.VITE_BASE_URL; @@ -186,6 +186,35 @@ const userServiceHandler = [ return HttpResponse.json(teamJoinStatusList); }), + // 전체 유저 검색 + http.get(`${BASE_URL}/user/search`, ({ request }) => { + const url = new URL(request.url); + const nickname = url.searchParams.get('nickname') || ''; + const accessToken = request.headers.get('Authorization'); + + // 유저 인증 확인 + if (!accessToken) return new HttpResponse(null, { status: 401 }); + + // 유저 ID 정보 취득 + const userId = convertTokenToUserId(accessToken); + if (!userId) return new HttpResponse(null, { status: 401 }); + + // 전체 유저 목록 조회 (USER_DUMMY 사용) + const allUsers = USER_DUMMY; + + // 유저 정보 취득 + const searchUsers: SearchUser[] = []; + for (let i = 0; i < allUsers.length; i++) { + const user = allUsers[i]; + if (!user) return new HttpResponse(null, { status: 404 }); + searchUsers.push({ userId: user.userId, nickname: user.nickname }); + } + + // 접두사(nickname)와 일치하는 유저 정보 최대 5명 추출 + const matchedSearchUsers = searchUsers.filter((user) => user.nickname.startsWith(nickname)).slice(0, 5); + + return HttpResponse.json(matchedSearchUsers); + }), ]; export default userServiceHandler;