pagination between sections
This commit is contained in:
@@ -1,52 +1,86 @@
|
|||||||
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 { useState, useEffect } from "react";
|
||||||
import xpath from "xpath";
|
import xpath from "xpath";
|
||||||
import BuildRow from "./buildrow";
|
import BuildRow from "./buildrow";
|
||||||
|
|
||||||
export default function BuildSection(props) {
|
const BuildSection = (props) => {
|
||||||
|
useEffect(() => {
|
||||||
|
document.title = `You clicked ${currentSection} times`;
|
||||||
|
window.scrollTo(0, 0);
|
||||||
|
});
|
||||||
|
|
||||||
let { t } = useTranslation();
|
let { t } = useTranslation();
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { locale } = router;
|
const { locale } = router;
|
||||||
|
|
||||||
const { formXML, whichSection, sectionCount } = props;
|
const { formXML, sectionCount } = props;
|
||||||
|
const [currentSection, setCurrentSection] = useState(1);
|
||||||
|
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
var doc = parser.parseFromString(props.formXML, "text/xml");
|
var doc = parser.parseFromString(props.formXML, "text/xml");
|
||||||
var titles = xpath.select(
|
var titles = xpath.select(
|
||||||
"//form/tabs/tab[" +
|
"//form/tabs/tab[" + currentSection + " ]/labels/label/@description",
|
||||||
(parseInt(whichSection) + 1) +
|
|
||||||
" ]/labels/label/@description",
|
|
||||||
doc
|
doc
|
||||||
);
|
);
|
||||||
var rowXML = xpath.select(
|
var rowXML = xpath.select(
|
||||||
"/form/tabs/tab[" +
|
"/form/tabs/tab[" +
|
||||||
(parseInt(whichSection) + 1) +
|
currentSection +
|
||||||
"]/columns//sections/section/rows/row",
|
"]/columns//sections/section/rows/row",
|
||||||
doc
|
doc
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleParam = (setValue) => (e) => setValue(e.target.value);
|
||||||
|
|
||||||
|
const basicSearch = (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
console.log(query);
|
||||||
|
// /searchresults
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="govuk-grid-row">
|
<div className="govuk-grid-row">
|
||||||
<div className="govuk-grid-column-full">
|
<div className="govuk-grid-column-full">
|
||||||
<h2>
|
<h2>{titles[0].value} </h2>
|
||||||
{props.whichSection} - {titles[0].value}{" "}
|
|
||||||
</h2>
|
|
||||||
<BuildRow
|
<BuildRow
|
||||||
rowXML={rowXML}
|
rowXML={rowXML}
|
||||||
whichSection={props.whichSection}
|
whichSection={props.whichSection}
|
||||||
sectionCount={props.sectionCount}
|
sectionCount={props.sectionCount}
|
||||||
/>
|
/>
|
||||||
<button
|
{}
|
||||||
type="submit"
|
<div class="govuk-button-group">
|
||||||
role="button"
|
{props.sectionCount != currentSection ? (
|
||||||
draggable="false"
|
<button
|
||||||
class="govuk-button"
|
class="govuk-button"
|
||||||
data-module="govuk-button"
|
data-module="govuk-button"
|
||||||
>
|
onClick={() =>
|
||||||
Continue
|
setCurrentSection(currentSection + 1)
|
||||||
</button>
|
}
|
||||||
|
>
|
||||||
|
Continue
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
""
|
||||||
|
)}
|
||||||
|
{currentSection > 1 ? (
|
||||||
|
<a
|
||||||
|
class="govuk-link"
|
||||||
|
href="#"
|
||||||
|
onClick={() =>
|
||||||
|
setCurrentSection(currentSection - 1)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Back
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
""
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default BuildSection;
|
||||||
|
|||||||
@@ -80,7 +80,11 @@ const Home = (props) => {
|
|||||||
<div className="govuk-width-container">
|
<div className="govuk-width-container">
|
||||||
<Banner />
|
<Banner />
|
||||||
<Breadcrumbs slug={appealtypes} />
|
<Breadcrumbs slug={appealtypes} />
|
||||||
{Sections}
|
|
||||||
|
<BuildSection
|
||||||
|
formXML={formXML}
|
||||||
|
sectionCount={sectionCount}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Footer footerLinks={footerLinks} />
|
<Footer footerLinks={footerLinks} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user