Skip to content
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

[WRFE-48] 래플/이벤트 수정 페이지 #50

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const STARTDATE_IS_OVER_ENDDATE = {
title: '유효하지 않은 날짜입니다.',
description: '응모 시작 일정은 응모 마감 일정 이후로 설정해주세요.',
duration: 5000,
variant: 'warning',
};

export const ENDDATE_IS_OVER_ANNOUNCEAT = {
title: '유효하지 않은 날짜입니다.',
description: '응모 마감 일정은 당첨자 발표 일정 이후로 설정해주세요.',
duration: 5000,
variant: 'warning',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const validateDate = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validateDate 보다는 이 날짜가 이전 날짜 보다 큰지를 보여주도록 함수 명에서 드러나면 좋을 것 같아요
isDateBefore 같은 느낌이 되면 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

17b7a0f
수정 커밋입니다!

date: Date | undefined,
referenceDate: Date | undefined,
) => {
if (!date || !referenceDate) return true;
if (date > referenceDate) {
return false;
}
return true;
};
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
'use client';

import type {CreateEventPayload} from '../../../entities/product/model';
import {ENDDATE_IS_OVER_ANNOUNCEAT} from '../config/const';
import {validateDate} from '../config/validateDate';
import {useFormContext} from 'react-hook-form';
import {FormControl, FormField, FormItem, FormLabel} from '@/shared/ui';
import {CalendarForm, useToast} from '@wraffle/ui';

export const EndDateForm = ({
defaultValue,
fromDate: startDate,
referenceDate: announceAt,
}: {
defaultValue: Date;
defaultValue: Date | undefined;
fromDate: Date;
referenceDate: Date | undefined;
}) => {
const {control} = useFormContext<CreateEventPayload>();
const {toast} = useToast();

return (
<FormField
control={control}
Expand All @@ -25,7 +30,13 @@ export const EndDateForm = ({
<CalendarForm
dateLabel='응모 마감 시간을 입력해주세요.'
selected={defaultValue}
setSelected={field.onChange}
onSelect={date => {
if (validateDate(date, announceAt)) {
field.onChange(date);
} else {
toast(ENDDATE_IS_OVER_ANNOUNCEAT);
}
}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ui에서 이 로직을 담당하는 것 보다는 onSelect를 외부에서 받아서 관리하는 방식이 좋아보일 것 같아요!
추후에 이 로직을 수정하기 위해서는 ui에 해당하는 이 onSelect까지 와야 한다는 사실을 알기 어려울 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1ff0234
수정 커밋입니다!

fromDate={startDate}
onClick={e => {
if (!startDate) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
'use client';

import type {CreateEventPayload} from '../../../entities/product/model';
import {STARTDATE_IS_OVER_ENDDATE} from '../config/const';
import {validateDate} from '../config/validateDate';
import {useFormContext} from 'react-hook-form';
import {FormControl, FormField, FormItem, FormLabel} from '@/shared/ui';
import {CalendarForm} from '@wraffle/ui';
import {CalendarForm, useToast} from '@wraffle/ui';

export const StartDateForm = ({defaultValue}: {defaultValue: Date}) => {
export const StartDateForm = ({
defaultValue,
referenceDate: endDate,
}: {
defaultValue: Date | undefined;
referenceDate: Date | undefined;
}) => {
const {control} = useFormContext<CreateEventPayload>();
const {toast} = useToast();
return (
<FormField
control={control}
Expand All @@ -18,7 +27,13 @@ export const StartDateForm = ({defaultValue}: {defaultValue: Date}) => {
<CalendarForm
dateLabel='응모 시작 시간을 입력해주세요.'
selected={defaultValue}
setSelected={field.onChange}
onSelect={date => {
if (validateDate(date, endDate)) {
field.onChange(date);
} else {
toast(STARTDATE_IS_OVER_ENDDATE);
}
}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분도 위와 동일 합니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1ff0234
수정 커밋입니다!

fromDate={new Date()}
/>
</FormControl>
Expand Down
12 changes: 6 additions & 6 deletions packages/ui/src/ui/calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import * as Popover from '@radix-ui/react-popover';
interface CalendarFormProps {
dateLabel: string;
selected: Date | undefined;
setSelected: (selected: Date | undefined) => void;
onSelect: (selected: Date | undefined) => void;
fromDate: Date;
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
}

interface CalendarProps {
selected: Date | undefined;
setSelected: (selected: Date | undefined) => void;
onSelect: (selected: Date | undefined) => void;
setCalendarOpen: (calendarOpen: boolean) => void;
fromDate: Date;
}

export const CalendarForm = ({
dateLabel,
selected,
setSelected,
onSelect,
fromDate,
onClick,
}: CalendarFormProps) => {
Expand Down Expand Up @@ -56,7 +56,7 @@ export const CalendarForm = ({
>
<SingleDayPickCalendar
selected={selected}
setSelected={setSelected}
onSelect={onSelect}
setCalendarOpen={setCalendarOpen}
fromDate={fromDate}
/>
Expand All @@ -68,7 +68,7 @@ export const CalendarForm = ({

const SingleDayPickCalendar = ({
selected,
setSelected,
onSelect,
setCalendarOpen,
fromDate,
}: CalendarProps) => {
Expand All @@ -77,7 +77,7 @@ const SingleDayPickCalendar = ({
mode='single'
selected={selected}
onSelect={date => {
setSelected(date);
onSelect(date);
setCalendarOpen(false);
}}
required
Expand Down