-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(materials): display custom error page when file is missing in cou…
…rse materials
- Loading branch information
1 parent
80f1e6b
commit f323b9b
Showing
6 changed files
with
131 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { LoaderFunction, redirect } from 'react-router-dom'; | ||
import { getIdFromUnknown } from 'utilities'; | ||
|
||
import CourseAPI from 'api/course'; | ||
|
||
const folderLoader: LoaderFunction = async ({ params }) => { | ||
const folderId = getIdFromUnknown(params?.folderId); | ||
if (!folderId) return redirect('/'); | ||
|
||
const { data } = await CourseAPI.folders.fetch(folderId); | ||
|
||
return data; | ||
}; | ||
|
||
export default folderLoader; |
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
35 changes: 35 additions & 0 deletions
35
client/app/bundles/course/material/folders/pages/BaseRetrievePage.tsx
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,35 @@ | ||
import { ReactNode } from 'react'; | ||
import { Typography } from '@mui/material'; | ||
|
||
import Page from 'lib/components/core/layouts/Page'; | ||
|
||
interface BaseRetrievePageProps { | ||
illustration: ReactNode; | ||
title: string; | ||
description: string; | ||
children?: ReactNode; | ||
} | ||
|
||
const BaseRetrievePage = ( | ||
props: BaseRetrievePageProps, | ||
): JSX.Element => ( | ||
<Page className="h-full m-auto flex flex-col items-center justify-center text-center"> | ||
{props.illustration} | ||
|
||
<Typography className="mt-5" variant="h6"> | ||
{props.title} | ||
</Typography> | ||
|
||
<Typography | ||
className="max-w-3xl mt-2" | ||
color="text.secondary" | ||
variant="body2" | ||
> | ||
{props.description} | ||
</Typography> | ||
|
||
{props.children} | ||
</Page> | ||
); | ||
|
||
export default BaseRetrievePage; |
55 changes: 55 additions & 0 deletions
55
client/app/bundles/course/material/folders/pages/ErrorRetrievingFolderPage.tsx
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,55 @@ | ||
import React from 'react'; | ||
import { defineMessages } from 'react-intl'; | ||
import { useParams } from 'react-router-dom'; | ||
import { Cancel, InsertDriveFileOutlined } from '@mui/icons-material'; | ||
|
||
import Link from 'lib/components/core/Link'; | ||
import useTranslation from 'lib/hooks/useTranslation'; | ||
|
||
import BaseRetrievePage from './BaseRetrievePage'; | ||
|
||
const translations = defineMessages({ | ||
problemRetrievingFolder: { | ||
id: 'course.material.folders.ErrorRetrievingFolderPage.problemRetrievingFolder', | ||
defaultMessage: 'Problem retrieving folder', | ||
}, | ||
problemRetrievingFolderDescription: { | ||
id: 'course.material.folders.ErrorRetrievingFolderPage.problemRetrievingFolderDescription', | ||
defaultMessage: | ||
"Either it no longer exists, you don't have the permission to access it, or something unexpected happened when we were trying to retrieve it.", | ||
}, | ||
goToTheWorkbin: { | ||
id: 'course.material.folders.ErrorRetrievingFolderPage.goToTheWorkbin', | ||
defaultMessage: 'Go to the Workbin', | ||
}, | ||
}); | ||
|
||
const ErrorRetrievingFolderPage = (): JSX.Element => { | ||
const { t } = useTranslation(); | ||
|
||
const params = useParams(); | ||
const workbinURL = `/courses/${params.courseId}`; | ||
|
||
return ( | ||
<BaseRetrievePage | ||
description={t(translations.problemRetrievingFolderDescription)} | ||
illustration={ | ||
<div className="relative"> | ||
<InsertDriveFileOutlined className="text-[6rem]" color="disabled" /> | ||
|
||
<Cancel | ||
className="absolute bottom-0 -right-2 text-[4rem] bg-white rounded-full" | ||
color="error" | ||
/> | ||
</div> | ||
} | ||
title={t(translations.problemRetrievingFolder)} | ||
> | ||
<Link className="mt-10" to={workbinURL}> | ||
{t(translations.goToTheWorkbin)} | ||
</Link> | ||
</BaseRetrievePage> | ||
); | ||
}; | ||
|
||
export default ErrorRetrievingFolderPage; |
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