Skip to content

Commit

Permalink
Merge pull request #1009 from sopt-makers/develop
Browse files Browse the repository at this point in the history
프로덕션 배포
  • Loading branch information
borimong authored Feb 8, 2025
2 parents 0624955 + 9e4c819 commit 501f19a
Show file tree
Hide file tree
Showing 29 changed files with 383 additions and 156 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@
"workspaces": [
"packages/*"
]
}
}
172 changes: 172 additions & 0 deletions pages/edit/flash/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import { zodResolver } from '@hookform/resolvers/zod';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useRouter } from 'next/router';
import { useEffect } from 'react';
import { FormProvider, SubmitHandler, useForm } from 'react-hook-form';
import { styled } from 'stitches.config';
import Loader from '@components/@common/loader/Loader';
import dynamic from 'next/dynamic';
import { useFlashByIdQuery } from '@api/flash/hook';
import { FlashFormType, flashSchema } from '@type/form';
import Presentation from '@components/form/Flash';
import BungaeIcon from '@assets/svg/bungae.svg';
import { updateFlashById } from '@api/flash';
import dayjs from 'dayjs';

const DevTool = dynamic(() => import('@hookform/devtools').then(module => module.DevTool), {
ssr: false,
});

const FlashEditPage = () => {
const queryClient = useQueryClient();
const router = useRouter();
const id = +(router.query.id || 0);

const { data: formData } = useFlashByIdQuery({ meetingId: id });
const { mutateAsync, isLoading: isSubmitting } = useMutation({
mutationFn: ({ id, formData }: { id: number; formData: FlashFormType }) => updateFlashById({ id, formData }),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['getFlash', id] });
},
});

const formMethods = useForm<FlashFormType>({
mode: 'onChange',
resolver: zodResolver(flashSchema),
});

const { isValid, errors } = formMethods.formState;

const onSubmit: SubmitHandler<FlashFormType> = async formData => {
try {
await mutateAsync({ id, formData });
// TODO: handle success
alert('모임을 수정했습니다.');
router.push(`/detail?id=${id}`);
} catch (error) {
// TODO: handle error
alert('모임을 수정하지 못했습니다.');
}
};

const handleChangeImage = (index: number, url: string) => {
const files = formMethods.getValues().files.slice();
files.splice(index, 1, url);
formMethods.setValue('files', files);
};

const handleDeleteImage = (index: number) => {
const files = formMethods.getValues().files.slice();
files.splice(index, 1);
formMethods.setValue('files', files);
};

useEffect(() => {
if (!formData) {
return;
}
async function fillForm() {
formMethods.reset({
...formData,
title: formData?.title,
desc: formData?.desc,
timeInfo: {
time: {
label: formData?.flashTimingType,
value: formData?.flashTimingType,
},
startDate: dayjs(formData?.activityStartDate).format('YYYY.MM.DD'),
endDate: dayjs(formData?.activityEndDate).format('YYYY.MM.DD'),
},
placeInfo: {
place: {
label: formData?.flashPlaceType,
value: formData?.flashPlaceType,
},
placeDetail: formData?.flashPlace,
},
capacityInfo: {
minCapacity: formData?.minimumCapacity,
maxCapacity: formData?.maximumCapacity,
},
files: formData?.imageURL.map(({ url }) => url),
welcomeTags: formData?.welcomeMessageTypes.map(type => ({ label: type, value: type })),
});
}

fillForm();
}, [formMethods, formData]);

if (!formData) {
return <Loader />;
}

return (
<FormProvider {...formMethods}>
<SContainer>
<SFormContainer>
<SFormName>번쩍 수정하기</SFormName>
<SFormWrapper>
<Presentation
errors={errors}
submitButtonLabel={
<>
<BungaeIcon />
번쩍 수정하기
</>
}
cancelButtonLabel="수정 취소하기"
handleChangeImage={handleChangeImage}
handleDeleteImage={handleDeleteImage}
onSubmit={formMethods.handleSubmit(onSubmit)}
disabled={isSubmitting || !isValid}
placeType={formData.flashPlaceType as '협의 후 결정' | '오프라인' | '온라인'}
timeType={formData.flashTimingType as '당일' | '예정 기간 (협의 후 결정)'}
/>
</SFormWrapper>
</SFormContainer>
</SContainer>
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
{/* @ts-ignore */}
<DevTool control={formMethods.control} />
</FormProvider>
);
};

