Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { SubstituteRequestPage } from '@/pages/user/substitute-request'
import { ManagerSubstituteRequestPage } from '@/pages/manager/substitute-request'
import { StoreRegisterPage } from '@/pages/manager/store-register'
import { ManagerWorkerInvitePage } from '@/pages/manager/worker-invite'
import { WorkerListPage } from '@/pages/manager/worker-list'
import { WorkspaceJoinPage } from '@/pages/user/workspace-join'
import { NotificationPage } from '@/pages/notification'
import { NotificationSettingsPage } from '@/pages/notification/settings'
Expand Down Expand Up @@ -147,10 +146,6 @@ export function App() {
path={ROUTES.MANAGER.WORKER_INVITE}
element={<ManagerWorkerInvitePage />}
/>
<Route
path={ROUTES.MANAGER.WORKER_LIST}
element={<WorkerListPage />}
/>
</Route>

<Route element={<MobileRouteLayoutWithDocbar />}>
Expand Down
47 changes: 0 additions & 47 deletions src/features/home/common/schedule/lib/date.ts

This file was deleted.

10 changes: 10 additions & 0 deletions src/features/home/common/schedule/lib/summaryFormat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function formatTotalWorkHoursText(totalWorkHours?: number): string {
return String(Math.round(totalWorkHours ?? 0)).padStart(2, '0')
}

export function formatEstimatedEarningsText(
estimatedLaborCost?: number
): string | undefined {
if (estimatedLaborCost == null) return undefined
return `약 ${estimatedLaborCost.toLocaleString()}원`
}
36 changes: 26 additions & 10 deletions src/features/manager/home/hooks/useManagerHomeViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useWorkspaceDetailQuery } from '@/features/manager/home/hooks/useWorksp
import { useWorkspaceWorkersViewModel } from '@/features/manager/home/hooks/useWorkspaceWorkersViewModel'
import { useManagedPostingsViewModel } from '@/features/manager/home/hooks/useManagedPostingsViewModel'
import { useSubstituteRequestsViewModel } from '@/features/manager/home/hooks/useSubstituteRequestsViewModel'
import { useMonthlySchedulesViewModel } from '@/features/manager/home/hooks/useMonthlySchedulesViewModel'
import { useWorkerScheduleCalendarViewModel } from '@/features/manager/home/hooks/useWorkerScheduleCalendarViewModel'
import { useTodaySchedulesViewModel } from '@/features/manager/home/hooks/useTodaySchedulesViewModel'

