Skip to content

Commit

Permalink
reset app errors on page refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamez committed Oct 12, 2023
1 parent 8ebce84 commit 678616e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
3 changes: 3 additions & 0 deletions web-app/src/app/components/AppSpinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import LoadingOverlay from 'react-loading-overlay-ts';
import { useSelector } from 'react-redux';
import { selectLoadingApp } from '../store/selectors';

/**
* This adds a spinner to the entire application
*/
const AppSpinner: React.FC<ContextProviderProps> = ({ children }) => {
const isActive = useSelector(selectLoadingApp);
return (
Expand Down
28 changes: 24 additions & 4 deletions web-app/src/app/components/Context.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
import React from 'react';
import React, { useEffect } from 'react';
import type ContextProviderProps from '../interface/ContextProviderProps';
import { Provider } from 'react-redux';
import { store } from '../store/store';
import { PersistGate } from 'redux-persist/integration/react';
import { persistStore } from 'redux-persist';
import { useAppDispatch } from '../hooks';
import { resetProfileErrors } from '../store/profile-reducer';

const persistor = persistStore(store);
/**
* This component is used to wrap the entire application
*/
const AppContent: React.FC<ContextProviderProps> = ({ children }) => {
const dispatch = useAppDispatch();

useEffect(() => {
// This function will run when the component is first loaded
// Clean errros from previous session
dispatch(resetProfileErrors());
}, []);
return (
<PersistGate loading={null} persistor={persistor}>
{children}
</PersistGate>
);
};

/**
* This component is used to wrap the entire application adding the store provider and reseting the errors from previous session
*/
const ContextProviders: React.FC<ContextProviderProps> = ({ children }) => {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
{children}
</PersistGate>
<AppContent>{children}</AppContent>
</Provider>
);
};
Expand Down
4 changes: 4 additions & 0 deletions web-app/src/app/store/profile-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ export const userProfileSlice = createSlice({
state.user.organization = action.payload;
}
},
resetProfileErrors: (state) => {
state.errors = { ...initialState.errors };
},
},
});

Expand All @@ -106,6 +109,7 @@ export const {
signUp,
signUpSuccess,
signUpFail,
resetProfileErrors,
} = userProfileSlice.actions;

export default userProfileSlice.reducer;

0 comments on commit 678616e

Please sign in to comment.