diff --git a/src/components/Calendar/Calendar-header.jsx b/src/components/Calendar/Calendar-header.jsx index f207918..c55fd95 100644 --- a/src/components/Calendar/Calendar-header.jsx +++ b/src/components/Calendar/Calendar-header.jsx @@ -1,8 +1,9 @@ -import useCalendar from '@hooks/useCalendar' +// import useCalendar from '@hooks/useCalendar' import styled from 'styled-components' +import { WEEKDAY } from '@constants/calendar' function CalendarHeader() { - const { calendarHeader } = useCalendar() + const calendarHeader = WEEKDAY return ( <> diff --git a/src/constants/calendar.js b/src/constants/calendar.js index 20625fc..dd8bd69 100644 --- a/src/constants/calendar.js +++ b/src/constants/calendar.js @@ -2,6 +2,8 @@ export const WEEKDAY = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'] export const MONTHS = Array.from({ length: 12 }, (_, i) => i + 1) +export const FIRSTDAY = (year, month) => new Date(year, month, 1).getDay() + export const HOLIDAYS = [ { date: '2024-01-01', name: '신정' }, { date: '2024-02-09', name: '설날 연휴' }, diff --git a/src/firebase/dataInserting.js b/src/firebase/dataInserting.js deleted file mode 100644 index b3451e6..0000000 --- a/src/firebase/dataInserting.js +++ /dev/null @@ -1,78 +0,0 @@ -import { db } from './firebaseConfig.js' -import { doc, setDoc } from 'firebase/firestore' - -// 특정 날짜와 시간으로 타임스탬프를 생성하는 함수 -function getTimestampFromDate(year, month, day, hour, minute = 0) { - const date = new Date(year, month - 1, day, hour, minute) - return date.getTime() // 밀리초 단위의 타임스탬프 반환 -} - -// 예시 데이터 -const month = { - workTimeTable: [ - // 8월 1일 - { - workIn: getTimestampFromDate(2024, 8, 1, 9, 0), - workOut: getTimestampFromDate(2024, 8, 1, 18, 0), - Objection: ['이의있음'], - }, - // 8월 2일 - { - workIn: getTimestampFromDate(2024, 8, 2, 9, 0), - workOut: getTimestampFromDate(2024, 8, 2, 19, 0), - Objection: ['이의있음'], - }, - // 8월 3일 (토요일) - { workIn: null, workOut: null, Objection: [] }, - // 8월 4일 (일요일) - { workIn: null, workOut: null, Objection: [] }, - // 8월 5일 - { - workIn: getTimestampFromDate(2024, 8, 5, 9, 0), - workOut: getTimestampFromDate(2024, 8, 5, 18, 30), - Objection: ['이의있음'], - }, - // 8월 6일 - { - workIn: getTimestampFromDate(2024, 8, 6, 9, 0), - workOut: getTimestampFromDate(2024, 8, 6, 20, 0), - Objection: ['이의있음'], - }, - // 8월 7일 - { - workIn: getTimestampFromDate(2024, 8, 7, 9, 0), - workOut: getTimestampFromDate(2024, 8, 7, 18, 0), - Objection: ['이의있음'], - }, - // 8월 8일 - { - workIn: getTimestampFromDate(2024, 8, 8, 9, 0), - workOut: getTimestampFromDate(2024, 8, 8, 19, 0), - Objection: ['이의있음'], - }, - ], -} - -/*예시 데이터 출력 -data.workTimeTable.forEach((entry) => { - console.log("출근 시간:", new Date(entry.workIn).toLocaleString()); - console.log("퇴근 시간:", new Date(entry.workOut).toLocaleString()); - console.log("이의 사항:", entry.Objection.join(", ")); -})*/ - -// Firestore에 데이터 추가 함수 -async function uploadAttendanceData() { - const empId = 'Zrghj2Jf3CVwQ7jSOmjCXYBBlek1' // 사원번호 - const monthDocId = '8' // 문서 ID - - try { - // Firestore에 데이터 삽입 - const docRef = doc(db, 'EMPLOYEES', empId, 'ATTENDENCE', monthDocId) - await setDoc(docRef, month, { merge: true }) - console.log('데이터가 성공적으로 삽입되었습니다.') - } catch (error) { - console.error('데이터 삽입 중 오류 발생:', error) - } -} - -uploadAttendanceData() diff --git a/src/hooks/useCalendar.jsx b/src/hooks/useCalendar.jsx index fc3ebd2..0d5abc2 100644 --- a/src/hooks/useCalendar.jsx +++ b/src/hooks/useCalendar.jsx @@ -1,15 +1,12 @@ -import { WEEKDAY } from '@constants/calendar' import { useState, useEffect } from 'react' +import { FIRSTDAY } from '@constants/calendar' const useCalendar = (year, month) => { - const calendarHeader = WEEKDAY - const [calendarDays, setCalendarDays] = useState([]) - const firstDayIndex = new Date(year, month, 1).getDay() + const firstDayIndex = FIRSTDAY(year, month) useEffect(() => { - // 이번달의 1일이 일요일이 아닌 경우에 지난달 마지막 주 추가 let previousMonthDays = [] if (firstDayIndex !== 0) { previousMonthDays = getLastWeekOfPreviousMonth(year, month) @@ -20,13 +17,13 @@ const useCalendar = (year, month) => { setCalendarDays([...previousMonthDays, ...currentMonthDays]) }, [year, month, firstDayIndex]) - return { calendarHeader, calendarDays, firstDayIndex } + return { calendarDays } } //helper const getLastWeekOfPreviousMonth = (year, month) => { - const lastDayOfPreviousMonth = new Date(year, month, 0) // 전달의 마지막 날 - const lastDayOfWeek = lastDayOfPreviousMonth.getDay() // 전달의 마지막 날의 요일 + const lastDayOfPreviousMonth = new Date(year, month, 0) + const lastDayOfWeek = lastDayOfPreviousMonth.getDay() return Array.from( { length: lastDayOfWeek + 1 }, diff --git a/src/pages/salary-management/ScheduleList.jsx b/src/pages/salary-management/ScheduleList.jsx index fd9a787..cac0c09 100644 --- a/src/pages/salary-management/ScheduleList.jsx +++ b/src/pages/salary-management/ScheduleList.jsx @@ -1,15 +1,15 @@ import { CalendarContext } from '@components/Container/calendar-context' import useAttendance from '@hooks/useAttandance' -import useCalendar from '@hooks/useCalendar' import { colors } from '@styles/Colors' import { format } from 'date-fns/format' import { useContext } from 'react' import styled from 'styled-components' +import { FIRSTDAY } from '@constants/calendar' function ScheduleList({ idx }) { const { month, year } = useContext(CalendarContext) const { data } = useAttendance({ month }) - const { firstDayIndex } = useCalendar(year, month) + const firstDayIndex = FIRSTDAY(year, month) const hasAttendance = !!data && Object.keys(data).length !== 0 if (!hasAttendance) return diff --git a/src/pages/task-management/TaskList.jsx b/src/pages/task-management/TaskList.jsx index 57cab6b..10850e9 100644 --- a/src/pages/task-management/TaskList.jsx +++ b/src/pages/task-management/TaskList.jsx @@ -1,20 +1,19 @@ import { CalendarContext } from '@components/Container/calendar-context' import { DIVISION_COLORS } from '@constants/Task' import useAuthState from '@hooks/useAuthState' -import useCalendar from '@hooks/useCalendar' import { fetchTasks } from '@reducers/taskSlice' import { colors } from '@styles/Colors' import { useContext, useEffect } from 'react' import { useDispatch, useSelector } from 'react-redux' import styled from 'styled-components' +import { FIRSTDAY } from '@constants/calendar' const TaskList = ({ idx }) => { const { month, year } = useContext(CalendarContext) - const { firstDayIndex } = useCalendar(year, month) + const firstDayIndex = FIRSTDAY(year, month) const dispatch = useDispatch() const { data: tasks, error } = useSelector(({ tasks }) => tasks) - // console.log('task', tasks) const { user } = useAuthState() useEffect(() => { diff --git a/src/reducers/userListSlice.js b/src/reducers/userListSlice.js index 650c1de..368d9bc 100644 --- a/src/reducers/userListSlice.js +++ b/src/reducers/userListSlice.js @@ -32,7 +32,6 @@ export const fetchEmployeeList = createAsyncThunk('user/fetchEmployee', async () const employeesList = docSnap.docs.map((doc) => ({ ...doc.data(), })) - // console.log('list', employeesList) return employeesList })