Skip to content

Commit

Permalink
Merge pull request #147 from themoment-team/develop
Browse files Browse the repository at this point in the history
Release v1.5.1
  • Loading branch information
frorong committed Apr 25, 2024
2 parents fc249d1 + 6b55099 commit 18cdfcb
Show file tree
Hide file tree
Showing 34 changed files with 483 additions and 120 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"eslint-config-next": "^13.5.2",
"firebase": "^10.3.1",
"next": "^14.0.1",
"next-view-transitions": "^0.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.46.1",
Expand Down
18 changes: 18 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions src/apis/board/getBoardList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';

import { boardUrl } from '@/libs';
import type { BoardInfoType } from '@/types';

export const getBoardList = async (): Promise<BoardInfoType[]> => {
const accessToken = cookies().get('accessToken')?.value;

if (!accessToken) return redirect('/auth/refresh');

const response = await fetch(
new URL(`/api/v1${boardUrl.getBoardList(0)}`, process.env.BASE_URL),
{
method: 'GET',
headers: { Cookie: `accessToken=${accessToken}` },
}
);

if (response.status === 401) {
return redirect('/auth/refresh');
}

if (!response.ok) {
return redirect('/auth/signin');
}

const boardList: BoardInfoType[] = await response.json();

return boardList;
};
1 change: 1 addition & 0 deletions src/apis/board/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './comment';
export * from './getBoardDetail';
export * from './getBoardList';
1 change: 1 addition & 0 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './board';
export * from './mentee';
export * from './mentor';
export * from './teacher';
53 changes: 29 additions & 24 deletions src/apis/mentor/getMyInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,40 @@ import type { MentorInfoType } from '@/types';
* @returns 멘토 정보 반환 시 멘토, null 반환 시 멘티입니다.
*/
export const getMyInfo = async (
redirectUrl: string
redirectUrl: string,
isTeacher: boolean | null
): Promise<MentorInfoType | null> => {
const accessToken = cookies().get('accessToken')?.value;
if (!isTeacher) {
const accessToken = cookies().get('accessToken')?.value;

if (!accessToken) return redirect(`/auth/refresh?redirect=${redirectUrl}`);

const response = await fetch(
new URL(`/api/v1${mentorUrl.getMyInfo()}`, process.env.BASE_URL),
{
method: 'GET',
headers: {
Cookie: `accessToken=${accessToken}`,
},
}
);

if (response.status === 403) {
return null;
}

if (!accessToken) return redirect(`/auth/refresh?redirect=${redirectUrl}`);
if (response.status === 401) {
return redirect(`/auth/refresh?redirect=${redirectUrl}`);
}

const response = await fetch(
new URL(`/api/v1${mentorUrl.getMyInfo()}`, process.env.BASE_URL),
{
method: 'GET',
headers: {
Cookie: `accessToken=${accessToken}`,
},
if (!response.ok) {
return redirect('/auth/signin');
}
);

if (response.status === 403) {
return null;
}
const mentorInfo = await response.json();

if (response.status === 401) {
return redirect(`/auth/refresh?redirect=${redirectUrl}`);
}

if (!response.ok) {
return redirect('/auth/signin');
return mentorInfo;
} else {
return null;
}

const mentorInfo = await response.json();

return mentorInfo;
};
37 changes: 37 additions & 0 deletions src/apis/teacher/getIsTeacher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';

import { userUrl } from '@/libs';

export const getIsTeacher = async (
redirectUrl: string
): Promise<boolean | null> => {
const accessToken = cookies().get('accessToken')?.value;

if (!accessToken) return redirect(`/auth/refresh?redirect=${redirectUrl}`);

const response = await fetch(
new URL(`/api/v1${userUrl.isTeacher()}`, process.env.BASE_URL),
{
method: 'GET',
headers: {
Cookie: `accessToken=${accessToken}`,
},
}
);

if (response.status === 403) {
return null;
}

if (response.status === 401) {
return redirect(`/auth/refresh?redirect=${redirectUrl}`);
}

if (!response.ok) {
return redirect('/auth/signin');
}
const isTeacher = await response.json();

return isTeacher?.isTeacher;
};
1 change: 1 addition & 0 deletions src/apis/teacher/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './getIsTeacher';
36 changes: 5 additions & 31 deletions src/app/community/board/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';

import { boardUrl } from '@/libs';
import { getBoardList } from '@/apis';
import { Board } from '@/pageContainer';
import type { BoardInfoType } from '@/types';

import type { Metadata } from 'next';

export const metadata: Metadata = {
title: '게시판',
description: '게시판 페이지입니다.',
openGraph: {
title: '게시판',
description: '게시판 페이지입니다.',
},
};

const BoardPage = async () => {
Expand All @@ -18,30 +18,4 @@ const BoardPage = async () => {
return <Board initialData={[...boardList]} />;
};

const getBoardList = async (): Promise<BoardInfoType[]> => {
const accessToken = cookies().get('accessToken')?.value;

if (!accessToken) return redirect('/auth/refresh');

const response = await fetch(
new URL(`/api/v1${boardUrl.getBoardList(0)}`, process.env.BASE_URL),
{
method: 'GET',
headers: { Cookie: `accessToken=${accessToken}` },
}
);

if (response.status === 401) {
return redirect('/auth/refresh');
}

if (!response.ok) {
return redirect('/auth/signin');
}

const boardList: BoardInfoType[] = await response.json();

return boardList;
};

export default BoardPage;
21 changes: 21 additions & 0 deletions src/app/community/board/teacher/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getBoardList } from '@/apis';
import { TeacherBoard } from '@/pageContainer';

import type { Metadata } from 'next';

export const metadata: Metadata = {
title: '선생님 게시판',
description: '게시판 페이지입니다.',
openGraph: {
title: '게시판',
description: '게시판 페이지입니다.',
},
};

const TeacherBoardPage = async () => {
const boardList = await getBoardList();

return <TeacherBoard initialData={[...boardList]} />;
};

export default TeacherBoardPage;
9 changes: 8 additions & 1 deletion src/app/mypage/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { redirect } from 'next/navigation';

import { getIsTeacher } from '@/apis';
import { MyInfoPage } from '@/pageContainer';

import type { Metadata } from 'next';
Expand All @@ -6,6 +9,10 @@ export const metadata: Metadata = {
title: '마이페이지',
};

const MyPage = () => <MyInfoPage />;
const MyPage = async () => {
const isTeacher = await getIsTeacher('/');
if (isTeacher) redirect(`/`);
return <MyInfoPage />;
};

export default MyPage;
5 changes: 3 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';

import { getMyInfo, getMyMenteeInfo } from '@/apis';
import { getIsTeacher, getMyInfo, getMyMenteeInfo } from '@/apis';
import { MainPage } from '@/components';
import { mentorUrl } from '@/libs';
import type { WorkerType } from '@/types';
Expand All @@ -11,7 +11,8 @@ import type { Metadata } from 'next';
export default async function Home() {
// TODO: resolve request waterfalls (e.g. Promise.allSettled)
const mentorList = await getMentorList();
const myInfo = await getMyInfo('/');
const isTeacher = await getIsTeacher('/');
const myInfo = await getMyInfo('/', isTeacher);
const myMenteeInfo = await getMyMenteeInfo('/');

return (
Expand Down
7 changes: 6 additions & 1 deletion src/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { usePathname } from 'next/navigation';
import { ThemeProvider } from '@emotion/react';

import { QueryClientProvider } from '@tanstack/react-query';
import { ViewTransitions } from 'next-view-transitions';

import QueryClient from '@/app/queryClient';
import { theme } from '@/styles';
Expand All @@ -30,7 +31,11 @@ const Providers: React.FC<Props> = ({ children }) => {

return (
<ThemeProvider theme={theme}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
<ViewTransitions>
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
</ViewTransitions>
</ThemeProvider>
);
};
Expand Down
28 changes: 28 additions & 0 deletions src/assets/NoticeIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const NoticeIcon = () => (
<svg
width='1.5625rem'
height='1.5625rem'
viewBox='0 0 25 25'
fill='none'
xmlns='http://www.w3.org/2000/svg'
>
<path
d='M3.16699 13.5L8.99662 14L9.89316 20.4817C10.012 21.3412 9.47231 22.1547 8.63422 22.3793C7.81179 22.5997 6.95188 22.1853 6.61173 21.4048L3.16699 13.5Z'
fill='#B4B5B7'
/>
<path
d='M9.66699 6.5C9.66699 6.5 12.167 6.41176 14.667 5.29412C15.5737 4.88878 16.4803 4.40995 17.2677 3.96424C18.3119 3.37318 19.667 4.11204 19.667 5.31193V18.2854C19.667 19.5592 18.1322 20.3121 17.0693 19.6102C16.3765 19.1526 15.5667 18.6498 14.667 18.1471C11.667 16.4706 9.66699 16.5 9.66699 16.5V6.5Z'
fill='#B4B5B7'
/>
<path
d='M2.66699 11.5C2.66699 8.73858 4.90557 6.5 7.66699 6.5H9.66699V16.5H7.66699C4.90557 16.5 2.66699 14.2614 2.66699 11.5Z'
fill='#D8D9DA'
/>
<path
d='M22.667 12C22.667 10.3431 21.3238 9 19.667 9V15C21.3238 15 22.667 13.6569 22.667 12Z'
fill='#D8D9DA'
/>
</svg>
);

export default NoticeIcon;
Loading

0 comments on commit 18cdfcb

Please sign in to comment.