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

[#465] [모임] BookInfoCard 컴포넌트 추상화 #466

Merged
merged 4 commits into from
Jan 4, 2024
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
3 changes: 3 additions & 0 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
- name: Install Dependency
run: yarn install --immutable

- name: Set .env
run: echo "${{ vars.DEVELOPMENT_ENV }}" > .env.local

- name: Publish Chromatic
id: chromatic
uses: chromaui/action@v1
Expand Down
51 changes: 44 additions & 7 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
import React from 'react';

import { rest } from 'msw';
import { initialize, mswLoader } from 'msw-storybook-addon';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import type { Preview } from '@storybook/react';
import '@/styles/global.css';

import Layout from '../src/v1/layout/Layout';
import ToastProvider from '../src/v1/base/Toast/ToastProvider';

import '@/styles/global.css';

const nextApi = (path: string) =>
new URL(path, process.env.NEXT_HOST).toString();

const serviceApi = (path: string) =>
new URL(path, process.env.NEXT_PUBLIC_API_URL).toString();

initialize({}, [
rest.get(nextApi('/service-api/*'), async (req, res, ctx) => {
const { pathname } = req.url;
const match = /\/service-api(?<path>.*)/g.exec(pathname);

if (!match || !match.groups || !match.groups.path) {
return res(ctx.status(404, 'Invalid Request URL'));
}
Comment on lines +21 to +25
Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines +23 to +25
Copy link
Member

Choose a reason for hiding this comment

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

ask;

이 조건부에서 만약 match.groups가 true이면 404에러를 띄워주는것으로 이해했는데
group과 관련없는 api를 호출하게 되었을때도 404에러가 띄어지는것인지 궁금합니다! 🤔

Copy link
Member Author

@gxxrxn gxxrxn Jan 4, 2024

Choose a reason for hiding this comment

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

@hanyugeon

const match = /\/service-api(?<path>.*)/g.exec(pathname);

앗.. 정규표현식에서 named capturing group 문법을 사용했어요. 요청 url에서 /service-api 뒤에 있는 문자열을 path라는 이름으로 가져오려고 할 때, match.groups.path 이렇게 접근할 수 있어요!

스토리북 전역에 queryclinet provider를 추가했기 때문에 nextApi 서버의 url로 들어오는 모든 요청을 처리할 수 있도록 구현했어요. 다독다독에서는 api 요청 url에 모두 /service-api/~ prefix를 붙이고 있기 때문에 결국 이 조건부 코드는 /service-api 로 시작하지 않는 요청, /service-api 뒤에 추가적인 path가 없는 요청에는 404로 응답하겠다는 의미로 이해하시면 될 것 같아요!

Copy link
Member

Choose a reason for hiding this comment

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

@gxxrxn

아하 match에 group이 독서 모임의 group이 아니였군요..!
약간의 오해가 있었군요!
아주 좋습니다 👍


const { path } = match.groups;
const originResponse = await ctx.fetch(serviceApi(`/api${path}`));
const originResponseData = await originResponse.json();

return res(ctx.json({ ...originResponseData }));
}),
]);

const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false,
},
},
});

const preview: Preview = {
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
Expand All @@ -20,13 +54,16 @@ const preview: Preview = {
},
layout: 'fullscreen',
},
loaders: [mswLoader],
decorators: [
Story => (
<ToastProvider>
<Layout>
<Story />
</Layout>
</ToastProvider>
<QueryClientProvider client={queryClient}>
<ToastProvider>
<Layout>
<Story />
</Layout>
</ToastProvider>
</QueryClientProvider>
),
],
};
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
"less": "^4.1.3",
"less-loader": "^11.1.3",
"lint-staged": "^13.1.1",
"msw": "1.3.2",
"msw-storybook-addon": "^1.10.0",
"postcss": "^8.4.25",
"prettier": "^2.8.4",
"prettier-plugin-tailwindcss": "^0.3.0",
Expand All @@ -70,5 +72,8 @@
]
},
"readme": "ERROR: No README data found!",
"_id": "[email protected]"
"_id": "[email protected]",
"msw": {
"workerDirectory": "public"
}
}
3 changes: 3 additions & 0 deletions public/icons/book-plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/icons/delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export { default as IconComments } from './comments.svg';
export { default as IconDelete } from './delete.svg';
export { default as IconMembers } from './members.svg';
export { default as IconPlus } from './plus.svg';
export { default as IconBookPlus } from './book-plus.svg';

// 카카오
export { default as IconKakao } from './kakao.svg';
Loading