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;