Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 0 additions & 5 deletions src/api/book-club/react-query/customHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ export function useBookClubCreateMutation() {
queryClient.invalidateQueries({
queryKey: bookClubs.my().queryKey,
});

showToast({
message: '북클럽이 성공적으로 생성되었습니다.',
type: 'success',
});
},
onError: () => {
showToast({ message: '북클럽 생성에 실패했습니다.', type: 'error' });
Expand Down
10 changes: 10 additions & 0 deletions src/features/club-create/container/DatePickerField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface DatePickerContainerProps {
label: string;
error?: string;
placeholder: string;
targetDate?: Date;
}

function DatePickerContainer({
Expand All @@ -26,8 +27,16 @@ function DatePickerContainer({
label,
error,
placeholder,
targetDate,
}: DatePickerContainerProps) {
const minDate = useMemo(() => new Date(), []);
const maxDate = useMemo(
() =>
name === 'endDate' && targetDate
? new Date(targetDate.getTime() - 24 * 60 * 60 * 1000)
: undefined,
[name, targetDate],
);

return (
<CreateClubFormField label={label} error={error}>
Expand All @@ -39,6 +48,7 @@ function DatePickerContainer({
selected={field.value}
onChange={field.onChange}
minDate={minDate}
maxDate={maxDate}
showTimeSelect
timeIntervals={10}
dateFormat="yyyy-MM-dd a HH:mm"
Expand Down
6 changes: 3 additions & 3 deletions src/features/club-create/container/FormContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function FormContainer() {
control,
setValue,
errors,
isValid,
watch,
onSubmit,
isLoading,
Expand Down Expand Up @@ -118,6 +117,7 @@ function FormContainer() {
label="언제 모임을 마감할까요?"
error={errors.endDate?.message}
placeholder="모임의 모집 마감 날짜를 선택해 주세요!"
targetDate={watch('targetDate')}
/>

<CreateClubFormField
Expand All @@ -139,8 +139,8 @@ function FormContainer() {
size="medium"
fillType="solid"
themeColor="green-normal-01"
disabled={!isValid || isLoading}
className={`h-14 ${!isValid || isLoading ? '' : 'hover-dim'}`}
disabled={isLoading}
className={`h-14 ${isLoading ? '' : 'hover-dim'}`}
/>
</form>

Expand Down
2 changes: 2 additions & 0 deletions src/features/club-create/hooks/useBookClubForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const useBookClubForm = () => {
} = usePopup();
const form = useForm<BookClubForm>({
resolver: zodResolver(bookClubSchema),
mode: 'onChange',
reValidateMode: 'onChange',
});

const onSubmit = form.handleSubmit(async (data: BookClubForm) => {
Expand Down
10 changes: 10 additions & 0 deletions src/features/club-create/types/bookClubSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ export const bookClubSchema = z
});
}
}

if (data.endDate && data.targetDate) {
if (data.endDate >= data.targetDate) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: '모집 마감일은 모임 날짜보다 이전이어야 합니다',
path: ['endDate'],
});
}
}
});

export type BookClubForm = z.infer<typeof bookClubSchema>;
Loading