-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: dev
Are you sure you want to change the base?
Changes from 1 commit
b1720c2
7b6f33f
9e566e6
f0921fd
317bd1c
a80e3fc
83d1fb9
81487ba
09e2e82
c901c75
29d6cff
a9c6708
4e1f418
dc39c87
17b7a0f
1ff0234
825710c
3832569
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 = ( | ||
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} | ||
|
@@ -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); | ||
} | ||
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ui에서 이 로직을 담당하는 것 보다는 onSelect를 외부에서 받아서 관리하는 방식이 좋아보일 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1ff0234 |
||
fromDate={startDate} | ||
onClick={e => { | ||
if (!startDate) { | ||
|
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} | ||
|
@@ -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); | ||
} | ||
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분도 위와 동일 합니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1ff0234 |
||
fromDate={new Date()} | ||
/> | ||
</FormControl> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validateDate 보다는 이 날짜가 이전 날짜 보다 큰지를 보여주도록 함수 명에서 드러나면 좋을 것 같아요
isDateBefore
같은 느낌이 되면 어떨까요?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
17b7a0f
수정 커밋입니다!