Skip to content

Commit

Permalink
Fix: #301 프로젝트 생성 & 할 일 생성 날짜 종료일 수정 (#307)
Browse files Browse the repository at this point in the history
* Fix: #301 프로젝트 생성 & 할 일 생성 날짜 종료일 수정

* Fix: #301 코드리뷰 반영 수정
  • Loading branch information
ice-bear98 authored Dec 25, 2024
1 parent ffa89ba commit 58f082e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/components/common/PeriodDateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type PeriodDateInputProps = {
endDateLabel: string;
startDateFieldName: string;
endDateFieldName: string;
enableEndDateSync: boolean;
limitStartDate?: string | Date | null;
limitEndDate?: string | Date | null;
};
Expand All @@ -27,6 +28,7 @@ export default function PeriodDateInput({
endDateFieldName,
limitStartDate = null,
limitEndDate = null,
enableEndDateSync = true,
}: PeriodDateInputProps) {
const [hasDeadline, setHasDeadline] = useState(false);
const { toastWarn } = useToast();
Expand All @@ -44,11 +46,12 @@ export default function PeriodDateInput({
useEffect(() => {
const startDate = startDateStr ? DateTime.fromISO(startDateStr).startOf('day') : null;
const endDate = endDateStr ? DateTime.fromISO(endDateStr).startOf('day') : null;

if (startDate && endDate) setHasDeadline(startDate < endDate);
}, [startDateStr, endDateStr]);

const handleDeadlineToggle = () => {
setValue(endDateFieldName, getValues(startDateFieldName));
setValue(endDateFieldName, enableEndDateSync ? null : getValues(startDateFieldName));
clearErrors(endDateFieldName);
setHasDeadline((prev) => !prev);
};
Expand Down Expand Up @@ -82,7 +85,12 @@ export default function PeriodDateInput({
className={`${hasDeadline ? '' : '!bg-disable outline-none'}`}
readOnly={!hasDeadline}
{...register(endDateFieldName, {
...PERIOD_VALIDATION_RULES.END_DATE(hasDeadline, limitStartDate, limitEndDate, watch(startDateFieldName)),
...PERIOD_VALIDATION_RULES.END_DATE(
hasDeadline,
limitStartDate,
limitEndDate,
hasDeadline ? startDateStr : null,
),
onChange: (e) => {
const startDate = DateTime.fromISO(startDateStr).startOf('day');
const endDate = DateTime.fromISO(e.target.value).startOf('day');
Expand Down
5 changes: 3 additions & 2 deletions src/components/modal/project/ModalProjectForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { FormProvider, useForm } from 'react-hook-form';
import { DateTime } from 'luxon';
import { useMemo, useState } from 'react';
import RoleTooltip from '@components/common/RoleTooltip';
import { PROJECT_DEFAULT_ROLE, PROJECT_ROLE_INFO, PROJECT_ROLES } from '@constants/role';
import { PROJECT_VALIDATION_RULES } from '@constants/formValidationRules';
import Spinner from '@components/common/Spinner';
import RoleTooltip from '@components/common/RoleTooltip';
import PeriodDateInput from '@components/common/PeriodDateInput';
import SearchUserInput from '@components/common/SearchUserInput';
import UserRoleSelectBox from '@components/common/UserRoleSelectBox';
Expand Down Expand Up @@ -55,7 +55,7 @@ export default function ModalProjectForm({ formId, onSubmit }: ModalProjectFormP
projectName: '',
content: '',
startDate: DateTime.fromJSDate(new Date()).toFormat('yyyy-LL-dd'),
endDate: DateTime.fromJSDate(new Date()).toFormat('yyyy-LL-dd'),
endDate: null,
coworkers: [],
},
});
Expand Down Expand Up @@ -157,6 +157,7 @@ export default function ModalProjectForm({ formId, onSubmit }: ModalProjectFormP
endDateId="endDate"
startDateFieldName="startDate"
endDateFieldName="endDate"
enableEndDateSync
/>

<SearchUserInput
Expand Down
1 change: 1 addition & 0 deletions src/components/modal/project/UpdateModalProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export default function UpdateModalProject({ projectId, onClose: handleClose }:
endDateId="endDate"
startDateFieldName="startDate"
endDateFieldName="endDate"
enableEndDateSync
/>
</form>
</FormProvider>
Expand Down
1 change: 1 addition & 0 deletions src/components/modal/task/ModalTaskForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export default function ModalTaskForm({ formId, project, onSubmit }: ModalTaskFo
endDateFieldName="endDate"
limitStartDate={projectStartDate}
limitEndDate={projectEndDate}
enableEndDateSync
/>

<div className="mb-20">
Expand Down
1 change: 1 addition & 0 deletions src/components/modal/task/UpdateModalTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export default function UpdateModalTask({
endDateFieldName="endDate"
limitStartDate={projectStartDate}
limitEndDate={projectEndDate}
enableEndDateSync={false}
/>

<MarkdownEditor id="content" label="내용" contentFieldName="content" />
Expand Down
4 changes: 2 additions & 2 deletions src/constants/formValidationRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type ValidateOption = { [key: string]: (value: string) => string | boolean };
function getDateValidation(
periodStartDate: Date | string | null,
periodEndDate: Date | string | null,
referenceDate?: Date | string,
referenceDate?: Date | string | null,
) {
const validation: ValidateOption = {};
// 기준일이 설정되어 있다면, 기준일 이후로 설정되는가 검증
Expand Down Expand Up @@ -199,7 +199,7 @@ export const PERIOD_VALIDATION_RULES = deepFreeze({
hasDeadline: boolean,
periodStartDate: Date | string | null,
periodEndDate: Date | string | null,
referenceDate: Date | string,
referenceDate: Date | string | null,
) => ({
required: hasDeadline && '종료일을 선택해주세요.',
validate: getDateValidation(periodStartDate, periodEndDate, referenceDate),
Expand Down

0 comments on commit 58f082e

Please sign in to comment.