added logout functions to clear store
This commit is contained in:
+19
-21
@@ -1,12 +1,14 @@
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import useTranslation from "next-translate/useTranslation";
|
import useTranslation from "next-translate/useTranslation";
|
||||||
|
import { useDispatch, useSelector, shallowEqual, connect } from "react-redux";
|
||||||
export default function Header({ courseName }) {
|
import { setLogout } from "../store/accountDetails/action";
|
||||||
|
const Header = (props) => {
|
||||||
let { t, lang } = useTranslation();
|
let { t, lang } = useTranslation();
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { locale } = router;
|
const { locale } = router;
|
||||||
|
const { setLogout } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header
|
<header
|
||||||
@@ -61,11 +63,8 @@ export default function Header({ courseName }) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="govuk-header__content govuk-!-width-one-half govuk-!-margin-top-3">
|
<div className="govuk-header__content govuk-!-width-one-half govuk-!-margin-top-3">
|
||||||
<Link href="/">
|
<Link href="/logout">
|
||||||
<a
|
<a
|
||||||
onClick={() => {
|
|
||||||
window.localStorage.clear();
|
|
||||||
}}
|
|
||||||
className="govuk-header__link
|
className="govuk-header__link
|
||||||
govuk-header__link--service-name"
|
govuk-header__link--service-name"
|
||||||
>
|
>
|
||||||
@@ -98,13 +97,8 @@ export default function Header({ courseName }) {
|
|||||||
<ul>
|
<ul>
|
||||||
{router.pathname != "/" ? (
|
{router.pathname != "/" ? (
|
||||||
<li>
|
<li>
|
||||||
<Link href="/">
|
<Link href="/logout">
|
||||||
<a
|
<a className="govuk-header__link ">
|
||||||
onClick={() => {
|
|
||||||
window.localStorage.clear();
|
|
||||||
}}
|
|
||||||
className="govuk-header__link "
|
|
||||||
>
|
|
||||||
{t("common:signout-label")}
|
{t("common:signout-label")}
|
||||||
</a>
|
</a>
|
||||||
</Link>
|
</Link>
|
||||||
@@ -154,13 +148,8 @@ export default function Header({ courseName }) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="fullNav">
|
<div className="fullNav">
|
||||||
{router.pathname != "/" ? (
|
{router.pathname != "/" ? (
|
||||||
<Link href="/">
|
<Link href="/logout">
|
||||||
<a
|
<a className="govuk-header__link govuk-!-margin-right-3">
|
||||||
onClick={() => {
|
|
||||||
window.localStorage.clear();
|
|
||||||
}}
|
|
||||||
className="govuk-header__link govuk-!-margin-right-3"
|
|
||||||
>
|
|
||||||
{t("common:signout-label")}
|
{t("common:signout-label")}
|
||||||
</a>
|
</a>
|
||||||
</Link>
|
</Link>
|
||||||
@@ -200,4 +189,13 @@ export default function Header({ courseName }) {
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
const mapDispatchToProps = (dispatch) => {
|
||||||
|
return {
|
||||||
|
setLogout: () => {
|
||||||
|
dispatch(setLogout());
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(null, mapDispatchToProps)(Header);
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// 404.js
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
export default function FourOhFour() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h1>404 - Page Not Found</h1>
|
||||||
|
<Link href="/">
|
||||||
|
<a>Go back home</a>
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -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 (
|
||||||
|
<div>
|
||||||
|
<Head>
|
||||||
|
<title>{t("common:service-name")}</title>
|
||||||
|
</Head>
|
||||||
|
<div id="page_wrapper">
|
||||||
|
<CookieBanner />
|
||||||
|
<Header courseName="Appeals Casework Portal" />
|
||||||
|
<div className="govuk-width-container">
|
||||||
|
<Banner />
|
||||||
|
<h2>You have been logged out</h2>
|
||||||
|
<div className="govuk-!-margin-top-9 govuk-!-margin-bottom-9">
|
||||||
|
<Link href="/">Return to Planning Casework portal</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Footer footerLinks={footerLinks} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => {
|
||||||
|
return {
|
||||||
|
setLogout: () => {
|
||||||
|
dispatch(setLogout());
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(null, mapDispatchToProps)(LogOut);
|
||||||
@@ -15,3 +15,9 @@ export const setAccountDetails = (accountDetails) => (dispatch) => {
|
|||||||
accountDetails: accountDetails,
|
accountDetails: accountDetails,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const setLogout = () => (dispatch) => {
|
||||||
|
return dispatch({
|
||||||
|
type: "USER_LOGOUT",
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
+14
-3
@@ -9,9 +9,10 @@ import LPAData from "./lpa/reducer";
|
|||||||
import accountDetails from "./accountDetails/reducer";
|
import accountDetails from "./accountDetails/reducer";
|
||||||
import { reducer as formReducer } from "redux-form";
|
import { reducer as formReducer } from "redux-form";
|
||||||
import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2";
|
import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2";
|
||||||
|
import storage from "redux-persist/lib/storage";
|
||||||
|
|
||||||
//COMBINING ALL REDUCERS
|
//COMBINING ALL REDUCERS
|
||||||
const combinedReducer = combineReducers({
|
const appReducer = combineReducers({
|
||||||
search,
|
search,
|
||||||
searchResultsObj,
|
searchResultsObj,
|
||||||
formData,
|
formData,
|
||||||
@@ -21,6 +22,16 @@ const combinedReducer = combineReducers({
|
|||||||
form: formReducer,
|
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) => {
|
const reducer = (state = {}, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case HYDRATE:
|
case HYDRATE:
|
||||||
@@ -77,7 +88,7 @@ const makeStore = ({ isServer }) => {
|
|||||||
const storage = require("redux-persist/lib/storage").default;
|
const storage = require("redux-persist/lib/storage").default;
|
||||||
|
|
||||||
const persistConfig = {
|
const persistConfig = {
|
||||||
key: "nextjs",
|
key: "acp",
|
||||||
whitelist: [
|
whitelist: [
|
||||||
"search",
|
"search",
|
||||||
"searchResults",
|
"searchResults",
|
||||||
@@ -87,7 +98,7 @@ const makeStore = ({ isServer }) => {
|
|||||||
"accountDetails",
|
"accountDetails",
|
||||||
"form",
|
"form",
|
||||||
],
|
],
|
||||||
storage,
|
storage: storage,
|
||||||
stateReconciler: autoMergeLevel2, // if needed, use a safer storage
|
stateReconciler: autoMergeLevel2, // if needed, use a safer storage
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user