-
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 or folder is miss…
…ing in course materials
- Loading branch information
1 parent
fe47f4d
commit 23414e8
Showing
14 changed files
with
179 additions
and
39 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
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,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
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
72 changes: 72 additions & 0 deletions
72
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,72 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { defineMessages } from 'react-intl'; | ||
import { useParams } from 'react-router-dom'; | ||
import { Cancel, FolderOutlined } from '@mui/icons-material'; | ||
|
||
import { loadDefaultMaterialId } from 'course/material/folders/handles'; | ||
import Link from 'lib/components/core/Link'; | ||
import useTranslation from 'lib/hooks/useTranslation'; | ||
|
||
import BaseRetrieveMaterialPage from '../../component/BaseRetrieveMaterialPage'; | ||
|
||
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 Illustration = (): JSX.Element => ( | ||
<div className="relative"> | ||
<FolderOutlined className="text-[6rem]" color="disabled" /> | ||
<Cancel | ||
className="absolute bottom-0 -right-2 text-[4rem] bg-white rounded-full" | ||
color="error" | ||
/> | ||
</div> | ||
); | ||
|
||
const useWorkbinURL = (courseId: string | undefined): string => { | ||
const [workbinURL, setWorkbinURL] = useState(`/courses/${courseId}`); | ||
|
||
useEffect(() => { | ||
if (courseId) { | ||
loadDefaultMaterialId().then((defaultMaterialId) => { | ||
setWorkbinURL( | ||
`/courses/${courseId}/materials/folders/${defaultMaterialId}`, | ||
); | ||
}); | ||
} | ||
}, [courseId]); | ||
|
||
return workbinURL; | ||
}; | ||
|
||
const ErrorRetrievingFolderPage = (): JSX.Element => { | ||
const { t } = useTranslation(); | ||
const params = useParams(); | ||
const workbinURL = useWorkbinURL(params.courseId); | ||
|
||
return ( | ||
<BaseRetrieveMaterialPage | ||
description={t(translations.problemRetrievingFolderDescription)} | ||
illustration={<Illustration />} | ||
title={t(translations.problemRetrievingFolder)} | ||
> | ||
<Link className="mt-10" to={workbinURL}> | ||
{t(translations.goToTheWorkbin)} | ||
</Link> | ||
</BaseRetrieveMaterialPage> | ||
); | ||
}; | ||
|
||
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
Oops, something went wrong.