-
Notifications
You must be signed in to change notification settings - Fork 0
[fix] 메인 홈 스케줄표 수정 #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3fe219e
feat: 사장님 메인페이지 캘린더 교체 및 날짜별 근무자 모달 추가
limtjdghks 515517e
fix: 근무자 리스트 페이지 삭제
limtjdghks 2c7032b
fix: 근무자 수정/삭제 액션 메인 홈 모달로 이전
limtjdghks 0f2ef85
feat: 알바생 홈 캘린더 날짜별 근무 일정 모달 추가
limtjdghks 1157c83
fix: 삭제 에러 메시지 날짜 전환/모달 재오픈 후에도 잔류 버그 수정
limtjdghks c520c83
feat: 캘린더에 사용 할 날짜 관련 유틸 추가
limtjdghks 6537dc1
delete: 날짜 관련 유틸 features에서 삭제
limtjdghks 962504d
refactor: 날짜 관련 유틸 import 수정
limtjdghks 47dd917
fix: 날짜 출력시 기준을 UTC에서 로컬 타임을 기준으로 하도록 수정
limtjdghks 2b91d3c
feat: 스크롤 잠금 유틸 추가
limtjdghks 051423d
refactor: 모달 로직 useScrollLock을 사용하도록 수정
limtjdghks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()}원` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 0 additions & 95 deletions
95
src/features/manager/home/hooks/useMonthlySchedulesViewModel.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
src/features/manager/home/hooks/useWorkerScheduleCalendarViewModel.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| }, []) | ||
|
|
||
| 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, | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.