152 lines
5.3 KiB
JavaScript
152 lines
5.3 KiB
JavaScript
import _ from "lodash";
|
|
import Head from "next/head";
|
|
import Header from "../../components/header";
|
|
import Banner from "../../components/banner";
|
|
import CookieBanner from "../../components/cookieBanner";
|
|
import Breadcrumbs from "../../components/breadcrumbs";
|
|
import Footer from "../../components/footer";
|
|
import Errorpage from "../../components/errorpage";
|
|
import styles from "../../styles/Home.module.css";
|
|
import { useSelector, shallowEqual, connect } from "react-redux";
|
|
import { wrapper } from "../../store/store";
|
|
import Cookies from "cookies";
|
|
import { useRouter } from "next/router";
|
|
import { useState } from "react";
|
|
import useTranslation from "next-translate/useTranslation";
|
|
|
|
import {
|
|
setAppealType,
|
|
setAppealTypeTitle,
|
|
setAppealTypeID,
|
|
getAppealTypeObj,
|
|
} from "../../store/appealType/action";
|
|
import { getAppealsTypes } from "../../actions";
|
|
import xpath from "xpath";
|
|
|
|
const Home = (props) => {
|
|
const { footerLinks, pages, formData } = props;
|
|
let { t, lang } = useTranslation();
|
|
|
|
const router = useRouter();
|
|
const { locale } = router;
|
|
const { appealtypes } = router.query;
|
|
|
|
const { appealType } = props;
|
|
|
|
const optionsObj = props.appealType.appealTypeOptions.GlobalOptionSet
|
|
.Options || [{}];
|
|
|
|
const appealOptions = Object.keys(optionsObj).map((key, index) => (
|
|
<option
|
|
value={optionsObj[key].Label.LocalizedLabels[0].Label.replace(
|
|
/[\s\-\+\(\)\,]/g,
|
|
""
|
|
).toLowerCase()}
|
|
key={key}
|
|
>
|
|
{optionsObj[key].Label.LocalizedLabels[0].Label}
|
|
</option>
|
|
));
|
|
|
|
const [appealTypeSelect, setAppealTypeSelect] = useState("");
|
|
const handleParam = (setValue) => (e) => setValue(e.target.value);
|
|
|
|
const selectAppealType = (event) => {
|
|
event.preventDefault();
|
|
router.replace("/newappeal/" + props.appealType.appealTypeID, null, {
|
|
shallow: true,
|
|
});
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
<Head>
|
|
<title>
|
|
{t("search:page-title")} - {t("common:service-name")}
|
|
</title>
|
|
</Head>
|
|
<div id="page_wrapper">
|
|
<CookieBanner />
|
|
<Header courseName={t("common:service-name")} />
|
|
<main
|
|
className="govuk-main-wrapper govuk-main-wrapper--auto-spacing"
|
|
id="main-content"
|
|
role="main"
|
|
>
|
|
<div className="govuk-grid-row">
|
|
<div className="govuk-grid-column-full">
|
|
<div className="govuk-width-container">
|
|
<Banner />
|
|
<Breadcrumbs slug={appealtypes} />
|
|
|
|
<h1>New Appeal</h1>
|
|
|
|
<form onSubmit={selectAppealType}>
|
|
<div className="govuk-form-group">
|
|
<label
|
|
className="govuk-label"
|
|
htmlFor="sort"
|
|
>
|
|
Select an appeal Type
|
|
</label>
|
|
<select
|
|
className="govuk-select"
|
|
id="appealTypes"
|
|
name="appealTypes"
|
|
onChange={(e) =>
|
|
props.onChangeSelect(e)
|
|
}
|
|
>
|
|
{appealOptions}
|
|
</select>
|
|
</div>
|
|
<button
|
|
className="govuk-button"
|
|
data-module="govuk-button"
|
|
>
|
|
Continue
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
<Footer footerLinks={footerLinks} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = wrapper.getServerSideProps(
|
|
(store) =>
|
|
async ({ query, req, res }) => {
|
|
const appealTypeData = await getAppealsTypes();
|
|
console.log("appeal types", appealTypeData);
|
|
store.dispatch(setAppealType(appealTypeData));
|
|
}
|
|
);
|
|
|
|
const mapStateToProps = (state) => {
|
|
return {
|
|
search: state.search,
|
|
searchResultsObj: state.searchResultsObj,
|
|
formData: state.formData,
|
|
appealType: state.appealType,
|
|
};
|
|
};
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
return {
|
|
onChangeSelect: (event) => {
|
|
dispatch(
|
|
setAppealTypeTitle(
|
|
event.target.options[event.target.selectedIndex].text
|
|
)
|
|
);
|
|
dispatch(setAppealTypeID(event.target.value));
|
|
},
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Home);
|