-
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
b1fcfdf
commit c57bf44
Showing
7 changed files
with
126 additions
and
23 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
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
63 changes: 63 additions & 0 deletions
63
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,63 @@ | ||
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 { loadDefaultMaterial } from 'course/material/folders/handles'; | ||
import Link from 'lib/components/core/Link'; | ||
import useTranslation from 'lib/hooks/useTranslation'; | ||
|
||
import BaseRetrievePage from '../../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.", | ||
}, | ||
goToWorkbin: { | ||
id: 'course.material.folders.ErrorRetrievingFolderPage.goToTheWorkbin', | ||
defaultMessage: 'Go to the Workbin', | ||
}, | ||
}); | ||
|
||
const ErrorRetrievingFolderPage = (): JSX.Element => { | ||
const { t } = useTranslation(); | ||
const params = useParams(); | ||
const [workbinURL, setWorkbinURL] = useState(''); | ||
|
||
useEffect(() => { | ||
const courseId = Number(params.courseId); | ||
loadDefaultMaterial(courseId).then((materialsItem) => { | ||
if (materialsItem) { | ||
setWorkbinURL(materialsItem); | ||
} | ||
}); | ||
}, [params.courseId]); | ||
|
||
return ( | ||
<BaseRetrievePage | ||
description={t(translations.problemRetrievingFolderDescription)} | ||
illustration={ | ||
<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> | ||
} | ||
title={t(translations.problemRetrievingFolder)} | ||
> | ||
<Link className="mt-10" to={workbinURL}> | ||
{t(translations.goToWorkbin)} | ||
</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