Skip to content

Commit

Permalink
Feat: #261 유저 전체 검색 mswHandler 추가 & 팀 생성 시 HEAD 권한 삭제 (#264)
Browse files Browse the repository at this point in the history
* Feat: #261 유저 전체 검색 mswHandler 추가 & 팀 생성 시 HEAD 권한 삭제

* Fix: #261 유저 전체검색 mswHandler 변경
  • Loading branch information
ice-bear98 authored Nov 10, 2024
1 parent aecc8cf commit 7447613
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/common/UserRoleSelectBox.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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';

type UserRoleSelectBoxProps<T extends RoleName> = {
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;
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/modal/team/ModalTeamForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions src/constants/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
23 changes: 22 additions & 1 deletion src/mocks/services/userServiceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

0 comments on commit 7447613

Please sign in to comment.