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

[#581] [모임 생성] 모임 생성 퍼널 페이지 작성 #582

Merged
merged 17 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
2 changes: 1 addition & 1 deletion src/apis/group/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const groupAPI = {
`/service-api/book-groups?pageSize=10&groupCursorId=` + pageParam
),

createGroup: ({ group }: { group: APICreateGroup }) =>
createGroup: (group: APICreateGroup) =>
publicApi.post('/service-api/book-groups', group),

getGroupDetailInfo: ({
Expand Down
20 changes: 4 additions & 16 deletions src/app/group/create/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
'use client';
import CreateBookGroupFunnel from '@/v1/bookGroup/create/CreateBookGroupFunnel';

import AddGroupForm from '@/ui/Group/AddGroupForm';
import { VStack } from '@chakra-ui/react';
import TopNavigation from '@/ui/common/TopNavigation';
import AuthRequired from '@/ui/AuthRequired';

const GroupCreatePage = () => {
return (
<AuthRequired>
<VStack justify="center" align="center">
<TopNavigation pageTitle="모임 생성" />
<AddGroupForm />
</VStack>
</AuthRequired>
);
const GroupCreateFunnelPage = () => {
return <CreateBookGroupFunnel />;
};

export default GroupCreatePage;
export default GroupCreateFunnelPage;
19 changes: 12 additions & 7 deletions src/hooks/useFunnel.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use client';

import { useEffect, useMemo, useRef } from 'react';
import { usePathname, useRouter, useSearchParams } from 'next/navigation';

import type { FunnelProps, StepProps } from '@/v1/base/Funnel/Funnel';
import { assert } from '@/utils/assert';

import { Funnel, Step } from '@/v1/base/Funnel/Funnel';
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
import type { FunnelProps, StepProps } from '@/v1/base/Funnel';
import { Funnel, Step } from '@/v1/base/Funnel';

export type NonEmptyArray<T> = readonly [T, ...T[]];

Expand Down Expand Up @@ -34,7 +34,11 @@ export const useFunnel = <Steps extends NonEmptyArray<string>>(
initialStep?: Steps[number];
onStepChange?: (name: Steps[number]) => void;
}
): readonly [FunnelComponent<Steps>, (step: Steps[number]) => void] => {
): readonly [
FunnelComponent<Steps>,
(step: Steps[number]) => void,
Steps[number]
] => {
const router = useRouter();
const searchParams = useSearchParams();
const pathname = usePathname();
Expand Down Expand Up @@ -78,11 +82,12 @@ export const useFunnel = <Steps extends NonEmptyArray<string>>(
const params = new URLSearchParams(searchParams.toString());
params.set('funnel-step', `${step}`);

return router.replace(`?${params.toString()}`);
return router.replace(`?${params.toString()}`, { shallow: true });
Comment on lines -81 to +85
Copy link
Member Author

Choose a reason for hiding this comment

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

comment;

관련 문서를 보면 해당 { shallow: true } 옵션을 통해 url의 query가 바뀌어도 페이지가 교체되지 않는다고 합니다 🤔

};

return [FunnelComponent, setStep] as unknown as readonly [
return [FunnelComponent, setStep, step] as unknown as readonly [
FunnelComponent<Steps>,
(step: Steps[number]) => Promise<void>
(step: Steps[number]) => Promise<void>,
Steps[number]
Comment on lines +88 to +91
Copy link
Member Author

@hanyugeon hanyugeon May 12, 2024

Choose a reason for hiding this comment

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

comment;

이제 useFunnel 커스텀 훅에서 현재 step의 name을 반환하는 currentStep을 return 합니다

const [Funnel, setStep, currentStep] = useFunnel(FUNNEL_STEPS, {
  initialStep: 'SelectBook',
});

];
};
13 changes: 13 additions & 0 deletions src/queries/group/useCreateBookGroupMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useMutation } from '@tanstack/react-query';

import type { APICreateGroup } from '@/types/group';
import groupAPI from '@/apis/group';

const useCreateBookGroupMutation = () => {
return useMutation({
mutationFn: (formData: APICreateGroup) =>
groupAPI.createGroup(formData).then(({ data }) => data),
});
};

export default useCreateBookGroupMutation;
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Meta, StoryObj } from '@storybook/react';
import { appLayoutMeta } from '@/stories/meta';
import { FormProvider, useForm } from 'react-hook-form';

import {
EnterTitleStep,
type EnterTitleStepValues,
} from '@/v1/bookGroup/create/steps/EnterTitleStep';
import type { EnterTitleStepValues } from '@/v1/bookGroup/create/types';

import { appLayoutMeta } from '@/stories/meta';
import { EnterTitleStep } from '@/v1/bookGroup/create/steps';

const meta: Meta<typeof EnterTitleStep> = {
title: 'bookGroup/create/steps/EnterTitleStep',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Meta, StoryObj } from '@storybook/react';
import { FormProvider, useForm } from 'react-hook-form';

import type { SelectBookFormValues } from '@/v1/bookGroup/create/types';

import { appLayoutMeta } from '@/stories/meta';
import SelectBookStep, {
SelectBookFormValue,
} from '@/v1/bookGroup/create/funnel/SelectBookStep';
import { SelectBookStep } from '@/v1/bookGroup/create/steps';

const meta: Meta<typeof SelectBookStep> = {
title: 'bookGroup/funnel/SelectBookStep',
title: 'bookGroup/create/steps/SelectBookStep',
component: SelectBookStep,
...appLayoutMeta,
};
Expand All @@ -17,7 +17,7 @@ export default meta;
type Story = StoryObj<typeof SelectBookStep>;

const RenderSelectBookStep = () => {
const methods = useForm<SelectBookFormValue>();
const methods = useForm<SelectBookFormValues>();

const goNextStep = () => {
const book = methods.getValues('book');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Meta, StoryObj } from '@storybook/react';
import { FormProvider, useForm } from 'react-hook-form';
import { appLayoutMeta } from '@/stories/meta';

import {
SelectJoinTypeStep,
SelectJoinTypeStepFormValues,
} from '@/v1/bookGroup/create/steps/SelectJoinTypeStep';
import type { SelectJoinTypeStepFormValues } from '@/v1/bookGroup/create/types';

import { appLayoutMeta } from '@/stories/meta';
import { SelectJoinTypeStep } from '@/v1/bookGroup/create/steps';

const meta: Meta<typeof SelectJoinTypeStep> = {
title: 'bookGroup/create/steps/SelectJoinTypeStep',
Expand All @@ -20,15 +19,15 @@ type Story = StoryObj<typeof SelectJoinTypeStep>;
const RenderSelectJoinTypeStep = () => {
const methods = useForm<SelectJoinTypeStepFormValues>({
defaultValues: {
hasJoinPasswd: 'false',
hasJoinPassword: 'false',
},
mode: 'all',
});

const onSubmit = () => {
const { hasJoinPasswd, joinPasswd, joinQuestion } = methods.getValues();
const { hasJoinPassword, joinPassword, joinQuestion } = methods.getValues();
alert(
`가입 문제 유무: ${hasJoinPasswd}\n가입 문제: ${joinQuestion}\n정답: ${joinPasswd}`
`가입 문제 유무: ${hasJoinPassword}\n가입 문제: ${joinQuestion}\n정답: ${joinPassword}`
);
};

Expand Down
14 changes: 4 additions & 10 deletions src/stories/bookGroup/create/steps/SetUpDetailStep.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { appLayoutMeta } from '@/stories/meta';
import { Meta, StoryObj } from '@storybook/react';
import { FormProvider, useForm } from 'react-hook-form';

import type { SetUpDetailStepValues } from '@/v1/bookGroup/create/types';

import { getTodayDate } from '@/utils/date';

import {
SetUpDetailStep,
type SetUpDetailStepValues,
} from '@/v1/bookGroup/create/steps/SetUpDetailStep';
import { appLayoutMeta } from '@/stories/meta';
import { SetUpDetailStep } from '@/v1/bookGroup/create/steps';

const meta: Meta<typeof SetUpDetailStep> = {
title: 'bookGroup/create/steps/SetUpDetailStep',
Expand All @@ -27,12 +26,7 @@ const SetUpDetailForm = () => {
book: {
bookId: 23,
},
introduce: '',
maxMemberCount: '',
customMemberCount: '',
startDate: getTodayDate(),
endDate: '',
isPublic: false,
},
});

Expand Down
Loading
Loading