export function useManagerHomeViewModel() {
Expand Down Expand Up @@ -126,13 +126,21 @@ export function useManagerHomeViewModel() {

const {
baseDate: scheduleBaseDate,
calendarData,
scheduleData,
totalWorkHoursText,
estimatedEarningsText,
selectedDateKey,
isLoading: isScheduleLoading,
onDateChange: onScheduleDateChange,
goToPrevMonth,
goToNextMonth,
} = useMonthlySchedulesViewModel(activeWorkspaceId)
onMonthChange: onScheduleMonthChange,
isModalOpen: isScheduleModalOpen,
modalDateKey: scheduleModalDateKey,
visibleWorkers: scheduleVisibleWorkers,
deleteError: scheduleDeleteError,
handleDateClick: onScheduleDateClick,
closeModal: closeScheduleModal,
handleDeleteWorker: handleScheduleDeleteWorker,
handleEditWorker: handleScheduleEditWorker,
} = useWorkerScheduleCalendarViewModel(activeWorkspaceId)

const { todayWorkers } = useTodaySchedulesViewModel(activeWorkspaceId)

Expand Down Expand Up @@ -181,12 +189,20 @@ export function useManagerHomeViewModel() {
hasMoreSubstitutes,
schedule: {
baseDate: scheduleBaseDate,
scheduleData,
totalWorkHoursText,
estimatedEarningsText,
selectedDateKey,
data: calendarData,
isLoading: isScheduleLoading,
onDateChange: onScheduleDateChange,
goToPrevMonth,
goToNextMonth,
onMonthChange: onScheduleMonthChange,
isModalOpen: isScheduleModalOpen,
modalDateKey: scheduleModalDateKey,
visibleWorkers: scheduleVisibleWorkers,
deleteError: scheduleDeleteError,
handleDateClick: onScheduleDateClick,
closeModal: closeScheduleModal,
handleDeleteWorker: handleScheduleDeleteWorker,
handleEditWorker: handleScheduleEditWorker,
},
workspaceDetail,
workspaceChangeModal: {
Expand Down
95 changes: 0 additions & 95 deletions src/features/manager/home/hooks/useMonthlySchedulesViewModel.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMemo } from 'react'
import { useQuery } from '@tanstack/react-query'
import { fetchTodaySchedules } from '@/features/manager/api/schedule'
import { queryKeys } from '@/shared/lib/queryKeys'
import { formatIsoTimeRangeLabel } from '@/features/home/common/schedule/lib/date'
import { formatIsoTimeRangeLabel } from '@/shared/lib/calendarUtils'
import type { TodayWorkerItem } from '@/features/manager/home/ui/TodayWorkerList'

export function useTodaySchedulesViewModel(workspaceId: number | null) {
Expand Down
136 changes: 136 additions & 0 deletions src/features/manager/home/hooks/useWorkerScheduleCalendarViewModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { useCallback, useMemo, useState } from 'react'
import { format } from 'date-fns'
import axios from 'axios'
import { useNavigate } from 'react-router-dom'
import { useWorkerListSchedulesQuery } from '@/features/manager/worker-list/hooks/query/useWorkerListSchedulesQuery'
import {
buildWorkerScheduleData,
getVisibleWorkers,
} from '@/features/manager/worker-list/lib/workerSchedule'
import type { WorkerListEntry } from '@/features/manager/worker-list/lib/workerSchedule'
import {
formatEstimatedEarningsText,
formatTotalWorkHoursText,
} from '@/features/home/common/schedule/lib/summaryFormat'
import {
useDeleteScheduleWorker,
useDeleteSchedule,
} from '@/features/manager/schedule/hooks/mutation'
import { managerWorkerSchedulePath } from '@/shared/constants/routes'
import type { WorkerScheduleLocationState } from '@/features/manager'

const DATE_KEY_FORMAT = 'yyyy-MM-dd'

const DELETE_WORKER_ERROR_MESSAGES: Record<string, string> = {
B020: '요청한 리소스를 찾을 수 없습니다.',
A002: '관리중인 업장이 아닙니다.',
}

function getDeleteWorkerErrorMessage(error: unknown): string {
if (axios.isAxiosError(error)) {
const code = (error.response?.data as { code?: string } | undefined)?.code
if (code && DELETE_WORKER_ERROR_MESSAGES[code]) {
return DELETE_WORKER_ERROR_MESSAGES[code]
}
}
return '삭제 중 오류가 발생했습니다. 다시 시도해 주세요.'
}

export function useWorkerScheduleCalendarViewModel(workspaceId: number | null) {
const [baseDate, setBaseDate] = useState(() => new Date())
const [selectedDateKey, setSelectedDateKey] = useState(() =>
format(new Date(), DATE_KEY_FORMAT)
)
const [modalDateKey, setModalDateKey] = useState<string | null>(null)
const [deleteError, setDeleteError] = useState<string | null>(null)

const navigate = useNavigate()
const { mutateAsync: deleteWorker } = useDeleteScheduleWorker(
workspaceId ?? 0
)
const { mutateAsync: deleteShift } = useDeleteSchedule(workspaceId ?? 0)

const year = baseDate.getFullYear()
const month = baseDate.getMonth() + 1

const { data: rawData, isPending } = useWorkerListSchedulesQuery(
workspaceId,
year,
month
)

const scheduleData = useMemo(
() => buildWorkerScheduleData(rawData),
[rawData]
)

const totalWorkHoursText = useMemo(
() => formatTotalWorkHoursText(rawData?.data.totalWorkHours),
[rawData]
)

const estimatedEarningsText = useMemo(
() => formatEstimatedEarningsText(rawData?.data.estimatedLaborCost),
[rawData]
)

const visibleWorkers = useMemo(
() => (modalDateKey ? getVisibleWorkers(rawData, modalDateKey) : []),
[rawData, modalDateKey]
)

const onMonthChange = useCallback((date: Date) => setBaseDate(date), [])

const handleDateClick = useCallback((dateKey: string) => {
setDeleteError(null)
setSelectedDateKey(dateKey)
setModalDateKey(dateKey)
}, [])

const closeModal = useCallback(() => {
setDeleteError(null)
setModalDateKey(null)
}, [])

Comment thread
limtjdghks marked this conversation as resolved.
const handleDeleteWorker = useCallback(
async (shiftId: number) => {
try {
setDeleteError(null)
await deleteWorker(shiftId)
await deleteShift(shiftId)
} catch (error) {
setDeleteError(getDeleteWorkerErrorMessage(error))
}
},
[deleteWorker, deleteShift]
)

const handleEditWorker = useCallback(
(worker: WorkerListEntry) => {
navigate(managerWorkerSchedulePath(workspaceId ?? 0, worker.workerId), {
state: {
editDate: modalDateKey ?? selectedDateKey,
} satisfies WorkerScheduleLocationState,
})
},
[navigate, workspaceId, modalDateKey, selectedDateKey]
)

return {
baseDate,
scheduleData,
totalWorkHoursText,
estimatedEarningsText,
selectedDateKey,
isLoading: isPending && workspaceId !== null,
onMonthChange,
isModalOpen: modalDateKey !== null,
modalDateKey,
visibleWorkers,
deleteError,
handleDateClick,
closeModal,
handleDeleteWorker,
handleEditWorker,
}
}
Loading
Loading