-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: serverErrorboundary를 hoc로 refactoring 및 ui 패키지로 이동 (#192)
- Loading branch information
1 parent
cfd0963
commit 856578b
Showing
10 changed files
with
139 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
import { CurrentApplicantCount } from '@dnd-academy/core'; | ||
import { Counter, PageTitle } from '@dnd-academy/ui'; | ||
import { withServerErrorBoundary } from '@dnd-academy/ui/server'; | ||
|
||
import ServerErrorBoundary from '@/components/common/ServerErrorBoundary'; | ||
import CurrentApplicantCountAction from '@/components/CurrentApplicantCountAction'; | ||
|
||
import styles from './page.module.scss'; | ||
|
||
async function page() { | ||
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http'; | ||
type Props = { | ||
data: CurrentApplicantCount; | ||
}; | ||
|
||
async function Page({ data }: Props) { | ||
const { designer, developer } = data; | ||
|
||
return ( | ||
<ServerErrorBoundary<CurrentApplicantCount> apiRequest={{ | ||
url: `${protocol}://${process.env.VERCEL_URL}/api/blob/latest/current_applicant_count`, | ||
}} | ||
> | ||
{({ designer, developer }) => ( | ||
<> | ||
<PageTitle | ||
title="현재 지원자 수" | ||
subTitle="현재 지원자 수는 google form의 spreadsheet를 통해 실시간으로 업데이트 됩니다." | ||
/> | ||
<div className={styles.counter}> | ||
오늘까지 | ||
<Counter count={designer + developer} /> | ||
명이 지원했어요! | ||
</div> | ||
<CurrentApplicantCountAction /> | ||
<strong> | ||
기본적으로 매일 00:00에 자동으로 반영되지만, 클릭시에는 즉시 반영할 수 있습니다. | ||
</strong> | ||
</> | ||
)} | ||
</ServerErrorBoundary> | ||
<> | ||
<PageTitle | ||
title="현재 지원자 수" | ||
subTitle="현재 지원자 수는 google form의 spreadsheet를 통해 실시간으로 업데이트 됩니다." | ||
/> | ||
<div className={styles.counter}> | ||
오늘까지 | ||
<Counter count={designer + developer} /> | ||
명이 지원했어요! | ||
</div> | ||
<CurrentApplicantCountAction /> | ||
<strong> | ||
기본적으로 매일 00:00에 자동으로 반영되지만, 클릭시에는 즉시 반영할 수 있습니다. | ||
</strong> | ||
</> | ||
); | ||
} | ||
|
||
export default page; | ||
export default withServerErrorBoundary(Page, { | ||
url: '/blob/latest/current_applicant_count', | ||
type: 'bff', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
import { type TotalCountStatus } from '@dnd-academy/core'; | ||
import { CounterCard, PageTitle } from '@dnd-academy/ui'; | ||
import { withServerErrorBoundary } from '@dnd-academy/ui/server'; | ||
|
||
import ServerErrorBoundary from '@/components/common/ServerErrorBoundary'; | ||
import TotalCountStatusForm from '@/components/TotalCountStatusForm'; | ||
|
||
import styles from './page.module.scss'; | ||
|
||
async function page() { | ||
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http'; | ||
type Props = { | ||
data: TotalCountStatus; | ||
}; | ||
|
||
async function Page({ data }: Props) { | ||
const { | ||
cumulativeApplicants, dropouts, totalParticipants, totalProjects, | ||
} = data; | ||
|
||
return ( | ||
<ServerErrorBoundary<TotalCountStatus> apiRequest={{ | ||
url: `${protocol}://${process.env.VERCEL_URL}/blob/latest/total_count_status`, | ||
}} | ||
> | ||
{({ | ||
<> | ||
<PageTitle | ||
title="지원자 수 카드 섹션" | ||
subTitle="캐시 적용으로 실제 적용까지는 최대 5분정도 소요됩니다." | ||
/> | ||
<div className={styles.counterCardWrapper}> | ||
<CounterCard count={cumulativeApplicants} title="누적 지원자 수" /> | ||
<CounterCard count={totalParticipants} title="총 참가자 수" /> | ||
<CounterCard count={totalProjects} title="총 프로젝트 수" suffix="개" /> | ||
<CounterCard count={dropouts} title="이탈자 수" color="primary" /> | ||
</div> | ||
<TotalCountStatusForm initialTotalCountStatus={{ | ||
cumulativeApplicants, totalParticipants, totalProjects, dropouts, | ||
}) => ( | ||
<> | ||
<PageTitle | ||
title="지원자 수 카드 섹션" | ||
subTitle="캐시 적용으로 실제 적용까지는 최대 5분정도 소요됩니다." | ||
/> | ||
<div className={styles.counterCardWrapper}> | ||
<CounterCard count={cumulativeApplicants} title="누적 지원자 수" /> | ||
<CounterCard count={totalParticipants} title="총 참가자 수" /> | ||
<CounterCard count={totalProjects} title="총 프로젝트 수" suffix="개" /> | ||
<CounterCard count={dropouts} title="이탈자 수" color="primary" /> | ||
</div> | ||
<TotalCountStatusForm initialTotalCountStatus={{ | ||
cumulativeApplicants, totalParticipants, totalProjects, dropouts, | ||
}} | ||
/> | ||
</> | ||
)} | ||
</ServerErrorBoundary> | ||
}} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default page; | ||
export default withServerErrorBoundary(Page, { | ||
url: '/blob/latest/total_count_status', | ||
type: 'bff', | ||
}); |
45 changes: 0 additions & 45 deletions
45
apps/admin/src/components/common/ServerErrorBoundary/index.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ComponentType, ReactNode } from 'react'; | ||
|
||
import { api, type ApiRequest, serverErrorHandling } from '@dnd-academy/core'; | ||
|
||
function withServerErrorBoundary<T, P extends object | undefined>( | ||
WrappedComponent: ComponentType<P & { data: T }>, | ||
apiRequest: ApiRequest<T>, | ||
) { | ||
return function WithServerErrorBoundary(props: Omit<P, 'data'>): JSX.Element { | ||
const data = serverErrorHandling(() => api(apiRequest)); | ||
|
||
return ( | ||
<> | ||
{/* @ts-expect-error Server Component */} | ||
<AsyncRenderer | ||
data={data} | ||
fallback={<div>Failed to fetch data</div>} | ||
> | ||
{(resolvedData) => ( | ||
<WrappedComponent | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...(props as P)} | ||
data={resolvedData as T} | ||
/> | ||
)} | ||
</AsyncRenderer> | ||
</> | ||
); | ||
}; | ||
} | ||
|
||
async function AsyncRenderer<T>({ | ||
data, | ||
children, | ||
fallback, | ||
}: { | ||
data: Promise<T>; | ||
children: (data: T) => ReactNode; | ||
fallback: ReactNode; | ||
}) { | ||
const resolvedData = await data; | ||
|
||
if (!resolvedData) { | ||
return fallback; | ||
} | ||
|
||
return children(resolvedData); | ||
} | ||
|
||
export default withServerErrorBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as withServerErrorBoundary } from './hoc/withServerErrorBoundary'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters