Skip to content

Commit

Permalink
Merge pull request #64 from woowacourse-teams/refactor/#51
Browse files Browse the repository at this point in the history
2-1 스프린트 전체 리팩토링
  • Loading branch information
ss0526100 authored Jul 17, 2024
2 parents 695b9c8 + 142d193 commit 3f18b0b
Show file tree
Hide file tree
Showing 51 changed files with 887 additions and 551 deletions.
512 changes: 512 additions & 0 deletions frontend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@storybook/react-webpack5": "^8.1.11",
"@storybook/test": "^8.1.11",
"@stylelint/postcss-css-in-js": "^0.38.0",
"@svgr/webpack": "^8.1.0",
"@tanstack/react-query": "^5.51.1",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
Expand Down
36 changes: 6 additions & 30 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
import { Global } from '@emotion/react';
import reset from './reset';

import {
QueryClient,
QueryClientProvider,
MutationCache,
} from '@tanstack/react-query';
import { RouterProvider, createBrowserRouter } from 'react-router-dom';

import ENDPOINTS from './constants/endpoints';
import { QueryClientProvider } from '@tanstack/react-query';
import { RouterProvider } from 'react-router-dom';
import createQueryClient from './queryClient';
import reset from './common/reset.style';
import router from './router';
import { useMemo } from 'react';
import MoimListPage from './pages/MoimList';
import MoimRegisterPage from './pages/MoimRegister';

const router = createBrowserRouter([
{
path: ENDPOINTS.main,
element: <MoimListPage />,
},
{
path: ENDPOINTS.addMoim,
element: <MoimRegisterPage />,
},
]);

export default function App() {
const queryClient = useMemo(() => {
return new QueryClient({
mutationCache: new MutationCache({
onError: (e: Error) => console.log(e),
}),
});
}, []);
const queryClient = useMemo(createQueryClient, []);

return (
<>
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/apis/endPoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ENV from '@_apis/env';

const getEndpoint = (string: string) => {
return `${ENV.baseUrl}/${string}`;
};

const ENDPOINTS = {
moim: getEndpoint('v1/moim'),
moims: getEndpoint('v1/moim'),
};
export default ENDPOINTS;
15 changes: 7 additions & 8 deletions frontend/src/apis/gets.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { GetMoim, MoimInfo } from '../types/requests';

import ENV from './env';
import ENDPOINTS from '@_apis/endPoints';
import { GetMoim } from '@_apis/responseTypes';
import { MoimInfo } from '@_types/index';

export const getMoims = async (): Promise<MoimInfo[]> => {
const url = `${ENV.baseUrl}/${'v1/moim'}`;

const headers = new Headers();
headers.append('Content-Type', 'application/json');
const url = ENDPOINTS.moims;

const options = {
method: 'GET',
Expand All @@ -18,8 +15,10 @@ export const getMoims = async (): Promise<MoimInfo[]> => {
const response = await fetch(url, options);

const statusHead = Math.floor(response.status / 100);
if (statusHead === 4 || statusHead === 5)
if (statusHead === 4 || statusHead === 5) {
throw new Error('모임을 받아오지 못했습니다.');
}

const json = (await response.json()) as GetMoim;
return json.data.moims;
};
8 changes: 4 additions & 4 deletions frontend/src/apis/posts.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { MoimInfo, PostMoim } from '../types/requests';

import ENV from './env';
import ENDPOINTS from '@_apis/endPoints';
import { MoimInfo } from '@_types/index';
import { PostMoim } from '@_apis/responseTypes';

export const postMoim = async (moim: MoimInfo): Promise<number> => {
const url = `${ENV.baseUrl}/${'v1/moim'}`;
const url = ENDPOINTS.moim;

const options = {
method: 'POST',
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/apis/responseTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { MoimInfo } from '../types';

export interface GetMoim {
data: { moims: MoimInfo[] };
}

export interface PostMoim {
id: number;
}
12 changes: 0 additions & 12 deletions frontend/src/button.styles.ts

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion frontend/src/common/reset.style.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { css } from '@emotion/react';

const reset = css`
html,
body,
Expand Down Expand Up @@ -84,9 +85,10 @@ const reset = css`
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font-size: 62.5%;
font: inherit;
vertical-align: baseline;
box-sizing: border-box;
}
/* HTML5 display-role reset for older browsers */
article,
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import type ButtonProps from './Button.type';
import { shapes } from './Button.style';
import { ReactNode } from 'react';
import { shapes } from '@_components/Button/Button.style';

interface ButtonProps {
shape: 'circle' | 'bar';
onClick: () => void;
disabled: boolean;
children: ReactNode;
}

export default function Button(props: ButtonProps) {
const { shape, onClick, disabled, children } = props;
Expand Down
8 changes: 0 additions & 8 deletions frontend/src/components/Button/Button.type.ts

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/src/components/Card/MoimCard.style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { common } from '@_common/common.style';
import { css } from '@emotion/react';
import { common } from '../../common/common.style';

export const cardBox = css`
display: flex;
Expand Down
17 changes: 12 additions & 5 deletions frontend/src/components/Card/MoimCard.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import * as S from './MoimCard.style';
import * as S from '@_components/Card/MoimCard.style';

import { hhmmToKorean, yyyymmddToKorean } from '../../utils/formatters';
import {
formatHhmmToKorean,
formatYyyymmddToKorean,
} from '../../utils/formatters';

import MoimCardProps from './MoimCard.type';
import { MoimInfo } from '../../types';

interface MoimCardProps {
moimInfo: MoimInfo;
}

export default function MoimCard(props: MoimCardProps) {
const {
data: { title, date, time, place, maxPeople },
moimInfo: { title, date, time, place, maxPeople },
} = props;

return (
Expand All @@ -15,7 +22,7 @@ export default function MoimCard(props: MoimCardProps) {
<div css={S.subjectBox}>
<span css={S.subjectTag}>날짜 및 시간</span>
<span css={S.subjectInfo}>
{`${yyyymmddToKorean(date)} ${hhmmToKorean(time)}`}
{`${formatYyyymmddToKorean(date)} ${formatHhmmToKorean(time)}`}
</span>
</div>
<div css={S.subjectBox}>
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/components/Card/MoimCard.type.ts

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/src/components/Input/MoimInput.style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { common } from '@_common/common.style';
import { css } from '@emotion/react';
import { common } from '../../common/common.style';

export const required = css`
color: #f00;
Expand Down
19 changes: 10 additions & 9 deletions frontend/src/components/Input/MoimInput.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import MoimInputProps from './MoimInput.type';
import * as S from './MoimInput.style';
import * as S from '@_components/Input/MoimInput.style';

export default function MoimInput(props: MoimInputProps) {
const {
name,
data: { title, type, placeholder, required },
onChange,
} = props;
import { HTMLProps } from 'react';

export interface LabeledInputProps extends HTMLProps<HTMLInputElement> {
title: string;
}

export default function LabeledInput(props: LabeledInputProps) {
const { name, title, type, placeholder, required, onChange } = props;

return (
<label htmlFor={title}>
Expand All @@ -22,7 +23,7 @@ export default function MoimInput(props: MoimInputProps) {
placeholder={placeholder}
id={title}
onChange={onChange}
></input>
/>
</label>
);
}
8 changes: 0 additions & 8 deletions frontend/src/components/Input/MoimInput.type.ts

This file was deleted.

19 changes: 13 additions & 6 deletions frontend/src/components/MoimCardList/MoimCardList.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import MoimCard from '../Card/MoimCard';
import * as S from './MoimCardList.style';
import MoimCardListProps from './MoimCardList.type';
import * as S from '@_components/MoimCardList/MoimCardList.style';

import MoimCard from '@_components/Card/MoimCard';
import { MoimInfo } from '@_types/index';

interface MoimCardListProps {
moimInfos: MoimInfo[];
}

export default function MoimCardList(props: MoimCardListProps) {
const { data } = props;
const { moimInfos } = props;
return (
<div css={S.cardListSection}>
{data.map((moimInfo, index) => {
return <MoimCard key={`${moimInfo.title}${index}`} data={moimInfo} />;
{moimInfos.map((moimInfo, index) => {
return (
<MoimCard key={`${moimInfo.title}${index}`} moimInfo={moimInfo} />
);
})}
</div>
);
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/components/MoimCardList/MoimCardList.type.ts

This file was deleted.

6 changes: 0 additions & 6 deletions frontend/src/constants/endpoints.ts

This file was deleted.

18 changes: 18 additions & 0 deletions frontend/src/constants/poclies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const POLICES = {
minimumTitleLength: 1,
maximumTitleLength: 20,

minimumPlaceLength: 1,
maximumPlaceLength: 100,

minimumMaxPeople: 1,
maximumMaxPeople: 99,

minimumAuthorNicknameLength: 1,
maximumAuthorNicknameLength: 10,

yyyymmddDashRegex: /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/,
hhmmRegex: /^\d{2}:\d{2}$/,
};

export default POLICES;
File renamed without changes.
6 changes: 6 additions & 0 deletions frontend/src/constants/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const ROUTES = {
main: '/',
addMoim: '/add-moim',
};

export default ROUTES;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';

import QUERY_KEYS from '../queryKeys';
import { postMoim } from '../apis/posts';
import QUERY_KEYS from '@_constants/queryKeys';
import { postMoim } from '@_apis/posts';

export default function useAddMoim(onSuccess: () => void) {
const queryClient = useQueryClient();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import QUERY_KEYS from '../queryKeys';
import { getMoims } from '../apis/gets';
import QUERY_KEYS from '@_constants/queryKeys';
import { getMoims } from '@_apis/gets';
import { useMemo } from 'react';
import { useQuery } from '@tanstack/react-query';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as S from './FormBottomWrapper.style';

import { PropsWithChildren } from 'react';
import * as S from './FormBottomButtonWrapper.style';

export default function FormBottomButtonWrapper(props: PropsWithChildren) {
export default function FormBottomWrapper(props: PropsWithChildren) {
const { children } = props;

return <div css={S.bottomFixedStyle}>{children}</div>;
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/layouts/FormLayout/FormHeader/FormHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ReactNode } from 'react';
import BackArrowLogo from './BackArrowLogo';
import * as S from './FormHeader.style';

import BackLogo from '../../../common/assets/back.svg';
import { ReactNode } from 'react';

interface FormHeaderProps {
onBackArrowClick: () => void;
children: ReactNode;
Expand All @@ -14,7 +15,7 @@ export default function FormHeader(props: FormHeaderProps) {
// TODO: '모임등록하기'가 정가운데에 오지 않음
<header css={S.headerStyle}>
<span onClick={onBackArrowClick}>
<BackArrowLogo />
<BackLogo />
</span>
<span css={S.headerTitleStyle}>{children}</span>
<span></span>
Expand Down
Loading

0 comments on commit 3f18b0b

Please sign in to comment.