Files
pedwfrontend/components/newappeal/buildsection.js
T
2021-07-08 17:17:12 +01:00

87 lines
2.6 KiB
JavaScript

import Link from "next/link";
import { useRouter } from "next/router";
import useTranslation from "next-translate/useTranslation";
import { useState, useEffect } from "react";
import xpath from "xpath";
import BuildRow from "./buildrow";
const BuildSection = (props) => {
useEffect(() => {
document.title = `You clicked ${currentSection} times`;
window.scrollTo(0, 0);
});
let { t } = useTranslation();
const router = useRouter();
const { locale } = router;
const { formXML, sectionCount } = props;
const [currentSection, setCurrentSection] = useState(1);
const parser = new DOMParser();
var doc = parser.parseFromString(props.formXML, "text/xml");
var titles = xpath.select(
"//form/tabs/tab[" + currentSection + " ]/labels/label/@description",
doc
);
var rowXML = xpath.select(
"/form/tabs/tab[" +
currentSection +
"]/columns//sections/section/rows/row",
doc
);
const handleParam = (setValue) => (e) => setValue(e.target.value);
const basicSearch = (event) => {
event.preventDefault();
console.log(query);
// /searchresults
};
return (
<div className="govuk-grid-row">
<div className="govuk-grid-column-full">
<h2>{titles[0].value} </h2>
<BuildRow
rowXML={rowXML}
whichSection={props.whichSection}
sectionCount={props.sectionCount}
/>
{}
<div class="govuk-button-group">
{props.sectionCount != currentSection ? (
<button
class="govuk-button"
data-module="govuk-button"
onClick={() =>
setCurrentSection(currentSection + 1)
}
>
Continue
</button>
) : (
""
)}
{currentSection > 1 ? (
<a
class="govuk-link"
href="#"
onClick={() =>
setCurrentSection(currentSection - 1)
}
>
Back
</a>
) : (
""
)}
</div>
</div>
</div>
);
};
export default BuildSection;