Skip to content

Commit

Permalink
feat: 스토리북에 msw 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
cobocho committed Jun 12, 2024
1 parent 03d2134 commit c3886d2
Show file tree
Hide file tree
Showing 22 changed files with 1,097 additions and 123 deletions.
34 changes: 34 additions & 0 deletions apps/web/src/components/SignUpForm/SignUpForm.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
AppRouterContext,
type AppRouterInstance,
} from 'next/dist/shared/lib/app-router-context.shared-runtime'
import type { Meta, StoryObj } from '@storybook/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'

import { SignUpForm } from './SignUpForm'

const meta: Meta<typeof SignUpForm> = {
title: 'SignUpForm',
parameters: {
layout: 'centered',
},
component: SignUpForm,
tags: ['autodocs'],
decorators: [
(Story) => (
<AppRouterContext.Provider value={{} as AppRouterInstance}>
<QueryClientProvider client={new QueryClient()}>
<div style={{ width: 400 }}>
<Story />
</div>
</QueryClientProvider>
</AppRouterContext.Provider>
),
],
}

export default meta

type Story = StoryObj<typeof meta>

export const Preview: Story = {}
40 changes: 24 additions & 16 deletions apps/web/src/components/SignUpForm/SignUpForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button, Checkbox, Input, Text } from '@vook-client/design-system'
import { useSignUpMutation, useUserInfoQuery } from '@vook-client/api'
import { useForm } from 'react-hook-form'
import { zodResolver } from '@hookform/resolvers/zod'
import { ChangeEventHandler } from 'react'
import { ChangeEventHandler, useMemo } from 'react'
import { useRouter } from 'next/navigation'
import z from 'zod'
import Cookies from 'js-cookie'
Expand Down Expand Up @@ -59,17 +59,33 @@ export const SignUpForm = () => {
},
)

const isAllChecked = useMemo(
() =>
watch('requiredTermsAgree') &&
watch('policyAgree') &&
watch('marketingEmailOptIn'),
[watch],
)

const isSubmitting = useMemo(
() => signUpMutation.isPending,
[signUpMutation.isPending],
)

const canSubmit = useMemo(
() =>
!formState.isValid ||
signUpMutation.isPending ||
signUpMutation.isSuccess,
[formState.isValid, signUpMutation.isPending, signUpMutation.isSuccess],
)

if (!userInfoQuery.data) {
return null
}

const email = userInfoQuery.data.result.email

const isAllChecked =
watch('requiredTermsAgree') &&
watch('policyAgree') &&
watch('marketingEmailOptIn')

const onSubmit = handleSubmit(() => {
signUpMutation.mutate()
})
Expand Down Expand Up @@ -162,16 +178,8 @@ export const SignUpForm = () => {
<Button
type="submit"
fit="fill"
disabled={
!formState.isValid ||
signUpMutation.isPending ||
signUpMutation.isSuccess
}
suffixIcon={
signUpMutation.isPending || signUpMutation.isSuccess
? 'spinner-big'
: undefined
}
disabled={canSubmit}
suffixIcon={isSubmitting ? 'spinner-big' : undefined}
>
가입하기
</Button>
Expand Down
3 changes: 2 additions & 1 deletion apps/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"@/providers/*": ["./src/providers/*"],
"@/components/*": ["./src/components/*"],
"@/styles/*": ["./src/styles/*"],
"@/utils/*": ["./src/utils/*"]
"@/utils/*": ["./src/utils/*"],
"@/mocks/*": ["./src/mocks/*"]
}
},
"include": [
Expand Down
7 changes: 6 additions & 1 deletion apps/workshop/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ const config: StorybookConfig = {
docs: {
autodocs: 'tag',
},
staticDirs: ['../public'],
staticDirs: [
{
from: '../public',
to: './public',
},
],
async viteFinal(config, type) {
return mergeConfig(config, {
define: {
Expand Down
16 changes: 15 additions & 1 deletion apps/workshop/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import '@vook-client/design-system/style.css'
import './storybook.css'

const preview = {
import { handlers } from '@vook-client/api'

import { initialize, mswLoader } from 'msw-storybook-addon'

import { Preview } from '@storybook/react'

initialize()

const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
msw: {
handlers: {
...handlers,
},
},
},
loaders: [mswLoader],
}

export default preview
10 changes: 9 additions & 1 deletion apps/workshop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"build-storybook": "storybook build"
},
"dependencies": {
"@vook-client/design-system": "*",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"@vook-client/design-system": "*"
"@vook-client/api": "*"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.3.3",
Expand All @@ -33,8 +34,15 @@
"chromatic": "^11.3.2",
"css-loader": "^7.1.1",
"mini-css-extract-plugin": "^2.9.0",
"msw": "^2.3.1",
"msw-storybook-addon": "^2.0.2",
"storybook": "^8.0.10",
"style-loader": "^4.0.0",
"vite": "^4.4.5"
},
"msw": {
"workerDirectory": [
"public"
]
}
}
3 changes: 0 additions & 3 deletions apps/workshop/public/Icons/backward.svg

This file was deleted.

8 changes: 0 additions & 8 deletions apps/workshop/public/Icons/blog.svg

This file was deleted.

4 changes: 0 additions & 4 deletions apps/workshop/public/Icons/close-circle.svg

This file was deleted.

3 changes: 0 additions & 3 deletions apps/workshop/public/Icons/close.svg

This file was deleted.

5 changes: 0 additions & 5 deletions apps/workshop/public/Icons/instagram.svg

This file was deleted.

3 changes: 0 additions & 3 deletions apps/workshop/public/Icons/plus.svg

This file was deleted.

3 changes: 0 additions & 3 deletions apps/workshop/public/Icons/search.svg

This file was deleted.

5 changes: 0 additions & 5 deletions apps/workshop/public/Icons/symbol.svg

This file was deleted.

6 changes: 0 additions & 6 deletions apps/workshop/public/Icons/typo.svg

This file was deleted.

Loading

0 comments on commit c3886d2

Please sign in to comment.