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 b13a9f41..aff8bcd8 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..78bf11af 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,27 @@ 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 }); + + // 접두사(nickname)와 일치하는 유저 정보 최대 5명 추출 + const matchedSearchUsers = USER_DUMMY.filter((user) => user.nickname.startsWith(nickname)) + .slice(0, 5) + .map((user) => ({ userId: user.userId, nickname: user.nickname })); + + return HttpResponse.json(matchedSearchUsers); + }), ]; export default userServiceHandler;