export default FlashEditPage;

const SContainer = styled('div', {
margin: '80px 0',
display: 'flex',
gap: '30px',

'@tablet': {
margin: 0,
},
});
const SFormContainer = styled('div', {
width: '100%',
padding: '44px 40px 56px',
borderRadius: '15px',

'@tablet': {
padding: '40px 0 0 0',
background: '$gray950',
},
});
const SFormName = styled('h1', {
fontAg: '24_bold_100',
color: '$gray10',
marginBottom: '90px',

'@tablet': {
margin: 0,
paddingBottom: '40px',
borderBottom: '1px solid $gray700',
},
});
const SFormWrapper = styled('div', {
'@tablet': {
paddingTop: '40px',
},
});
12 changes: 4 additions & 8 deletions pages/edit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import Presentation from '@components/form/Presentation';
import TableOfContents from '@components/form/TableOfContents';
import { zodResolver } from '@hookform/resolvers/zod';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useRouter } from 'next/router';
import { useEffect } from 'react';
import { FormProvider, SubmitHandler, useForm } from 'react-hook-form';
import { getMeeting, updateMeeting } from '@api/API_LEGACY/meeting';
import { updateMeeting } from '@api/API_LEGACY/meeting';
import { FormType, schema } from '@type/form';
import { styled } from 'stitches.config';
import dayjs from 'dayjs';
import Loader from '@components/@common/loader/Loader';
import CheckIcon from '@assets/svg/check.svg';
import dynamic from 'next/dynamic';
import { parts } from '@data/options';
import { useQueryGetMeeting } from '@api/API_LEGACY/meeting/hooks';
const DevTool = dynamic(() => import('@hookform/devtools').then(module => module.DevTool), {
ssr: false,
});
Expand All @@ -22,12 +23,7 @@ const EditPage = () => {
const router = useRouter();
const id = router.query.id as string;

const query = useQuery({
queryKey: ['meeting', id],
queryFn: () => getMeeting(id),
enabled: !!id,
});
const { data: formData } = query;
const { data: formData } = useQueryGetMeeting({ params: { id } });
const { mutateAsync, isLoading: isSubmitting } = useMutation({
mutationFn: ({ id, formData }: { id: string; formData: FormType }) => updateMeeting(id, formData),
onSuccess: () => {
Expand Down
4 changes: 2 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ const Home: NextPage = () => {
{isLoading && (isTablet ? <MobileFeedListSkeleton count={3} /> : <DesktopFeedListSkeleton row={3} column={3} />)}
{isTablet ? (
<>
<SContentTitle style={{ marginTop: '16px' }}>️솝트만의 일회성 모임, 번쩍</SContentTitle>
<SContentTitle style={{ marginTop: '16px' }}>솝트만의 일회성 모임, 번쩍</SContentTitle>
{flashList && <GroupBrowsingSlider cardList={flashList}></GroupBrowsingSlider>}
</>
) : (
<>
<Flex align="center" justify="center">
<SContentTitle style={{ marginTop: '54px' }}>️솝트만의 일회성 모임, 번쩍</SContentTitle>
<SContentTitle style={{ marginTop: '54px' }}>솝트만의 일회성 모임, 번쩍</SContentTitle>
</Flex>
<GroupBrowsingCarouselContainer>
{flashList && <Carousel cardList={flashList} />}
Expand Down
27 changes: 18 additions & 9 deletions pages/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Filter from '@components/page/list/Filter';
import Search from '@components/page/list/Filter/Search';
import GridLayout from '@components/page/list/Grid/Layout';
import { MeetingListOfAll } from '@components/page/list/Grid/List';
import NoticeSlider from '@components/page/list/Slider/NoticeSlider/NoticeSlider';
import { SSRSafeSuspense } from '@components/util/SSRSafeSuspense';
import useModal from '@hooks/useModal';
import { playgroundLink } from '@sopt-makers/playground-common';
Expand All @@ -18,12 +17,15 @@ import { useRouter } from 'next/router';
import { useEffect } from 'react';
import { styled } from 'stitches.config';
import CrewTab from '@components/CrewTab';
import Chips from '@components/page/list/Filter/Modal/Chip';
import { CATEGORY_FILTER } from '@constants/option';

const Home: NextPage = () => {
const router = useRouter();
const { data: me } = useQueryMyProfile();
const { isModalOpened, handleModalOpen, handleModalClose } = useModal();
const { data: notices } = useNotices();

const categoryFilterStyle = { display: 'flex', alignItems: 'flex-start', gap: '$12', alignSelf: 'stretch' };

const handleMakeMeeting = () => {
if (!me?.hasActivities) {
Expand Down Expand Up @@ -61,12 +63,12 @@ const Home: NextPage = () => {
</SMakeMeetingButton>
</CrewTab>

{/*Notice 슬라이더*/}
<SNoticeWrapper>
<NoticeSlider notices={notices} />
</SNoticeWrapper>
{/*카테고리 필터 칩*/}
<SChipWrapper>
<Chips css={categoryFilterStyle} filter={CATEGORY_FILTER} />
</SChipWrapper>

{/*필터 - 필터, 모임 검색, 모임 신청 가이드, 필터 적용 후 생기는 FLEX 박스(chip 모임)*/}
{/*필터 - 모임 검색, 드롭다운, 토글, 모임 신청 가이드*/}
<SFilterWrapper>
<Filter />
</SFilterWrapper>
Expand Down Expand Up @@ -136,10 +138,10 @@ const SMobileButtonContainer = styled('div', {
});

const SFilterWrapper = styled('div', {
mt: '$40',
mt: '$20',
mb: '$64',
'@tablet': {
mt: '$32',
mt: '$16',
mb: '$24',
},
});
Expand All @@ -150,3 +152,10 @@ const SNoticeWrapper = styled('div', {
mt: '$28',
},
});

const SChipWrapper = styled('div', {
mt: '$45',
'@tablet': {
mt: '$32',
},
});
2 changes: 1 addition & 1 deletion pages/make/flash/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dynamic from 'next/dynamic';
import { ampli } from '@/ampli';
import { fontsObject } from '@sopt-makers/fonts';
import { colors } from '@sopt-makers/colors';
import Presentation from '@components/form/Bungae';
import Presentation from '@components/form/Flash';
import { createFlash } from '@api/flash';

const DevTool = dynamic(() => import('@hookform/devtools').then(module => module.DevTool), {
Expand Down
4 changes: 4 additions & 0 deletions public/assets/svg/arrow_right_circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions src/api/flash/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const filterFlashFormData = (formData: FlashFormType) => {
activityEndDate: convertedEndDate,
flashPlaceType: formData.placeInfo.place.value,
flashPlace: convertedFlashPlace,
minimumCapacity: formData.minCapacity,
maximumCapacity: formData.maxCapacity,
minimumCapacity: formData.capacityInfo.minCapacity,
maximumCapacity: formData.capacityInfo.maxCapacity,
files: formData.files,
},
welcomeMessageTypes: convertedTags?.length === 0 ? null : convertedTags,
Expand Down Expand Up @@ -54,3 +54,10 @@ export const getFlashList = async () => {
};
return (await api.get<GetMeetingListResponse>('/meeting/v2', { params })).data;
};

export const updateFlashById = async ({ id, formData }: { id: number; formData: FlashFormType }) => {
const {
data: { meetingId },
} = await api.put(`/flash/v2/${id}`, filterFlashFormData(formData));
return meetingId;
};
4 changes: 2 additions & 2 deletions src/api/meeting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ const filterFlashFormData = (formData: FlashFormType) => {
activityEndDate: convertedEndDate,
flashPlaceType: formData.placeInfo.place.value,
flashPlace: convertedFlashPlace,
minimumCapacity: formData.minCapacity,
maximumCapacity: formData.maxCapacity,
minimumCapacity: formData.capacityInfo.minCapacity,
maximumCapacity: formData.capacityInfo.maxCapacity,
files: formData.files,
},
welcomeMessageTypes: convertedTags?.length === 0 ? null : convertedTags,
Expand Down
Loading

0 comments on commit 501f19a

Please sign in to comment.