From 81251de731f2e5fabb2a57e734dfa7391ecb0375 Mon Sep 17 00:00:00 2001 From: SeonghunYang Date: Thu, 2 May 2024 04:44:57 +0000 Subject: [PATCH 1/6] refactor: Add user-action.mock.ts and db.mock.ts files --- app/mocks/actions/user-action.mock.ts | 49 +++++++++++++++++++++++++++ app/mocks/db.mock.ts | 48 +++----------------------- 2 files changed, 53 insertions(+), 44 deletions(-) create mode 100644 app/mocks/actions/user-action.mock.ts diff --git a/app/mocks/actions/user-action.mock.ts b/app/mocks/actions/user-action.mock.ts new file mode 100644 index 00000000..d317b747 --- /dev/null +++ b/app/mocks/actions/user-action.mock.ts @@ -0,0 +1,49 @@ +import { SignInRequestBody, SignUpRequestBody, UserInfoResponse } from '@/app/business/user/user.type'; +import { mockDatabaseStore, MockUser } from '../db.mock'; + +export interface MockUserACtion { + getUser: (authId: string) => MockUser | undefined; + createUser: (user: SignUpRequestBody) => boolean; + signIn: (userData: SignInRequestBody) => boolean; + getUserInfo: (authId: string) => UserInfoResponse; +} + +export const mockUserAction: MockUserACtion = { + getUser: (authId: string) => mockDatabaseStore.users.find((user) => user.authId === authId), + createUser: (user: SignUpRequestBody) => { + if (mockDatabaseStore.users.find((u) => u.authId === user.authId || u.studentNumber === user.studentNumber)) { + return false; + } + mockDatabaseStore.users = [ + ...mockDatabaseStore.users, + { + ...user, + isSumbitted: false, + major: '융소입니다', + name: '모킹이2', + }, + ]; + return true; + }, + signIn: (userData: SignInRequestBody) => { + const user = mockDatabaseStore.users.find((u) => u.authId === userData.authId && u.password === userData.password); + return !!user; + }, + getUserInfo: (authId: string) => { + const user = mockDatabaseStore.users.find((u) => u.authId === authId); + if (!user) { + return { + studentNumber: '', + studentName: '', + major: '', + isSumbitted: false, + }; + } + return { + studentNumber: user.studentNumber, + studentName: user.name, + major: user.major, + isSumbitted: user.isSumbitted, + }; + }, +}; diff --git a/app/mocks/db.mock.ts b/app/mocks/db.mock.ts index 1bbc2871..fa4dfcd3 100644 --- a/app/mocks/db.mock.ts +++ b/app/mocks/db.mock.ts @@ -1,10 +1,10 @@ import { SearchLectures } from '../business/lecture/search-lecture.query'; import { TakenLectures } from '../business/lecture/taken-lecture.query'; import { ResultCategoryDetailInfo } from '../business/result/result.query'; -import { SignUpRequestBody, SignInRequestBody, UserInfoResponse } from '../business/user/user.type'; import { takenLectures, resultCategoryDetailInfo, searchLectures } from './data.mock'; +import { mockUserAction, type MockUserACtion } from './actions/user-action.mock'; -interface MockUser { +export interface MockUser { authId: string; password: string; studentNumber: string; @@ -27,11 +27,7 @@ type MockDatabaseAction = { getResultCategoryDetailInfo: () => ResultCategoryDetailInfo; addTakenLecture: (lectureId: number) => boolean; deleteTakenLecture: (lectureId: number) => boolean; - getUser: (authId: string) => MockUser | undefined; - createUser: (user: SignUpRequestBody) => boolean; - signIn: (userData: SignInRequestBody) => boolean; - getUserInfo: (authId: string) => UserInfoResponse; -}; +} & MockUserACtion; export const mockDatabase: MockDatabaseAction = { getTakenLectures: () => mockDatabaseStore.takenLectures, @@ -60,43 +56,7 @@ export const mockDatabase: MockDatabaseAction = { return true; }, getResultCategoryDetailInfo: () => mockDatabaseStore.resultCategoryDetailInfo, - getUser: (authId: string) => mockDatabaseStore.users.find((user) => user.authId === authId), - createUser: (user: SignUpRequestBody) => { - if (mockDatabaseStore.users.find((u) => u.authId === user.authId || u.studentNumber === user.studentNumber)) { - return false; - } - mockDatabaseStore.users = [ - ...mockDatabaseStore.users, - { - ...user, - isSumbitted: false, - major: '융소입니다', - name: '모킹이2', - }, - ]; - return true; - }, - signIn: (userData: SignInRequestBody) => { - const user = mockDatabaseStore.users.find((u) => u.authId === userData.authId && u.password === userData.password); - return !!user; - }, - getUserInfo: (authId: string) => { - const user = mockDatabaseStore.users.find((u) => u.authId === authId); - if (!user) { - return { - studentNumber: '', - studentName: '', - major: '', - isSumbitted: false, - }; - } - return { - studentNumber: user.studentNumber, - studentName: user.name, - major: user.major, - isSumbitted: user.isSumbitted, - }; - }, + ...mockUserAction, }; const initialState: MockDatabaseState = { From 8eeccf01af91657cc1d7492813960a9f9b8a619c Mon Sep 17 00:00:00 2001 From: SeonghunYang Date: Thu, 2 May 2024 04:46:20 +0000 Subject: [PATCH 2/6] refactor: Refactor mock handlers and rename taken-lecture-handler.mock.ts to lecture-handler.mock.ts --- app/mocks/handlers/index.ts | 4 ++-- ...{taken-lecture-handler.mock.ts => lecture-handler.mock.ts} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename app/mocks/handlers/{taken-lecture-handler.mock.ts => lecture-handler.mock.ts} (97%) diff --git a/app/mocks/handlers/index.ts b/app/mocks/handlers/index.ts index 8b6609df..6b4cf5cb 100644 --- a/app/mocks/handlers/index.ts +++ b/app/mocks/handlers/index.ts @@ -1,5 +1,5 @@ import { resultHandlers } from './result-handler.mock'; -import { takenLectureHandlers } from './taken-lecture-handler.mock'; +import { lectureHandlers } from './lecture-handler.mock'; import { userHandlers } from './user-handler.mock'; -export const handlers = [...userHandlers, ...takenLectureHandlers, ...resultHandlers]; +export const handlers = [...userHandlers, ...lectureHandlers, ...resultHandlers]; diff --git a/app/mocks/handlers/taken-lecture-handler.mock.ts b/app/mocks/handlers/lecture-handler.mock.ts similarity index 97% rename from app/mocks/handlers/taken-lecture-handler.mock.ts rename to app/mocks/handlers/lecture-handler.mock.ts index daf28079..1e352582 100644 --- a/app/mocks/handlers/taken-lecture-handler.mock.ts +++ b/app/mocks/handlers/lecture-handler.mock.ts @@ -3,7 +3,7 @@ import { API_PATH } from '../../business/api-path'; import { mockDatabase } from '../db.mock'; import { parsePDF } from '../data.mock'; -export const takenLectureHandlers = [ +export const lectureHandlers = [ http.get(API_PATH.takenLectures, async () => { const takenLectures = mockDatabase.getTakenLectures(); await delay(1000); From cf1b8a4b7825a867b71370eff098cdd813a8a00a Mon Sep 17 00:00:00 2001 From: SeonghunYang Date: Thu, 2 May 2024 04:49:29 +0000 Subject: [PATCH 3/6] refactor: Add lecture-action.mock.ts and db.mock.ts files --- app/mocks/actions/lecture-action.mock.ts | 38 ++++++++++++++++++++++++ app/mocks/db.mock.ts | 34 +++------------------ 2 files changed, 42 insertions(+), 30 deletions(-) create mode 100644 app/mocks/actions/lecture-action.mock.ts diff --git a/app/mocks/actions/lecture-action.mock.ts b/app/mocks/actions/lecture-action.mock.ts new file mode 100644 index 00000000..20ee3db4 --- /dev/null +++ b/app/mocks/actions/lecture-action.mock.ts @@ -0,0 +1,38 @@ +import { SearchLectures } from '@/app/business/lecture/search-lecture.query'; +import { TakenLectures } from '@/app/business/lecture/taken-lecture.query'; +import { mockDatabaseStore } from '../db.mock'; + +export interface MockLectureAction { + getTakenLectures: () => TakenLectures; + getSearchLectures: () => SearchLectures; + addTakenLecture: (lectureId: number) => boolean; + deleteTakenLecture: (lectureId: number) => boolean; +} + +export const mockLectureAction: MockLectureAction = { + getTakenLectures: () => mockDatabaseStore.takenLectures, + getSearchLectures: () => mockDatabaseStore.searchLectures, + deleteTakenLecture: (lectureId) => { + if (mockDatabaseStore.takenLectures.takenLectures.find((lecture) => lecture.id === lectureId)) { + mockDatabaseStore.takenLectures.takenLectures = mockDatabaseStore.takenLectures.takenLectures.filter( + (lecture) => lecture.id !== lectureId, + ); + return true; + } + return false; + }, + addTakenLecture: (lectureId) => { + mockDatabaseStore.takenLectures.takenLectures = [ + ...mockDatabaseStore.takenLectures.takenLectures, + { + id: lectureId, + year: '2023', + semester: '2학기', + lectureCode: 'HECD140', + lectureName: '추가한과목', + credit: 3, + }, + ]; + return true; + }, +}; diff --git a/app/mocks/db.mock.ts b/app/mocks/db.mock.ts index fa4dfcd3..bd41c90b 100644 --- a/app/mocks/db.mock.ts +++ b/app/mocks/db.mock.ts @@ -3,6 +3,7 @@ import { TakenLectures } from '../business/lecture/taken-lecture.query'; import { ResultCategoryDetailInfo } from '../business/result/result.query'; import { takenLectures, resultCategoryDetailInfo, searchLectures } from './data.mock'; import { mockUserAction, type MockUserACtion } from './actions/user-action.mock'; +import { mockLectureAction, type MockLectureAction } from './actions/lecture-action.mock'; export interface MockUser { authId: string; @@ -22,41 +23,14 @@ interface MockDatabaseState { } type MockDatabaseAction = { - getTakenLectures: () => TakenLectures; - getSearchLectures: () => SearchLectures; getResultCategoryDetailInfo: () => ResultCategoryDetailInfo; - addTakenLecture: (lectureId: number) => boolean; - deleteTakenLecture: (lectureId: number) => boolean; -} & MockUserACtion; +} & MockUserACtion & + MockLectureAction; export const mockDatabase: MockDatabaseAction = { - getTakenLectures: () => mockDatabaseStore.takenLectures, - getSearchLectures: () => mockDatabaseStore.searchLectures, - deleteTakenLecture: (lectureId) => { - if (mockDatabaseStore.takenLectures.takenLectures.find((lecture) => lecture.id === lectureId)) { - mockDatabaseStore.takenLectures.takenLectures = mockDatabaseStore.takenLectures.takenLectures.filter( - (lecture) => lecture.id !== lectureId, - ); - return true; - } - return false; - }, - addTakenLecture: (lectureId) => { - mockDatabaseStore.takenLectures.takenLectures = [ - ...mockDatabaseStore.takenLectures.takenLectures, - { - id: lectureId, - year: '2023', - semester: '2학기', - lectureCode: 'HECD140', - lectureName: '추가한과목', - credit: 3, - }, - ]; - return true; - }, getResultCategoryDetailInfo: () => mockDatabaseStore.resultCategoryDetailInfo, ...mockUserAction, + ...mockLectureAction, }; const initialState: MockDatabaseState = { From c42bac2ecdd44c006291bf3a664d7c69fb5f4652 Mon Sep 17 00:00:00 2001 From: SeonghunYang Date: Thu, 2 May 2024 04:52:45 +0000 Subject: [PATCH 4/6] refactor: Add result-action.mock.ts file --- app/mocks/actions/result-action.mock.ts | 10 ++++++++++ app/mocks/db.mock.ts | 8 +++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 app/mocks/actions/result-action.mock.ts diff --git a/app/mocks/actions/result-action.mock.ts b/app/mocks/actions/result-action.mock.ts new file mode 100644 index 00000000..0f8a7700 --- /dev/null +++ b/app/mocks/actions/result-action.mock.ts @@ -0,0 +1,10 @@ +import { type ResultCategoryDetailInfo } from '../../business/result/result.query'; +import { mockDatabaseStore } from '../db.mock'; + +export interface MockResultAction { + getResultCategoryDetailInfo: () => ResultCategoryDetailInfo; +} + +export const mockResultAction: MockResultAction = { + getResultCategoryDetailInfo: () => mockDatabaseStore.resultCategoryDetailInfo, +}; diff --git a/app/mocks/db.mock.ts b/app/mocks/db.mock.ts index bd41c90b..528e63e7 100644 --- a/app/mocks/db.mock.ts +++ b/app/mocks/db.mock.ts @@ -4,6 +4,7 @@ import { ResultCategoryDetailInfo } from '../business/result/result.query'; import { takenLectures, resultCategoryDetailInfo, searchLectures } from './data.mock'; import { mockUserAction, type MockUserACtion } from './actions/user-action.mock'; import { mockLectureAction, type MockLectureAction } from './actions/lecture-action.mock'; +import { mockResultAction, type MockResultAction } from './actions/result-action.mock'; export interface MockUser { authId: string; @@ -22,15 +23,12 @@ interface MockDatabaseState { searchLectures: SearchLectures; } -type MockDatabaseAction = { - getResultCategoryDetailInfo: () => ResultCategoryDetailInfo; -} & MockUserACtion & - MockLectureAction; +type MockDatabaseAction = MockUserACtion & MockLectureAction & MockResultAction; export const mockDatabase: MockDatabaseAction = { - getResultCategoryDetailInfo: () => mockDatabaseStore.resultCategoryDetailInfo, ...mockUserAction, ...mockLectureAction, + ...mockResultAction, }; const initialState: MockDatabaseState = { From 704107415f9f93a4018e68f0e35419b386cdfa53 Mon Sep 17 00:00:00 2001 From: SeonghunYang Date: Thu, 2 May 2024 05:00:39 +0000 Subject: [PATCH 5/6] refactor: Refactor mock files and add data folder --- app/mocks/actions/lecture-action.mock.ts | 2 +- app/mocks/actions/result-action.mock.ts | 2 +- app/mocks/actions/user-action.mock.ts | 3 +- app/mocks/{ => data}/data.mock.ts | 0 app/mocks/data/index.ts | 48 +++++++++++++++++++ app/mocks/db.mock.ts | 48 ------------------- app/mocks/handlers/lecture-handler.mock.ts | 2 +- .../lecture-search/lecture-search.stories.tsx | 3 +- .../taken-lecture/taken-lecture.stories.tsx | 3 +- .../sign-in-form/sign-in-form.stories.tsx | 3 +- .../sign-up-form/sign-up-form.stories.tsx | 2 +- 11 files changed, 60 insertions(+), 56 deletions(-) rename app/mocks/{ => data}/data.mock.ts (100%) create mode 100644 app/mocks/data/index.ts diff --git a/app/mocks/actions/lecture-action.mock.ts b/app/mocks/actions/lecture-action.mock.ts index 20ee3db4..02c48733 100644 --- a/app/mocks/actions/lecture-action.mock.ts +++ b/app/mocks/actions/lecture-action.mock.ts @@ -1,6 +1,6 @@ import { SearchLectures } from '@/app/business/lecture/search-lecture.query'; import { TakenLectures } from '@/app/business/lecture/taken-lecture.query'; -import { mockDatabaseStore } from '../db.mock'; +import { mockDatabaseStore } from '../data'; export interface MockLectureAction { getTakenLectures: () => TakenLectures; diff --git a/app/mocks/actions/result-action.mock.ts b/app/mocks/actions/result-action.mock.ts index 0f8a7700..0f949e0c 100644 --- a/app/mocks/actions/result-action.mock.ts +++ b/app/mocks/actions/result-action.mock.ts @@ -1,5 +1,5 @@ import { type ResultCategoryDetailInfo } from '../../business/result/result.query'; -import { mockDatabaseStore } from '../db.mock'; +import { mockDatabaseStore } from '../data'; export interface MockResultAction { getResultCategoryDetailInfo: () => ResultCategoryDetailInfo; diff --git a/app/mocks/actions/user-action.mock.ts b/app/mocks/actions/user-action.mock.ts index d317b747..fb057c70 100644 --- a/app/mocks/actions/user-action.mock.ts +++ b/app/mocks/actions/user-action.mock.ts @@ -1,5 +1,6 @@ import { SignInRequestBody, SignUpRequestBody, UserInfoResponse } from '@/app/business/user/user.type'; -import { mockDatabaseStore, MockUser } from '../db.mock'; +import { MockUser } from '../data'; +import { mockDatabaseStore } from '../data'; export interface MockUserACtion { getUser: (authId: string) => MockUser | undefined; diff --git a/app/mocks/data.mock.ts b/app/mocks/data/data.mock.ts similarity index 100% rename from app/mocks/data.mock.ts rename to app/mocks/data/data.mock.ts diff --git a/app/mocks/data/index.ts b/app/mocks/data/index.ts new file mode 100644 index 00000000..914b85d5 --- /dev/null +++ b/app/mocks/data/index.ts @@ -0,0 +1,48 @@ +import { takenLectures, resultCategoryDetailInfo, searchLectures } from './data.mock'; +import { SearchLectures } from '@/app/business/lecture/search-lecture.query'; +import { TakenLectures } from '@/app/business/lecture/taken-lecture.query'; +import { ResultCategoryDetailInfo } from '@/app/business/result/result.query'; + +export interface MockUser { + authId: string; + password: string; + studentNumber: string; + engLv: string; + major: string; + isSumbitted: boolean; + name: string; +} + +interface MockDatabaseState { + takenLectures: TakenLectures; + resultCategoryDetailInfo: ResultCategoryDetailInfo; + users: MockUser[]; + searchLectures: SearchLectures; +} + +const initialState: MockDatabaseState = { + takenLectures: takenLectures, + resultCategoryDetailInfo: resultCategoryDetailInfo, + users: [ + { + authId: 'admin', + password: 'admin', + studentNumber: '60000000', + engLv: 'ENG12', + isSumbitted: false, + major: '융소입니다', + name: '모킹이', + }, + ], + searchLectures: searchLectures, +}; + +function initStore(): MockDatabaseState { + return JSON.parse(JSON.stringify(initialState)); +} + +export let mockDatabaseStore = initStore(); + +export const resetMockDB = () => { + mockDatabaseStore = initStore(); +}; diff --git a/app/mocks/db.mock.ts b/app/mocks/db.mock.ts index 528e63e7..66a18116 100644 --- a/app/mocks/db.mock.ts +++ b/app/mocks/db.mock.ts @@ -1,28 +1,7 @@ -import { SearchLectures } from '../business/lecture/search-lecture.query'; -import { TakenLectures } from '../business/lecture/taken-lecture.query'; -import { ResultCategoryDetailInfo } from '../business/result/result.query'; -import { takenLectures, resultCategoryDetailInfo, searchLectures } from './data.mock'; import { mockUserAction, type MockUserACtion } from './actions/user-action.mock'; import { mockLectureAction, type MockLectureAction } from './actions/lecture-action.mock'; import { mockResultAction, type MockResultAction } from './actions/result-action.mock'; -export interface MockUser { - authId: string; - password: string; - studentNumber: string; - engLv: string; - major: string; - isSumbitted: boolean; - name: string; -} - -interface MockDatabaseState { - takenLectures: TakenLectures; - resultCategoryDetailInfo: ResultCategoryDetailInfo; - users: MockUser[]; - searchLectures: SearchLectures; -} - type MockDatabaseAction = MockUserACtion & MockLectureAction & MockResultAction; export const mockDatabase: MockDatabaseAction = { @@ -30,30 +9,3 @@ export const mockDatabase: MockDatabaseAction = { ...mockLectureAction, ...mockResultAction, }; - -const initialState: MockDatabaseState = { - takenLectures: takenLectures, - resultCategoryDetailInfo: resultCategoryDetailInfo, - users: [ - { - authId: 'admin', - password: 'admin', - studentNumber: '60000000', - engLv: 'ENG12', - isSumbitted: false, - major: '융소입니다', - name: '모킹이', - }, - ], - searchLectures: searchLectures, -}; - -function initStore(): MockDatabaseState { - return JSON.parse(JSON.stringify(initialState)); -} - -export let mockDatabaseStore = initStore(); - -export const resetMockDB = () => { - mockDatabaseStore = initStore(); -}; diff --git a/app/mocks/handlers/lecture-handler.mock.ts b/app/mocks/handlers/lecture-handler.mock.ts index 1e352582..62bca8ad 100644 --- a/app/mocks/handlers/lecture-handler.mock.ts +++ b/app/mocks/handlers/lecture-handler.mock.ts @@ -1,7 +1,7 @@ import { HttpResponse, http, delay } from 'msw'; import { API_PATH } from '../../business/api-path'; import { mockDatabase } from '../db.mock'; -import { parsePDF } from '../data.mock'; +import { parsePDF } from '../data/data.mock'; export const lectureHandlers = [ http.get(API_PATH.takenLectures, async () => { diff --git a/app/ui/lecture/lecture-search/lecture-search.stories.tsx b/app/ui/lecture/lecture-search/lecture-search.stories.tsx index 7c9cb090..25d1969b 100644 --- a/app/ui/lecture/lecture-search/lecture-search.stories.tsx +++ b/app/ui/lecture/lecture-search/lecture-search.stories.tsx @@ -1,6 +1,7 @@ import type { Meta, StoryObj } from '@storybook/react'; import { expect, userEvent } from '@storybook/test'; -import { mockDatabase, resetMockDB } from '@/app/mocks/db.mock'; +import { mockDatabase } from '@/app/mocks/db.mock'; +import { resetMockDB } from '@/app/mocks/data'; import TakenLectureAtomHydrator from '@/app/store/taken-lecture-atom-hydrator'; import { screen } from '@storybook/testing-library'; import TakenLectureLabel from '../taken-lecture/taken-lecture-label'; diff --git a/app/ui/lecture/taken-lecture/taken-lecture.stories.tsx b/app/ui/lecture/taken-lecture/taken-lecture.stories.tsx index ff01e281..66b9f055 100644 --- a/app/ui/lecture/taken-lecture/taken-lecture.stories.tsx +++ b/app/ui/lecture/taken-lecture/taken-lecture.stories.tsx @@ -1,6 +1,7 @@ import type { Meta, StoryObj } from '@storybook/react'; import { expect, userEvent } from '@storybook/test'; -import { mockDatabase, resetMockDB } from '@/app/mocks/db.mock'; +import { mockDatabase } from '@/app/mocks/db.mock'; +import { resetMockDB } from '@/app/mocks/data'; import TakenLectureList from './taken-lecture-list'; import TakenLectureAtomHydrator from '@/app/store/taken-lecture-atom-hydrator'; import { screen } from '@storybook/testing-library'; diff --git a/app/ui/user/sign-in-form/sign-in-form.stories.tsx b/app/ui/user/sign-in-form/sign-in-form.stories.tsx index ad96043a..1719f9b9 100644 --- a/app/ui/user/sign-in-form/sign-in-form.stories.tsx +++ b/app/ui/user/sign-in-form/sign-in-form.stories.tsx @@ -3,7 +3,8 @@ import type { Meta, StoryObj } from '@storybook/react'; import SignInForm from './sign-in-form'; import { userEvent, within, expect, fn, waitFor } from '@storybook/test'; -import { resetMockDB, mockDatabase } from '@/app/mocks/db.mock'; +import { mockDatabase } from '@/app/mocks/db.mock'; +import { resetMockDB } from '@/app/mocks/data'; const meta = { title: 'ui/user/SignInForm', diff --git a/app/ui/user/sign-up-form/sign-up-form.stories.tsx b/app/ui/user/sign-up-form/sign-up-form.stories.tsx index 8b48d133..3683160a 100644 --- a/app/ui/user/sign-up-form/sign-up-form.stories.tsx +++ b/app/ui/user/sign-up-form/sign-up-form.stories.tsx @@ -3,7 +3,7 @@ import type { Meta, StoryObj } from '@storybook/react'; import SignUpForm from './sign-up-form'; import { userEvent, within, expect, fn, waitFor } from '@storybook/test'; -import { resetMockDB } from '@/app/mocks/db.mock'; +import { resetMockDB } from '@/app/mocks/data'; const meta = { title: 'ui/user/SignUpForm', From adecc5307c4647d2b6187dfdeee9725a08505410 Mon Sep 17 00:00:00 2001 From: SeonghunYang Date: Thu, 2 May 2024 05:18:25 +0000 Subject: [PATCH 6/6] refactor: Refactor dashboard components and remove unused files --- app/__test__/page.test.tsx | 12 ---- app/business/invoice/revenue.command.ts | 4 -- app/business/invoice/revenue.query.ts | 21 ------- .../components/dashboard-nav-links.tsx | 29 ---------- app/dashboard/components/side-nav.tsx | 27 --------- app/dashboard/invoices/page.tsx | 3 - app/dashboard/layout.tsx | 12 ---- app/dashboard/loading.tsx | 3 - app/dashboard/page.tsx | 8 --- app/page.tsx | 4 +- app/ui/invoice/revenu-chart.tsx | 57 ------------------- 11 files changed, 2 insertions(+), 178 deletions(-) delete mode 100644 app/__test__/page.test.tsx delete mode 100644 app/business/invoice/revenue.command.ts delete mode 100644 app/business/invoice/revenue.query.ts delete mode 100644 app/dashboard/components/dashboard-nav-links.tsx delete mode 100644 app/dashboard/components/side-nav.tsx delete mode 100644 app/dashboard/invoices/page.tsx delete mode 100644 app/dashboard/layout.tsx delete mode 100644 app/dashboard/loading.tsx delete mode 100644 app/dashboard/page.tsx delete mode 100644 app/ui/invoice/revenu-chart.tsx diff --git a/app/__test__/page.test.tsx b/app/__test__/page.test.tsx deleted file mode 100644 index 28d1e747..00000000 --- a/app/__test__/page.test.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import '@testing-library/jest-dom'; -import { findByText, render, screen } from '@testing-library/react'; -import Home from '../page'; - -// test sample: RSC가 아닌 컴포넌트 테스트할 때 -describe('Home', () => { - it('Home을 렌더링한다.', async () => { - render(); - - expect(await screen.findByText(/dashboard/i)).toBeInTheDocument(); - }); -}); diff --git a/app/business/invoice/revenue.command.ts b/app/business/invoice/revenue.command.ts deleted file mode 100644 index f1a133c8..00000000 --- a/app/business/invoice/revenue.command.ts +++ /dev/null @@ -1,4 +0,0 @@ -// server action을 사용해 데이터를 mutation 하는 부분 -// https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations -// sample code는 못작성했음 revenue data에 관한 mutation 로직은 여기서 작성 -'use server'; diff --git a/app/business/invoice/revenue.query.ts b/app/business/invoice/revenue.query.ts deleted file mode 100644 index 0f09f1fc..00000000 --- a/app/business/invoice/revenue.query.ts +++ /dev/null @@ -1,21 +0,0 @@ -// RSC를 위한 data fetch 함수 작성 -// 이 sample 코드는 invoice 도메인에 revenue 도메인 객체(애그리게이트) 쉽게 말하면 걍 데이터를 fetch하는 함수들을 작성 - -import { API_PATH } from '../api-path'; - -export type Revenue = { - month: string; - revenue: number; -}; - -export const fetchRevenue = async (): Promise => { - const res = await fetch(API_PATH.revenue, { cache: 'no-store' }); - - if (!res.ok) { - throw new Error('Failed to fetch revenue data.'); - } - - const data = await res.json(); - - return data; -}; diff --git a/app/dashboard/components/dashboard-nav-links.tsx b/app/dashboard/components/dashboard-nav-links.tsx deleted file mode 100644 index c8847a5a..00000000 --- a/app/dashboard/components/dashboard-nav-links.tsx +++ /dev/null @@ -1,29 +0,0 @@ -'use client'; -import { UserGroupIcon, HomeIcon, DocumentDuplicateIcon } from '@heroicons/react/24/outline'; -import NavLink from '@/app/ui/view/atom/nav-link'; -import { usePathname } from 'next/navigation'; - -const links = [ - { name: 'Home', href: '/dashboard', icon: HomeIcon }, - { - name: 'Invoices', - href: '/dashboard/invoices', - icon: DocumentDuplicateIcon, - }, - { name: 'Customers', href: '/dashboard/customers', icon: UserGroupIcon }, -]; - -export default function DashboardNavLinks() { - const pathname = usePathname(); - return ( - <> - {links.map((link) => { - return ( - - {link.name} - - ); - })} - - ); -} diff --git a/app/dashboard/components/side-nav.tsx b/app/dashboard/components/side-nav.tsx deleted file mode 100644 index c11b5117..00000000 --- a/app/dashboard/components/side-nav.tsx +++ /dev/null @@ -1,27 +0,0 @@ -// page에 종속되는 component 작성 -// 일단 아래 방식대로 나눠봤는데 생각보다 헷갈리네, 일단 써보고 불편하면 변경할 예정 -// https://nextjs.org/docs/app/building-your-application/routing/colocation#split-project-files-by-feature-or-route - -import Link from 'next/link'; -import DashboardNavLinks from './dashboard-nav-links'; -import { PowerIcon } from '@heroicons/react/24/outline'; - -export default function SideNav() { - return ( -
- -
- -
- -
-
- -
-
-
- ); -} diff --git a/app/dashboard/invoices/page.tsx b/app/dashboard/invoices/page.tsx deleted file mode 100644 index 0e12bf0c..00000000 --- a/app/dashboard/invoices/page.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export default function Page() { - return

invoices Page

; -} diff --git a/app/dashboard/layout.tsx b/app/dashboard/layout.tsx deleted file mode 100644 index 4b8ae685..00000000 --- a/app/dashboard/layout.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import SideNav from './components/side-nav'; - -export default function Layout({ children }: { children: React.ReactNode }) { - return ( -
-
- -
-
{children}
-
- ); -} diff --git a/app/dashboard/loading.tsx b/app/dashboard/loading.tsx deleted file mode 100644 index 194d366b..00000000 --- a/app/dashboard/loading.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export default function Loading() { - return
...loading
; -} diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx deleted file mode 100644 index 101e3f71..00000000 --- a/app/dashboard/page.tsx +++ /dev/null @@ -1,8 +0,0 @@ -export default async function Page() { - return ( -
-

Dashboard

-
-
- ); -} diff --git a/app/page.tsx b/app/page.tsx index 2bf91196..afd1ce5a 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -4,10 +4,10 @@ export default function Home() { return (
- dashboard + my
); diff --git a/app/ui/invoice/revenu-chart.tsx b/app/ui/invoice/revenu-chart.tsx deleted file mode 100644 index 2cac2707..00000000 --- a/app/ui/invoice/revenu-chart.tsx +++ /dev/null @@ -1,57 +0,0 @@ -// RSC sample code -// domain component sample code: invoice domain의 sample 코드 -import { generateYAxis } from '@/app/utils/chart.util'; -import { CalendarIcon } from '@heroicons/react/24/outline'; -import { fetchRevenue } from '@/app/business/invoice/revenue.query'; - -export default async function RevenueChart() { - const revenue = await fetchRevenue(); // Fetch data inside the component - const chartHeight = 350; - - const { yAxisLabels, topLabel } = generateYAxis(revenue); - - if (!revenue || revenue.length === 0) { - return

No data available.

; - } - - return ( -
-

Recent Revenue

- {/* NOTE: comment in this code when you get to this point in the course */} - -
-
-
- {yAxisLabels.map((label) => ( -

{label}

- ))} -
- - {revenue - .map((month) => ( -
-
-

- {month.month} - {month.revenue} -

-
- )) - .slice(0, 11)} -
-
- -

Last 12 months

-
-
-
- ); -}