Skip to content

Commit

Permalink
feat: 커리큘럼 시작일 DTO 추가, 그에 따른 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hamo-o committed Sep 4, 2024
1 parent 95aa278 commit 5b535a5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const AssignmentList = async ({ studyId }: { studyId: string }) => {
const assignmentList = await studyApi.getAssignmentList(
parseInt(studyId, 10)
);
const study = await studyApi.getStudyBasicInfo(+studyId);
const studyStartDate = study?.period?.startDate;

return (
<section aria-label="assignment-list">
Expand All @@ -19,7 +17,6 @@ const AssignmentList = async ({ studyId }: { studyId: string }) => {
<AssignmentListItem
assignment={assignment}
key={`studyDetailId-${index}`}
studyStartDate={studyStartDate}
/>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import AssignmentButtons from "./AssignmentButtons";

const AssignmentListItem = ({
assignment,
studyStartDate,
}: {
assignment: AssignmentApiResponseDto;
studyStartDate?: string;
}) => {
const { studyDetailId, title, deadline, week, assignmentStatus } = assignment;
const {
studyDetailId,
title,
deadline,
week,
assignmentStatus,
studyDetailStartDate,
} = assignment;

const formatDateToEndString = (date: string | null) => {
if (!date) return "-";
Expand All @@ -23,8 +28,7 @@ const AssignmentListItem = ({
return `종료 : ${year}${month}${day}${padWithZero(hours)}:${padWithZero(minutes)}`;
};

const thisWeekAssignment =
studyStartDate && getIsCurrentWeek(studyStartDate, week);
const thisWeekAssignment = getIsCurrentWeek(studyDetailStartDate);
const studyDeadline = formatDateToEndString(deadline);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const CurriculumListItem = ({
const { month: endMonth, day: endDay } = parseISODate(endDate);

const curriculumTimeLine = `${padWithZero(startMonth)}.${padWithZero(startDay)} - ${padWithZero(endMonth)}.${padWithZero(endDay)}`;
const thisWeekAssignment = getIsCurrentWeek(startDate, week);
const thisWeekAssignment = getIsCurrentWeek(startDate);

return (
<Table>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { Flex } from "@styled-system/jsx";
import { formatDateToISOString, formatStringToDate } from "@wow-class/utils";
import { formatDateToISOString } from "@wow-class/utils";
import { useState } from "react";
import { useFormContext } from "react-hook-form";
import type {
Expand All @@ -20,12 +20,12 @@ const AssignmentForm = ({
assignment: AssignmentApiResponseDto;
}) => {
const { control, setValue } = useFormContext<AssignmentApiRequestDto>();
const { title, descriptionLink, deadline } = assignment;
const { title, descriptionLink, deadline, studyDetailStartDate } = assignment;
const [selectedDate, setSelectedDate] = useState<Date | undefined>(
deadline ? new Date(deadline) : undefined
);

const startDate = findStartDate();
const startDate = findStartDate(studyDetailStartDate);

return (
<Flex direction="column" gap="2.25rem">
Expand Down Expand Up @@ -75,7 +75,7 @@ const findStartDate = (curriculumStartString?: string) => {
);
if (!curriculumStartString) return tomorrow;

const curriculumStartDate = formatStringToDate(curriculumStartString);
const curriculumStartDate = new Date(curriculumStartString);

const curriculumStartTime = curriculumStartDate.getTime();
const tomorrowTime = tomorrow.getTime();
Expand Down
1 change: 1 addition & 0 deletions apps/admin/types/dtos/assignmentList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface AssignmentApiResponseDto {
week: number;
descriptionLink: string | null;
assignmentStatus: StudyAssignmentStatusType;
studyDetailStartDate: string;
}

export interface AssignmentApiRequestDto {
Expand Down
6 changes: 3 additions & 3 deletions apps/admin/utils/getIsCurrentWeek.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const getIsCurrentWeek = (dateString: string, week: number): boolean => {
const getIsCurrentWeek = (dateString: string): boolean => {
const startDate = new Date(dateString);
const today = new Date();

const diffInTime = today.getTime() - startDate.getTime();
const diffInDays = Math.floor(diffInTime / (1000 * 60 * 60 * 24));
const weekNumber = Math.ceil((diffInDays + 1) / 7);
console.log(diffInDays);

return weekNumber === week;
return 0 <= diffInDays && diffInDays < 7;
};

export default getIsCurrentWeek;

0 comments on commit 5b535a5

Please sign in to comment.