Skip to content

Commit

Permalink
added error handling for when SAM wizard has not yet run.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Jun 22, 2024
1 parent 7f00c72 commit b579070
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
20 changes: 19 additions & 1 deletion src/components/layout/AppHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import { AppHeaderSearch } from 'src/components/header'
import { CippActionsOffcanvas, TenantSelector } from '../utilities'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faBars } from '@fortawesome/free-solid-svg-icons'
import { setCurrentTheme, setUserSettings, toggleSidebarShow } from 'src/store/features/app'
import {
setCurrentTheme,
setSetupCompleted,
setUserSettings,
toggleSidebarShow,
} from 'src/store/features/app'
import { useMediaPredicate } from 'react-media-hook'
import {
useGenericGetRequestQuery,
Expand Down Expand Up @@ -92,6 +97,19 @@ const AppHeader = () => {
}
}, [delay, state])
}
//useEffect to check if any of the dashboard alerts contained the key "setupCompleted" and if so,
//check if the value of this key is false. If so, set the setupCompleted state to false
//if none is found, set the setupCompleted state to true
useEffect(() => {
if (dashboard && dashboard.length >= 1) {
const setupCompleted = dashboard.find((alert) => alert.setupCompleted === false)
if (setupCompleted) {
dispatch(setSetupCompleted({ setupCompleted: false }))
} else {
dispatch(setSetupCompleted({ setupCompleted: true }))
}
}
}, [dashboard, dispatch])

useEffect(() => {
if (cippQueueList.isUninitialized && (cippQueueList.isFetching || cippQueueList.isLoading)) {
Expand Down
5 changes: 5 additions & 0 deletions src/store/features/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const initialState = {
defaultColumns: {},
newUserDefaults: {},
recentPages: [],
setupCompleted: false,
}

export const appSlice = createSlice({
Expand Down Expand Up @@ -62,6 +63,9 @@ export const appSlice = createSlice({
setRecentPages: (state, action) => {
state.recentPages = action.payload?.recentPages
},
setSetupCompleted: (state, action) => {
state.setupCompleted = action.payload?.setupCompleted
},
},
})

Expand All @@ -80,6 +84,7 @@ export const {
setDefaultColumns,
setNewUserDefaults,
setRecentPages,
setSetupCompleted,
} = appSlice.actions

export default persistReducer(
Expand Down
8 changes: 6 additions & 2 deletions src/store/middleware/errorMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
// set action.hideToastError to `true` to ignore this middleware
import { showToast } from 'src/store/features/toasts'
import { isRejectedWithValue } from '@reduxjs/toolkit'
import { store } from '../store'

export const errorMiddleware =
({ dispatch }) =>
(next) =>
(action) => {
const { getState } = store
const state = getState()
const setupCompleted = state.app?.setupCompleted
if (
isRejectedWithValue(action) &&
!action.error?.hideToastError &&
action.payload.message !== 'canceled'
action.payload.message !== 'canceled' &&
setupCompleted
) {
console.error(action)
if (action.payload.data === 'Backend call failure') {
action.payload.data =
'The Azure Function has taken too long to respond. Try selecting a different report or a single tenant instead'
Expand Down

0 comments on commit b579070

Please sign in to comment.