From fba22cbfea057316e5a6d1b7d485698dba55850e Mon Sep 17 00:00:00 2001 From: Suk Woo Date: Mon, 9 Sep 2024 14:56:45 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20#117=20=EC=83=81=ED=83=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=ED=9B=84=20=EC=83=81=ED=83=9C=20=EC=88=9C=EC=84=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=EC=8B=9C=20=EB=B0=9C=EC=83=9D=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=97=90=EB=9F=AC=20=ED=95=B4=EA=B2=B0=20(#119)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: #117 초기 상태값 의존성 문제 해결 & sortOrder 번호 수정 * Fix: #117 MockHash 데이터 최신화를 위한 로직 변경 --- src/hooks/query/useStatusQuery.ts | 4 +-- src/mocks/mockHash.ts | 42 +++++++++++++++------- src/mocks/services/statusServiceHandler.ts | 5 +-- src/mocks/services/taskServiceHandler.ts | 8 +++-- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/hooks/query/useStatusQuery.ts b/src/hooks/query/useStatusQuery.ts index d4142aa4..25a65102 100644 --- a/src/hooks/query/useStatusQuery.ts +++ b/src/hooks/query/useStatusQuery.ts @@ -70,9 +70,9 @@ export function useReadStatuses(projectId: Project['projectId'], statusId?: Proj () => ({ statusName: status?.statusName || '', colorCode: status?.colorCode || '', - sortOrder: status?.sortOrder || statusList.length, + sortOrder: status?.sortOrder || statusList.length + 1, }), - [status], + [status, statusList], ); const nameList = useMemo(() => getStatusNameList(statusList, status?.statusName), [statusList, status?.statusName]); const colorList = useMemo(() => getStatusColorList(statusList, status?.colorCode), [statusList, status?.colorCode]); diff --git a/src/mocks/mockHash.ts b/src/mocks/mockHash.ts index 740828ca..57fe8d22 100644 --- a/src/mocks/mockHash.ts +++ b/src/mocks/mockHash.ts @@ -11,20 +11,38 @@ type Hash = { }; // ToDo: MSW 처리중 해쉬 테이블 처리를 사용하는 부분 대체해주기 -export const USERS_HASH: Hash = {}; -USER_DUMMY.forEach((user) => (USERS_HASH[user.userId] = user)); +export function getUserHash() { + const userHash: Hash = {}; + USER_DUMMY.forEach((user) => (userHash[user.userId] = user)); + return userHash; +} -export const ROLES_HASH: Hash = {}; -ROLE_DUMMY.forEach((role) => (ROLES_HASH[role.roleId] = role)); +export function getRoleHash() { + const roleHash: Hash = {}; + ROLE_DUMMY.forEach((role) => (roleHash[role.roleId] = role)); + return roleHash; +} -export const TEAMS_HASH: Hash = {}; -TEAM_DUMMY.forEach((team) => (TEAMS_HASH[team.teamId] = team)); +export function getTeamHash() { + const teamHash: Hash = {}; + TEAM_DUMMY.forEach((team) => (teamHash[team.teamId] = team)); + return teamHash; +} -export const PROJECTS_HASH: Hash = {}; -PROJECT_DUMMY.forEach((project) => (PROJECTS_HASH[project.projectId] = project)); +export function getProjectHash() { + const projectHash: Hash = {}; + PROJECT_DUMMY.forEach((project) => (projectHash[project.projectId] = project)); + return projectHash; +} -export const STATUSES_HASH: Hash = {}; -STATUS_DUMMY.forEach((status) => (STATUSES_HASH[status.statusId] = status)); +export function getStatusHash() { + const statusHash: Hash = {}; + STATUS_DUMMY.forEach((status) => (statusHash[status.statusId] = status)); + return statusHash; +} -export const TASK_HASH: Hash = {}; -TASK_DUMMY.forEach((task) => (TASK_HASH[task.taskId] = task)); +export function getTaskHash() { + const taskHash: Hash = {}; + TASK_DUMMY.forEach((task) => (taskHash[task.taskId] = task)); + return taskHash; +} diff --git a/src/mocks/services/statusServiceHandler.ts b/src/mocks/services/statusServiceHandler.ts index d772c623..4637ece9 100644 --- a/src/mocks/services/statusServiceHandler.ts +++ b/src/mocks/services/statusServiceHandler.ts @@ -1,6 +1,6 @@ import { http, HttpResponse } from 'msw'; import { STATUS_DUMMY } from '@mocks/mockData'; -import { STATUSES_HASH } from '@mocks/mockHash'; +import { getStatusHash } from '@mocks/mockHash'; import type { ProjectStatusForm, StatusOrderForm } from '@/types/ProjectStatusType'; @@ -43,7 +43,8 @@ const statusServiceHandler = [ for (let i = 0; i < statusOrders.length; i++) { const { statusId, sortOrder } = statusOrders[i]; - const target = STATUSES_HASH[statusId]; + const statusHash = getStatusHash(); + const target = statusHash[statusId]; if (!target) return new HttpResponse(null, { status: 404 }); if (target.projectId !== Number(projectId)) return new HttpResponse(null, { status: 400 }); diff --git a/src/mocks/services/taskServiceHandler.ts b/src/mocks/services/taskServiceHandler.ts index ae7f26d3..591eedcc 100644 --- a/src/mocks/services/taskServiceHandler.ts +++ b/src/mocks/services/taskServiceHandler.ts @@ -1,6 +1,6 @@ import { http, HttpResponse } from 'msw'; import { STATUS_DUMMY, TASK_DUMMY } from '@mocks/mockData'; -import { STATUSES_HASH, TASK_HASH } from '@mocks/mockHash'; +import { getStatusHash, getTaskHash } from '@mocks/mockHash'; import type { TaskOrderForm } from '@/types/TaskType'; const BASE_URL = import.meta.env.VITE_BASE_URL; @@ -34,10 +34,12 @@ const taskServiceHandler = [ for (let i = 0; i < taskOrders.length; i++) { const { taskId, statusId, sortOrder } = taskOrders[i]; - const target = TASK_HASH[taskId]; + const taskHash = getTaskHash(); + const target = taskHash[taskId]; if (!target) return new HttpResponse(null, { status: 404 }); - const status = STATUSES_HASH[statusId]; + const statusHash = getStatusHash(); + const status = statusHash[statusId]; if (status.projectId !== Number(projectId)) return new HttpResponse(null, { status: 400 }); target.statusId = statusId;