Skip to content

Commit

Permalink
Merge pull request #177 from INtiful/feat/hyuk/KAN-119-auto-participate
Browse files Browse the repository at this point in the history
feat: 모임 만들기 내 기능 추가 및 리팩토링
  • Loading branch information
BeMatthewsong authored Oct 12, 2024
2 parents 35859e7 + 70037de commit 17a5a08
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/app/components/Modal/MakeGatheringModal.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
'use client';

import { useRouter } from 'next/navigation';
import postGatherings from '@/app/api/actions/gatherings/postGatherings';
import postGatheringToJoin from '@/app/api/actions/gatherings/postGatheringToJoin';

import { LOCATION_OPTIONS, MIN_PARTICIPANTS } from '@/constants/common';
import objectCheckFalseValue from '@/utils/objectCheckFalseValue';
import objectExtractTrueValue from '@/utils/objectExtractTrueValue';

import { useRouter } from 'next/navigation';
import { FormEvent, useState } from 'react';
import toast from 'react-hot-toast';

import Button from '../Button/Button';
import BoxSelectGroup from './MakeGatheringModal/BoxSelectGroup';
import CalendarSelect from './MakeGatheringModal/CalendarSelect';
import ImageUploader from './MakeGatheringModal/ImageUploader';
import NameInput from './MakeGatheringModal/NameInput';
import PlaceDropdown from './MakeGatheringModal/PlaceDropdown';
import RecruitmentNumber from './MakeGatheringModal/RecruitmentNumber';
import SelectTimeChip from './MakeGatheringModal/SelectTimeChip';
import ModalFrame from './ModalFrame';
import ModalHeader from './ModalHeader';
import NameInput from './MakeGatheringModal/NameInput';

interface MakeGatheringModalProps {
onClose: () => void;
Expand All @@ -35,19 +41,6 @@ const MakeGatheringModal = ({ onClose }: MakeGatheringModalProps) => {
const [selectedTime, setSelectedTime] = useState<string | null>(null);
const [capacity, setCapacity] = useState<number>(0);

// true인 key 값만 필터링
const getSelectedGatheringType = () => {
const selectedGatheringType = String(
Object.keys(gatheringType).filter((key) => gatheringType[key]),
);
return selectedGatheringType;
};

// 모든 gatheringType이 false인지 확인
const isAllGatheringTypeFalse = () => {
return Object.values(gatheringType).every((value) => value === false);
};

// 캘린더의 날짜와 타임칩의 시간을 결합
let combinedDateTime: Date | null = null;
if (dateTime && selectedTime) {
Expand All @@ -60,7 +53,7 @@ const MakeGatheringModal = ({ onClose }: MakeGatheringModalProps) => {
name &&
location &&
image &&
!isAllGatheringTypeFalse() &&
!objectCheckFalseValue(gatheringType) &&
dateTime &&
selectedTime &&
combinedDateTime &&
Expand All @@ -76,7 +69,7 @@ const MakeGatheringModal = ({ onClose }: MakeGatheringModalProps) => {
const formData = new FormData();
formData.append('name', name);
formData.append('location', location!);
formData.append('type', getSelectedGatheringType());
formData.append('type', objectExtractTrueValue(gatheringType));
formData.append('dateTime', (combinedDateTime as Date).toISOString());
formData.append('capacity', capacity.toString());
formData.append('image', image as File);
Expand All @@ -91,6 +84,8 @@ const MakeGatheringModal = ({ onClose }: MakeGatheringModalProps) => {

onClose();

await postGatheringToJoin(data.id);

router.push(`/gatherings/${data.id}`);

toast.success(message);
Expand Down
7 changes: 7 additions & 0 deletions src/utils/objectCheckFalseValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// 모든 gatheringType이 false인지 확인 (boolean)

const objectCheckFalseValue = (obj: Record<string, boolean>): boolean => {
return Object.values(obj).every((value) => value === false);
};

export default objectCheckFalseValue;
10 changes: 10 additions & 0 deletions src/utils/objectExtractTrueValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// true인 key 값만 필터링해서 문자열로 반환하는 함수

const objectExtractTrueValue = (obj: Record<string, boolean>) => {
const selectedGatheringType = String(
Object.keys(obj).filter((key) => obj[key]),
);
return selectedGatheringType;
};

export default objectExtractTrueValue;

0 comments on commit 17a5a08

Please sign in to comment.