diff --git a/components/header.js b/components/header.js index a355acc5..48c07293 100644 --- a/components/header.js +++ b/components/header.js @@ -1,12 +1,14 @@ import Link from "next/link"; import { useRouter } from "next/router"; import useTranslation from "next-translate/useTranslation"; - -export default function Header({ courseName }) { +import { useDispatch, useSelector, shallowEqual, connect } from "react-redux"; +import { setLogout } from "../store/accountDetails/action"; +const Header = (props) => { let { t, lang } = useTranslation(); const router = useRouter(); const { locale } = router; + const { setLogout } = props; return (
- + { - window.localStorage.clear(); - }} className="govuk-header__link govuk-header__link--service-name" > @@ -98,13 +97,8 @@ export default function Header({ courseName }) {
{router.pathname != "/" ? ( - - { - window.localStorage.clear(); - }} - className="govuk-header__link govuk-!-margin-right-3" - > + + {t("common:signout-label")} @@ -200,4 +189,13 @@ export default function Header({ courseName }) {
); -} +}; +const mapDispatchToProps = (dispatch) => { + return { + setLogout: () => { + dispatch(setLogout()); + }, + }; +}; + +export default connect(null, mapDispatchToProps)(Header); diff --git a/pages/404.js b/pages/404.js new file mode 100644 index 00000000..8ba64663 --- /dev/null +++ b/pages/404.js @@ -0,0 +1,13 @@ +// 404.js +import Link from "next/link"; + +export default function FourOhFour() { + return ( + <> +

404 - Page Not Found

+ + Go back home + + + ); +} diff --git a/pages/logout.js b/pages/logout.js new file mode 100644 index 00000000..21fd1d78 --- /dev/null +++ b/pages/logout.js @@ -0,0 +1,50 @@ +import _ from "lodash"; +import Link from "next/link"; +import Head from "next/head"; +import Header from "../components/header"; +import Banner from "../components/banner"; +import CookieBanner from "../components/cookieBanner"; + +import Footer from "../components/footer"; +import { useSelector, shallowEqual, connect } from "react-redux"; +import { useRouter } from "next/router"; +import useTranslation from "next-translate/useTranslation"; +import { setLogout } from "../store/accountDetails/action"; + +const LogOut = (props) => { + const { footerLinks, pages, setLogout } = props; + let { t, lang } = useTranslation(); + + const router = useRouter(); + const { locale } = router; + setLogout(); + return ( +
+ + {t("common:service-name")} + +
+ +
+
+ +

You have been logged out

+
+ Return to Planning Casework portal +
+
+
+
+ ); +}; + +const mapDispatchToProps = (dispatch) => { + return { + setLogout: () => { + dispatch(setLogout()); + }, + }; +}; + +export default connect(null, mapDispatchToProps)(LogOut); diff --git a/store/accountDetails/action.js b/store/accountDetails/action.js index f106d058..efc3a7f2 100644 --- a/store/accountDetails/action.js +++ b/store/accountDetails/action.js @@ -15,3 +15,9 @@ export const setAccountDetails = (accountDetails) => (dispatch) => { accountDetails: accountDetails, }); }; + +export const setLogout = () => (dispatch) => { + return dispatch({ + type: "USER_LOGOUT", + }); +}; diff --git a/store/store.js b/store/store.js index 83769736..89fcc1b5 100644 --- a/store/store.js +++ b/store/store.js @@ -9,9 +9,10 @@ import LPAData from "./lpa/reducer"; import accountDetails from "./accountDetails/reducer"; import { reducer as formReducer } from "redux-form"; import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2"; +import storage from "redux-persist/lib/storage"; //COMBINING ALL REDUCERS -const combinedReducer = combineReducers({ +const appReducer = combineReducers({ search, searchResultsObj, formData, @@ -21,6 +22,16 @@ const combinedReducer = combineReducers({ form: formReducer, }); +const combinedReducer = (state, action) => { + if (action.type === "USER_LOGOUT") { + // for all keys defined in your persistConfig(s) + storage.removeItem("persist:acp"); + // storage.removeItem('persist:otherKey') + return appReducer(undefined, action); + } + return appReducer(state, action); +}; + const reducer = (state = {}, action) => { switch (action.type) { case HYDRATE: @@ -77,7 +88,7 @@ const makeStore = ({ isServer }) => { const storage = require("redux-persist/lib/storage").default; const persistConfig = { - key: "nextjs", + key: "acp", whitelist: [ "search", "searchResults", @@ -87,7 +98,7 @@ const makeStore = ({ isServer }) => { "accountDetails", "form", ], - storage, + storage: storage, stateReconciler: autoMergeLevel2, // if needed, use a safer storage };