-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/toast notification errors (#281)
* feat: add error toasts when saving and deleting images/files This commit adds error toast notifications when the api call to save or delete an image or file fails. * feat: add error toasts when saving settings This commit adds error toast notifications when the api call to save a repo's setting config fails. * feat: add error toasts for FolderCard This commit adds error toast notifications when the api call to rename or to delete a folder (collection or resource category) fails * feat: add error toasts for OverviewCard This commit adds error toast notifications when the api call to delete or to move a page (normal page, collection page, or resource page) fails * feat: add error toast notifications to ComponentSettingsModal operations This commit adds error toast notifications when the ComponentSettingsModal tries but fails to retrieve page setting information. It also modifies the component so that an error toast is displayed when the api call to save page settings or to delete the page fails. * feat: add error toast when we fail to retrieve third nav options This commit adds an error toast when we fail to retrieve third nav options in the ComponentSettingsModal * feat: add error toasts for EditPage and EditHomepage This commit adds error toasts when the api calls to save EditHomepage fails, or when the api calls to save or delete the EditPage fails. * fix: undefined exception when handling errors When handling errors in some cases, we attempt to check for a http error response status. However, since the error might not come from a http error, the `status` attribute might not be present in the error object, which leads to an undefined attribute exception. This commit fixes that bug by using optional chaining. * chore: typo * chore: store default error toast message as a constant This commit modifies all applicable existing usage of the Toast component to use the default error toast message that is now defined as a constant in the main utils file. This is so that if we need to reword our error message, we only need to do it in one place, instead of in every single file. Co-authored-by: Jie Hao Kwa <[email protected]>
- Loading branch information
Showing
11 changed files
with
125 additions
and
22 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
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 |
---|---|---|
@@ -1,24 +1,37 @@ | ||
import axios from 'axios'; | ||
import React from 'react'; | ||
import elementStyles from '../styles/isomer-cms/Elements.module.scss'; | ||
import { toast } from 'react-toastify'; | ||
import Toast from '../components/Toast'; | ||
import { DEFAULT_ERROR_TOAST_MSG } from '../utils' | ||
|
||
// axios settings | ||
axios.defaults.withCredentials = true | ||
|
||
export const retrieveThirdNavOptions = async (siteName, collectionName, isExistingCollection) => { | ||
let thirdNavArr = [], allCollectionPages = [] | ||
if (isExistingCollection) { | ||
const endpoint = `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}/collections/${collectionName}/pages` | ||
const { data : { collectionPages } } = await axios.get(endpoint) | ||
thirdNavArr = collectionPages.filter((elem) => elem.type === 'third-nav') | ||
allCollectionPages = collectionPages | ||
} | ||
const thirdNavOptions = [''].concat(thirdNavArr).map((thirdNav) => ( | ||
{ | ||
value:thirdNav.title, | ||
label:thirdNav.title ? thirdNav.title : 'None', | ||
try { | ||
let thirdNavArr = [], allCollectionPages = [] | ||
if (isExistingCollection) { | ||
const endpoint = `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}/collections/${collectionName}/pages` | ||
const { data : { collectionPages } } = await axios.get(endpoint) | ||
thirdNavArr = collectionPages.filter((elem) => elem.type === 'third-nav') | ||
allCollectionPages = collectionPages | ||
} | ||
const thirdNavOptions = [''].concat(thirdNavArr).map((thirdNav) => ( | ||
{ | ||
value:thirdNav.title, | ||
label:thirdNav.title ? thirdNav.title : 'None', | ||
} | ||
)) | ||
return { | ||
collectionPages: allCollectionPages, | ||
thirdNavOptions, | ||
} | ||
)) | ||
return { | ||
collectionPages: allCollectionPages, | ||
thirdNavOptions, | ||
} catch (err) { | ||
toast( | ||
<Toast notificationType='error' text={`There was a problem trying to retrieve data from your repo. ${DEFAULT_ERROR_TOAST_MSG}`}/>, | ||
{className: `${elementStyles.toastError} ${elementStyles.toastLong}`}, | ||
); | ||
console.log(err); | ||
} | ||
} |