create ui for address search and results
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { useContext } from "react";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import SearchForCase from "./search/searchforcase";
|
||||
import AddressSearch from "./search/addresssearch";
|
||||
|
||||
export default function Search(props) {
|
||||
let { t } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
//console.log("props here:", props.myportal || false);
|
||||
|
||||
return (
|
||||
<main
|
||||
className="govuk-main-wrapper govuk-main-wrapper--auto-spacing"
|
||||
id="main-content"
|
||||
role="main"
|
||||
>
|
||||
<AddressSearch myportal={props.myportal || false} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { useContext } from "react";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import SearchForCase from "./search/searchforcase";
|
||||
import SearchResults from "./search/addresssearchresults";
|
||||
import CRMError from "./crmError";
|
||||
|
||||
export default function Search(props) {
|
||||
const {
|
||||
searchString,
|
||||
searchResultsObj,
|
||||
advancedSearch,
|
||||
myportal,
|
||||
watchedCases,
|
||||
isLinkedCase,
|
||||
showLoginCheck,
|
||||
} = props;
|
||||
let { t } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
|
||||
var hasError = _.has(searchResultsObj.searchResultsObj, "errorCode")
|
||||
? true
|
||||
: false;
|
||||
|
||||
//console.log("has an error", hasError);
|
||||
|
||||
return (
|
||||
<main
|
||||
className="govuk-main-wrapper govuk-main-wrapper--auto-spacing"
|
||||
id="main-content"
|
||||
role="main"
|
||||
>
|
||||
{hasError ? (
|
||||
<CRMError props={props} />
|
||||
) : (
|
||||
<>
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-full">
|
||||
<SearchResults
|
||||
advancedSearch={advancedSearch}
|
||||
searchString={searchString}
|
||||
searchResultsObj={
|
||||
searchResultsObj.searchResultsObj
|
||||
}
|
||||
searchDetailsObj={
|
||||
searchResultsObj.searchDetailsObj
|
||||
}
|
||||
myportal={myportal}
|
||||
watchedCases={watchedCases}
|
||||
isLinkedCase={isLinkedCase}
|
||||
showLoginCheck={showLoginCheck}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-full">
|
||||
<div className="govuk-button-group">
|
||||
<Link
|
||||
href="/addresssearch"
|
||||
className="govuk-button"
|
||||
>
|
||||
{t("common:breadcrumb-address-search")}
|
||||
</Link>
|
||||
{/* <a
|
||||
onClick={() => router.back()}
|
||||
className="govuk-button govuk-button--secondary"
|
||||
>
|
||||
{t("search:searchresults-new-search-button-label")}
|
||||
</a> */}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import { reduxForm, formValueSelector, Field } from "redux-form";
|
||||
import { useDispatch, useSelector, shallowEqual, connect } from "react-redux";
|
||||
import { JSONPath as jsonpath } from "jsonpath-plus";
|
||||
import data from "../../data/collections.json";
|
||||
|
||||
import transLookup from "../../data/lookuptranslations.json";
|
||||
import { values } from "lodash";
|
||||
|
||||
const required = (errorMsg) => (value) =>
|
||||
value || typeof value === "number" ? undefined : errorMsg;
|
||||
|
||||
export const minLength = (errorMsg) => (value) =>
|
||||
value && value.length < 3
|
||||
? errorMsg //`Must be ${min} characters or more`
|
||||
: undefined;
|
||||
|
||||
export const leastOneValue = (values, errorMsg) => (value) =>
|
||||
value ? console.log(values) : errorMsg;
|
||||
|
||||
const validate = (values) => {
|
||||
const errors = {};
|
||||
|
||||
if (values.appellantname) {
|
||||
if (
|
||||
!(
|
||||
values.addressline1 != null ||
|
||||
values.town != null ||
|
||||
values.county != null ||
|
||||
values.postcode != null
|
||||
)
|
||||
) {
|
||||
errors.appellantname =
|
||||
document.documentElement.lang == "cy"
|
||||
? "Angen rhan o'r cyfeiriad i chwilio gydag enw"
|
||||
: "Need part of the address to search with a name";
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
};
|
||||
|
||||
const RenderTextfield = ({
|
||||
id,
|
||||
className,
|
||||
rows,
|
||||
datafieldname,
|
||||
name,
|
||||
label,
|
||||
input,
|
||||
hint1,
|
||||
hint2,
|
||||
hint3,
|
||||
meta: { touched, error },
|
||||
...custom
|
||||
}) => {
|
||||
let { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="govuk-form-group">
|
||||
<div id="basicSearch-hint" className="govuk-hint ">
|
||||
<label className="govuk-label" htmlFor="caseRef">
|
||||
{label}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input
|
||||
{...input}
|
||||
className={className}
|
||||
name={name}
|
||||
id={id}
|
||||
/>
|
||||
{touched && error && (
|
||||
<span
|
||||
id={id + "-error"}
|
||||
className="govuk-error-message govuk-form-group--error"
|
||||
>
|
||||
<span className="govuk-visually-hidden">
|
||||
Error:
|
||||
</span>{" "}
|
||||
{error}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
let AddressSearch = (props) => {
|
||||
let { t } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
|
||||
const {
|
||||
LPAData,
|
||||
onSubmit,
|
||||
handleSubmit,
|
||||
myportal,
|
||||
error,
|
||||
pristine,
|
||||
reset,
|
||||
submitting,
|
||||
} = props;
|
||||
|
||||
const onHandleSubmit = (values) => {
|
||||
event.preventDefault();
|
||||
//spinnerState();
|
||||
|
||||
var searchString = "";
|
||||
|
||||
searchString +=
|
||||
values.appellantname != null
|
||||
? "appellantname=" + values.appellantname + "&"
|
||||
: "";
|
||||
|
||||
searchString +=
|
||||
values.addressline1 != null
|
||||
? "addressline1=" + values.addressline1.trim() + "&"
|
||||
: "";
|
||||
|
||||
searchString += values.town != null ? "town=" + values.town + "&" : "";
|
||||
|
||||
searchString +=
|
||||
values.county != null ? "county=" + values.county + "&" : "";
|
||||
|
||||
searchString +=
|
||||
values.postcode != null ? "postcode=" + values.postcode + "&" : "";
|
||||
|
||||
searchString = "?" + searchString.slice(0, -1);
|
||||
|
||||
console.log(searchString);
|
||||
|
||||
router.replace(
|
||||
router.locale == "cy"
|
||||
? (myportal == true ? "/fymhorth" : "") +
|
||||
"/canlyniadaucyfeiriadau" +
|
||||
searchString
|
||||
: (myportal == true ? "/myportal" : "") +
|
||||
"/addresssearchresults" +
|
||||
searchString
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<form onSubmit={handleSubmit(onHandleSubmit)}>
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-full">
|
||||
<div className="card" id="searchforcase-card">
|
||||
<div className="card-body">
|
||||
<div className="govuk-body-m ">
|
||||
<legend className="govuk-fieldset__legend govuk-fieldset__legend--l">
|
||||
<h1 className="govuk-fieldset__heading govuk-heading-m">
|
||||
{t(
|
||||
"search:address-search-title-label"
|
||||
)}
|
||||
</h1>
|
||||
</legend>
|
||||
|
||||
<fieldset className="govuk-fieldset">
|
||||
<Field
|
||||
validate={[
|
||||
minLength(
|
||||
t(
|
||||
"myportal:searchcases-validation-minlength"
|
||||
)
|
||||
),
|
||||
]}
|
||||
className="govuk-input govuk-!-width-two-thirds"
|
||||
component={RenderTextfield}
|
||||
id="appellantname"
|
||||
name="appellantname"
|
||||
type="text"
|
||||
aria-describedby="appellantname-hint"
|
||||
label={t(
|
||||
"search:applicant-label"
|
||||
)}
|
||||
/>
|
||||
|
||||
<Field
|
||||
validate={[
|
||||
minLength(
|
||||
t(
|
||||
"myportal:searchcases-validation-minlength"
|
||||
)
|
||||
),
|
||||
]}
|
||||
className="govuk-input govuk-!-width-two-thirds"
|
||||
component={RenderTextfield}
|
||||
id="addressline1"
|
||||
name="addressline1"
|
||||
type="text"
|
||||
aria-describedby="addressline1-hint"
|
||||
label={t(
|
||||
"search:address-line-one-label"
|
||||
)}
|
||||
/>
|
||||
<Field
|
||||
validate={[
|
||||
minLength(
|
||||
t(
|
||||
"myportal:searchcases-validation-minlength"
|
||||
)
|
||||
),
|
||||
]}
|
||||
className="govuk-input govuk-!-width-two-thirds"
|
||||
component={RenderTextfield}
|
||||
id="town"
|
||||
name="town"
|
||||
type="text"
|
||||
aria-describedby="addressline1-hint"
|
||||
label={t("search:town-label")}
|
||||
/>
|
||||
<Field
|
||||
validate={[
|
||||
minLength(
|
||||
t(
|
||||
"myportal:searchcases-validation-minlength"
|
||||
)
|
||||
),
|
||||
]}
|
||||
className="govuk-input govuk-!-width-two-thirds"
|
||||
component={RenderTextfield}
|
||||
id="county"
|
||||
name="county"
|
||||
type="text"
|
||||
aria-describedby="addressline1-hint"
|
||||
label={t("search:county-label")}
|
||||
/>
|
||||
<Field
|
||||
validate={[
|
||||
minLength(
|
||||
t(
|
||||
"myportal:searchcases-validation-minlength"
|
||||
)
|
||||
),
|
||||
]}
|
||||
className="govuk-input govuk-!-width-two-thirds"
|
||||
component={RenderTextfield}
|
||||
id="postcode"
|
||||
name="postcode"
|
||||
type="text"
|
||||
aria-describedby="addressline1-hint"
|
||||
label={t(
|
||||
"search:postcode-label"
|
||||
)}
|
||||
/>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-full">
|
||||
<div className="govuk-form-group">
|
||||
<button
|
||||
type="submit"
|
||||
name="search"
|
||||
className="govuk-button"
|
||||
disabled={pristine}
|
||||
>
|
||||
{t("common:search-button")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
currentView: state.currentView,
|
||||
search: state.search,
|
||||
searchResultsObj: state.searchResultsObj,
|
||||
formData: state.formData,
|
||||
appealType: state.appealType,
|
||||
LPAData: state.LPAData,
|
||||
//form: state.form,
|
||||
myCases: state.myCases,
|
||||
watchedCases: state.watchedCases,
|
||||
myRepresentations: state.myRepresentations,
|
||||
awaitingSubmission: state.awaitingSubmission,
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {};
|
||||
};
|
||||
|
||||
const selector = formValueSelector("addressSearchForm"); // <-- same as form name
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(
|
||||
reduxForm({
|
||||
form: "addressSearchForm",
|
||||
destroyOnUnmount: false,
|
||||
validate,
|
||||
})(AddressSearch)
|
||||
);
|
||||
@@ -0,0 +1,317 @@
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import { reduxForm, formValueSelector, Field } from "redux-form";
|
||||
import { useDispatch, useSelector, shallowEqual, connect } from "react-redux";
|
||||
import { JSONPath as jsonpath } from "jsonpath-plus";
|
||||
import data from "../../data/collections.json";
|
||||
|
||||
import transLookup from "../../data/lookuptranslations.json";
|
||||
import { values } from "lodash";
|
||||
|
||||
const required = (errorMsg) => (value) =>
|
||||
value || typeof value === "number" ? undefined : errorMsg;
|
||||
|
||||
export const minLength = (errorMsg) => (value) =>
|
||||
value && value.length < 3
|
||||
? errorMsg //`Must be ${min} characters or more`
|
||||
: undefined;
|
||||
|
||||
export const leastOneValue = (values, errorMsg) => (value) =>
|
||||
value ? console.log(values) : errorMsg;
|
||||
|
||||
const validate = (values) => {
|
||||
const errors = {};
|
||||
|
||||
console.log(document.documentElement.lang);
|
||||
|
||||
if (values.appellantname) {
|
||||
if (
|
||||
!(
|
||||
values.addressline1 != null ||
|
||||
values.town != null ||
|
||||
values.county != null ||
|
||||
values.postcode != null
|
||||
)
|
||||
) {
|
||||
errors.appellantname =
|
||||
document.documentElement.lang == "cy"
|
||||
? "Angen rhan o'r cyfeiriad i chwilio gydag enw"
|
||||
: "Need part of the address to search with a name";
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
};
|
||||
|
||||
const RenderTextfield = ({
|
||||
id,
|
||||
className,
|
||||
rows,
|
||||
datafieldname,
|
||||
name,
|
||||
label,
|
||||
input,
|
||||
hint1,
|
||||
hint2,
|
||||
hint3,
|
||||
meta: { touched, error },
|
||||
...custom
|
||||
}) => {
|
||||
let { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="govuk-form-group">
|
||||
<div id="basicSearch-hint" className="govuk-hint ">
|
||||
<label className="govuk-label" htmlFor="caseRef">
|
||||
{label}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input
|
||||
{...input}
|
||||
className={className}
|
||||
name={name}
|
||||
id={id}
|
||||
/>
|
||||
{touched && error && (
|
||||
<span
|
||||
id={id + "-error"}
|
||||
className="govuk-error-message govuk-form-group--error"
|
||||
>
|
||||
<span className="govuk-visually-hidden">
|
||||
Error:
|
||||
</span>{" "}
|
||||
{error}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
let AddressSearch = (props) => {
|
||||
let { t } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
|
||||
const {
|
||||
LPAData,
|
||||
onSubmit,
|
||||
handleSubmit,
|
||||
myportal,
|
||||
error,
|
||||
pristine,
|
||||
reset,
|
||||
submitting,
|
||||
} = props;
|
||||
|
||||
const onHandleSubmit = (values) => {
|
||||
event.preventDefault();
|
||||
//spinnerState();
|
||||
|
||||
var searchString = "";
|
||||
|
||||
searchString +=
|
||||
values.appellantname != null
|
||||
? "appellantname=" + values.appellantname + "&"
|
||||
: "";
|
||||
|
||||
searchString +=
|
||||
values.addressline1 != null
|
||||
? "addressline1=" + values.addressline1.trim() + "&"
|
||||
: "";
|
||||
|
||||
searchString += values.town != null ? "town=" + values.town + "&" : "";
|
||||
|
||||
searchString +=
|
||||
values.county != null ? "county=" + values.county + "&" : "";
|
||||
|
||||
searchString +=
|
||||
values.postcode != null ? "postcode=" + values.postcode + "&" : "";
|
||||
|
||||
searchString = "?" + searchString.slice(0, -1);
|
||||
|
||||
console.log(searchString);
|
||||
|
||||
router.replace(
|
||||
router.locale == "cy"
|
||||
? (myportal == true ? "/fymhorth" : "") +
|
||||
"/canlyniadaucyfeiriadau" +
|
||||
searchString
|
||||
: (myportal == true ? "/myportal" : "") +
|
||||
"/addresssearchresults" +
|
||||
searchString
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<form onSubmit={handleSubmit(onHandleSubmit)}>
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-full">
|
||||
<div className="card" id="searchforcase-card">
|
||||
<div className="card-body">
|
||||
<div className="govuk-body-m ">
|
||||
<legend className="govuk-fieldset__legend govuk-fieldset__legend--l">
|
||||
<h1 className="govuk-fieldset__heading govuk-heading-m">
|
||||
{t(
|
||||
"search:address-search-title-label"
|
||||
)}
|
||||
</h1>
|
||||
</legend>
|
||||
|
||||
<fieldset className="govuk-fieldset">
|
||||
<Field
|
||||
validate={[
|
||||
minLength(
|
||||
t(
|
||||
"myportal:searchcases-validation-minlength"
|
||||
)
|
||||
),
|
||||
]}
|
||||
className="govuk-input govuk-!-width-two-thirds"
|
||||
component={RenderTextfield}
|
||||
id="appellantname"
|
||||
name="appellantname"
|
||||
type="text"
|
||||
aria-describedby="appellantname-hint"
|
||||
label={t(
|
||||
"search:applicant-label"
|
||||
)}
|
||||
/>
|
||||
<Field
|
||||
validate={[
|
||||
minLength(
|
||||
t(
|
||||
"myportal:searchcases-validation-minlength"
|
||||
)
|
||||
),
|
||||
]}
|
||||
className="govuk-input govuk-!-width-two-thirds"
|
||||
component={RenderTextfield}
|
||||
id="addressline1"
|
||||
name="addressline1"
|
||||
type="text"
|
||||
aria-describedby="addressline1-hint"
|
||||
label={t(
|
||||
"search:address-line-one-label"
|
||||
)}
|
||||
/>
|
||||
|
||||
<Field
|
||||
validate={[
|
||||
minLength(
|
||||
t(
|
||||
"myportal:searchcases-validation-minlength"
|
||||
)
|
||||
),
|
||||
]}
|
||||
className="govuk-input govuk-!-width-two-thirds"
|
||||
component={RenderTextfield}
|
||||
id="town"
|
||||
name="town"
|
||||
type="text"
|
||||
aria-describedby="addressline1-hint"
|
||||
label={t("search:town-label")}
|
||||
/>
|
||||
|
||||
<Field
|
||||
validate={[
|
||||
minLength(
|
||||
t(
|
||||
"myportal:searchcases-validation-minlength"
|
||||
)
|
||||
),
|
||||
]}
|
||||
className="govuk-input govuk-!-width-two-thirds"
|
||||
component={RenderTextfield}
|
||||
id="county"
|
||||
name="county"
|
||||
type="text"
|
||||
aria-describedby="addressline1-hint"
|
||||
label={t("search:county-label")}
|
||||
/>
|
||||
|
||||
<Field
|
||||
validate={[
|
||||
minLength(
|
||||
t(
|
||||
"myportal:searchcases-validation-minlength"
|
||||
)
|
||||
),
|
||||
]}
|
||||
className="govuk-input govuk-!-width-two-thirds"
|
||||
component={RenderTextfield}
|
||||
id="postcode"
|
||||
name="postcode"
|
||||
type="text"
|
||||
aria-describedby="addressline1-hint"
|
||||
label={t(
|
||||
"search:postcode-label"
|
||||
)}
|
||||
/>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-full">
|
||||
<div className="govuk-form-group">
|
||||
<button
|
||||
type="submit"
|
||||
name="search"
|
||||
className="govuk-button"
|
||||
disabled={pristine}
|
||||
>
|
||||
{t("common:search-button")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
currentView: state.currentView,
|
||||
search: state.search,
|
||||
searchResultsObj: state.searchResultsObj,
|
||||
formData: state.formData,
|
||||
appealType: state.appealType,
|
||||
LPAData: state.LPAData,
|
||||
//form: state.form,
|
||||
myCases: state.myCases,
|
||||
watchedCases: state.watchedCases,
|
||||
myRepresentations: state.myRepresentations,
|
||||
awaitingSubmission: state.awaitingSubmission,
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {};
|
||||
};
|
||||
|
||||
const selector = formValueSelector("addressSearchForm"); // <-- same as form name
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(
|
||||
reduxForm({
|
||||
form: "addressSearchForm",
|
||||
destroyOnUnmount: false,
|
||||
validate,
|
||||
})(AddressSearch)
|
||||
);
|
||||
@@ -0,0 +1,900 @@
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import {
|
||||
currentViewActionTypes,
|
||||
setCurrentReference,
|
||||
} from "../../store/currentView/action";
|
||||
import { connect } from "react-redux";
|
||||
import { JSONPath as jsonpath } from "jsonpath-plus";
|
||||
import _, { result } from "lodash";
|
||||
import transLookup from "../../data/lookuptranslations.json";
|
||||
import {
|
||||
getBasicSearchPaged,
|
||||
getSearchDocumentDetails,
|
||||
getBasicSearchDetailsPaged,
|
||||
getAdvancedSearchPaged,
|
||||
} from "../../actions";
|
||||
import data from "../../data/collections.json";
|
||||
import { useCallback, useState } from "react";
|
||||
|
||||
import {
|
||||
setSearchResults,
|
||||
setSearchDetails,
|
||||
} from "../../store/searchOutput/action";
|
||||
import { setLoggedInUserId } from "../../store/accountDetails/action";
|
||||
import {
|
||||
setWatchedCases,
|
||||
setWatchedCasesDetails,
|
||||
} from "../../store/watchedCases/action";
|
||||
import { useEffect } from "react";
|
||||
import { parseCookies, setCookie, destroyCookie } from "nookies";
|
||||
|
||||
import PaginationControl from "./pagination";
|
||||
import {
|
||||
getSearchDetailsPaged,
|
||||
getFormCollection,
|
||||
getFormCollectionByID,
|
||||
} from "../utils";
|
||||
|
||||
import {
|
||||
createWatchedCases,
|
||||
getWatchedCasesProxy,
|
||||
getPortalModuleDetailsProxy,
|
||||
deleteWatchedCases,
|
||||
} from "../../actions";
|
||||
import { useSession, signIn, signOut } from "next-auth/react";
|
||||
|
||||
const SearchResults = (props) => {
|
||||
const {
|
||||
searchString,
|
||||
searchResultsObj,
|
||||
searchDetailsObj,
|
||||
setCurrentReference,
|
||||
setSearchResults,
|
||||
setSearchDetails,
|
||||
advancedSearch,
|
||||
myportal,
|
||||
watchedCases,
|
||||
setWatchedCases,
|
||||
setWatchedCasesDetails,
|
||||
isLinkedCase,
|
||||
showLoginCheck,
|
||||
} = props;
|
||||
let { t } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
const { data: session } = useSession();
|
||||
|
||||
let [resultsArr, setResultsArr] = useState(searchResultsObj.value || []);
|
||||
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [searchLoaded, setSearchLoaded] = useState(false);
|
||||
const [showSpinnerState, setShowSpinnerState] = useState(false);
|
||||
const [selectedOption, setSelectedOption] = useState(10);
|
||||
const [orderByState, setOrderbyState] = useState("createdon");
|
||||
const [fieldSortState, setfieldSortState] = useState("asc");
|
||||
const [loginToWatch, setLoginToWatch] = useState("true");
|
||||
|
||||
let spinnerState = () => {
|
||||
showSpinnerState == true
|
||||
? setShowSpinnerState(false)
|
||||
: setShowSpinnerState(true);
|
||||
};
|
||||
|
||||
const cookies = parseCookies();
|
||||
|
||||
const selectWatchedCase = (loggedInUser, incidentID, appealType) => {
|
||||
let updateBody = {
|
||||
"pinswg_WatchedCase@odata.bind": "/incidents(" + incidentID + ")",
|
||||
"pinswg_Contact@odata.bind": "/contacts(" + loggedInUser + ")",
|
||||
"pinswg_appealcasetype": +appealType,
|
||||
};
|
||||
|
||||
createWatchedCases(updateBody)
|
||||
.then((data) => data)
|
||||
.then(() => {
|
||||
getWatchedCasesProxy(props.accountDetails.loggedinUserId).then(
|
||||
(data) => {
|
||||
setWatchedCases(data),
|
||||
getDetails(data, "myWatchedCases").then((data) => {
|
||||
setWatchedCasesDetails(data);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const isWatchedCase = (whichIncident) => {
|
||||
let isWatched = jsonpath(
|
||||
"$..value[?(@._pinswg_watchedcase_value=='" + whichIncident + "')]",
|
||||
watchedCases
|
||||
);
|
||||
|
||||
return isWatched;
|
||||
};
|
||||
|
||||
const deleteItem = (caseID, topThreeType) => {
|
||||
let cookies = parseCookies();
|
||||
topThreeType == "watchedCases" &&
|
||||
deleteWatchedCases(caseID)
|
||||
.then((data) => data)
|
||||
.then(() => {
|
||||
getWatchedCasesProxy(
|
||||
props.accountDetails.loggedinUserId
|
||||
).then((data) => {
|
||||
setWatchedCases(data),
|
||||
getDetails(data, "myWatchedCases").then((data) => {
|
||||
setWatchedCasesDetails(data);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const getDetails = (resultsObj, detailsType) => {
|
||||
// console.log(resultsObj);
|
||||
let detailsArr = [];
|
||||
resultsObj = resultsObj.value;
|
||||
const detailsObj = resultsObj.map((searchDetail, index) => {
|
||||
if (searchDetail.pinswg_appealcasetype == null) {
|
||||
console.log(
|
||||
detailsType != "myWatchedCases"
|
||||
? searchDetail.ticketnumber
|
||||
: searchDetail[
|
||||
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
]
|
||||
);
|
||||
} else {
|
||||
detailsArr.push(
|
||||
getPortalModuleDetailsProxy(
|
||||
getFormCollectionByID(
|
||||
searchDetail.pinswg_appealcasetype
|
||||
).LogicalCollectionName,
|
||||
detailsType != "myWatchedCases"
|
||||
? searchDetail.ticketnumber
|
||||
: searchDetail[
|
||||
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
//console.log(detailsArr);
|
||||
return Promise.all(detailsArr);
|
||||
};
|
||||
|
||||
const indexOfLastRecord = currentPage * selectedOption;
|
||||
const indexOfFirstRecord = indexOfLastRecord - selectedOption;
|
||||
|
||||
const ResultsView = (resultsArr) => {
|
||||
var resultsArrPaged = resultsArr.slice(
|
||||
indexOfFirstRecord,
|
||||
indexOfLastRecord
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<dl className="govuk-summary-list govuk-!-margin-bottom-9 results">
|
||||
<div className="govuk-summary-list__row results-headings">
|
||||
<dd className="govuk-summary-list__key govuk-!-font-size-16 results_wider ">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => sortDataBy("pinswg_name")}
|
||||
className={
|
||||
orderByState == "pinswg_name"
|
||||
? fieldSortState == "asc"
|
||||
? `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortAsc`
|
||||
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortDesc`
|
||||
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16`
|
||||
}
|
||||
>
|
||||
{t("search:searchresults-case-reference-label")}
|
||||
</button>
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
||||
{t("search:searchresults-site-address-label")}
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
sortDataBy(
|
||||
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue"
|
||||
)
|
||||
}
|
||||
className={
|
||||
orderByState ==
|
||||
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue"
|
||||
? fieldSortState == "asc"
|
||||
? `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortAsc`
|
||||
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortDesc`
|
||||
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16`
|
||||
}
|
||||
>
|
||||
{t("search:searchresults-applicant-label")}
|
||||
</button>
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
sortDataBy("_pinswg_associatedlpa_value")
|
||||
}
|
||||
className={
|
||||
orderByState ==
|
||||
"_pinswg_associatedlpa_value"
|
||||
? fieldSortState == "asc"
|
||||
? `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortAsc`
|
||||
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortDesc`
|
||||
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16`
|
||||
}
|
||||
>
|
||||
{t("search:searchresults-authority-label")}
|
||||
</button>
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => sortDataBy("pinswg_appealType")}
|
||||
className={
|
||||
orderByState == "pinswg_appealcasetype"
|
||||
? fieldSortState == "asc"
|
||||
? `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortAsc`
|
||||
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortDesc`
|
||||
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16`
|
||||
}
|
||||
>
|
||||
{t("search:searchresults-case-type-label")}
|
||||
</button>
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
||||
{/* {t("search:searchresults-status-label")} */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => sortDataBy("statuscode")}
|
||||
className={
|
||||
orderByState == "statuscode"
|
||||
? fieldSortState == "asc"
|
||||
? `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortAsc`
|
||||
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16 sortDesc`
|
||||
: `govuk-link govuk-link--no-underline govuk-!-font-weight-bold govuk-!-font-size-16`
|
||||
}
|
||||
>
|
||||
{t("search:searchresults-status-label")}
|
||||
</button>
|
||||
</dd>
|
||||
|
||||
<dd className="govuk-summary-list__key govuk-!-font-size-16 govuk-summary-list__action"></dd>
|
||||
</div>
|
||||
{showSpinnerState == true ? (
|
||||
<div className="govuk-summary-list__row">
|
||||
<div className="govuk-!-margin-top-9 govuk-!-margin-bottom-9 govuk-!-font-weight-bold govuk-!-font-size-20 ">
|
||||
{t("common:spinner-fetching-data")}
|
||||
<img
|
||||
className="data-loading-icon"
|
||||
src="/assets/images/loading.gif"
|
||||
alt={
|
||||
router.locale == "cy"
|
||||
? "Nôl data"
|
||||
: "Fetching data"
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
resultsArrPaged.map((item, key) => {
|
||||
let detailsObj = jsonpath(
|
||||
'$..value[?(@.pinswg_name=="' +
|
||||
item.pinswg_name +
|
||||
'")]',
|
||||
searchDetailsObj
|
||||
);
|
||||
detailsObj = detailsObj[0];
|
||||
return (
|
||||
<div
|
||||
className="govuk-summary-list__row"
|
||||
key={key}
|
||||
>
|
||||
<dd className="govuk-summary-list__value govuk-!-font-size-16 ">
|
||||
<Link
|
||||
href={
|
||||
(router.locale == "cy"
|
||||
? myportal == true
|
||||
? "/fymhorth/achos/id"
|
||||
: "/achos/id"
|
||||
: myportal == true
|
||||
? "/myportal/case/id"
|
||||
: "/case/id") +
|
||||
"/" +
|
||||
item.incidentid
|
||||
}
|
||||
className="govuk-link--no-underline"
|
||||
// onClick={() => {
|
||||
// setCurrentReference({
|
||||
// "ticketnumber":
|
||||
// item.ticketnumber,
|
||||
// "currentReference":
|
||||
// item.title,
|
||||
// "currentType":
|
||||
// "searchResultsObj",
|
||||
// "incidentid":
|
||||
// item.incidentid,
|
||||
// "appealType":
|
||||
// item.pinswg_appealcasetype,
|
||||
// "showLoginCheck":
|
||||
// props.showLoginCheck,
|
||||
// });
|
||||
// }}
|
||||
>
|
||||
<span className="results-visually-hidden">
|
||||
{t(
|
||||
"search:searchresults-case-reference-label"
|
||||
)}
|
||||
:
|
||||
</span>
|
||||
{item.pinswg_name}
|
||||
</Link>
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
||||
<span className="results-visually-hidden">
|
||||
{t(
|
||||
"search:searchresults-site-address-label"
|
||||
)}
|
||||
:
|
||||
</span>
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_projectlocation"
|
||||
)
|
||||
? detailsObj.pinswg_projectlocation !=
|
||||
null
|
||||
? detailsObj.pinswg_projectlocation.indexOf(
|
||||
";"
|
||||
) < 0
|
||||
? detailsObj.pinswg_projectlocation
|
||||
: router.locale == "cy"
|
||||
? detailsObj.pinswg_projectlocation.split(
|
||||
";"
|
||||
)[1]
|
||||
: detailsObj.pinswg_projectlocation.split(
|
||||
";"
|
||||
)[0]
|
||||
: ""
|
||||
: ""}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_siteaddressline1"
|
||||
)
|
||||
? detailsObj.pinswg_siteaddressline1
|
||||
: ""}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_addressline1"
|
||||
)
|
||||
? detailsObj.pinswg_addressline1
|
||||
: ""}
|
||||
{/* {detailsObj.pinswg_siteaddressline1 !=
|
||||
null && <br />} */}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_siteaddressline1"
|
||||
) &&
|
||||
detailsObj.pinswg_siteaddressline1 !=
|
||||
null && <br />}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_addressline1"
|
||||
) &&
|
||||
detailsObj.pinswg_addressline1 !=
|
||||
null && <br />}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_siteaddressline1"
|
||||
)
|
||||
? detailsObj.pinswg_siteaddressline2
|
||||
: ""}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_addressline1"
|
||||
)
|
||||
? detailsObj.pinswg_addressline2
|
||||
: ""}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_siteaddressline2"
|
||||
) &&
|
||||
detailsObj.pinswg_siteaddressline2 !=
|
||||
null && <br />}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_addressline2"
|
||||
) &&
|
||||
detailsObj.pinswg_addressline2 !=
|
||||
null && <br />}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_siteaddresstown"
|
||||
)
|
||||
? detailsObj.pinswg_siteaddresstown
|
||||
: ""}
|
||||
{_.has(detailsObj, "pinswg_addresstown")
|
||||
? detailsObj.pinswg_addresstown
|
||||
: ""}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_siteaddresstown"
|
||||
) &&
|
||||
detailsObj.pinswg_siteaddresstown !=
|
||||
null && <br />}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_addresstown"
|
||||
) &&
|
||||
detailsObj.pinswg_addresstown !=
|
||||
null && <br />}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_siteaddresscounty"
|
||||
)
|
||||
? detailsObj.pinswg_siteaddresscounty
|
||||
: ""}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_addresscounty"
|
||||
)
|
||||
? detailsObj.pinswg_addresscounty
|
||||
: ""}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_siteaddresscounty"
|
||||
) &&
|
||||
detailsObj.pinswg_siteaddresscounty !=
|
||||
null && <br />}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_addresscounty"
|
||||
) &&
|
||||
detailsObj.pinswg_addresscounty !=
|
||||
null && <br />}
|
||||
{_.has(
|
||||
detailsObj,
|
||||
"pinswg_siteaddresspostcode"
|
||||
)
|
||||
? detailsObj.pinswg_siteaddresspostcode
|
||||
: ""}
|
||||
{_.has(detailsObj, "pinswg_postcode")
|
||||
? detailsObj.pinswg_postcode
|
||||
: ""}
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
||||
<span className="results-visually-hidden">
|
||||
{t(
|
||||
"search:searchresults-applicant-label"
|
||||
)}
|
||||
:
|
||||
</span>
|
||||
{_.has(detailsObj, [
|
||||
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue",
|
||||
])
|
||||
? detailsObj[
|
||||
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue"
|
||||
]
|
||||
: ""}
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
||||
<span className="results-visually-hidden">
|
||||
{t(
|
||||
"search:searchresults-authority-label"
|
||||
)}
|
||||
:
|
||||
</span>
|
||||
{_.has(item, [
|
||||
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue",
|
||||
])
|
||||
? router.locale == "cy"
|
||||
? jsonpath(
|
||||
'$..[?(@.value=="' +
|
||||
item[
|
||||
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
||||
] +
|
||||
'")].value_cy',
|
||||
transLookup
|
||||
)
|
||||
: item[
|
||||
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
||||
] || "N/A"
|
||||
: ""}
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
||||
<span className="results-visually-hidden">
|
||||
{t(
|
||||
"search:searchresults-case-type-label"
|
||||
)}
|
||||
:
|
||||
</span>
|
||||
{router.locale == "cy"
|
||||
? jsonpath(
|
||||
'$..[?(@.value=="' +
|
||||
item[
|
||||
"pinswg_appealType"
|
||||
] +
|
||||
'")].value_cy',
|
||||
transLookup
|
||||
)
|
||||
: item["pinswg_appealType"] ||
|
||||
"N/A"}
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__value govuk-!-font-size-16">
|
||||
<span className="results-visually-hidden">
|
||||
{t(
|
||||
"search:searchresults-status-label"
|
||||
)}
|
||||
:
|
||||
</span>
|
||||
|
||||
{router.locale == "cy"
|
||||
? jsonpath(
|
||||
'$..[?(@.value=="' +
|
||||
item[
|
||||
"statuscode@OData.Community.Display.V1.FormattedValue"
|
||||
] +
|
||||
'")].value_cy',
|
||||
transLookup
|
||||
)
|
||||
: item[
|
||||
"statuscode@OData.Community.Display.V1.FormattedValue"
|
||||
] || "N/A"}
|
||||
</dd>
|
||||
{myportal == true && (
|
||||
<dd className="govuk-summary-list__value govuk-!-font-size-14 govuk-summary-list__action">
|
||||
{isWatchedCase(item.incidentid)
|
||||
.length >
|
||||
0 ==
|
||||
true ? (
|
||||
<button
|
||||
className="govuk-summary-list__actionLink watched_link"
|
||||
onClick={() => {
|
||||
confirm(
|
||||
t(
|
||||
"case:you-have-stopped-watching-label"
|
||||
) +
|
||||
item.pinswg_name +
|
||||
"?"
|
||||
) &&
|
||||
deleteItem(
|
||||
isWatchedCase(
|
||||
item.incidentid
|
||||
)[0]
|
||||
.pinswg_watchlistid,
|
||||
|
||||
"watchedCases"
|
||||
);
|
||||
}}
|
||||
title={t(
|
||||
"case:stop-watching-case-link"
|
||||
)}
|
||||
>
|
||||
<span className="eye"></span>
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
className="govuk-summary-list__actionLink watchLink"
|
||||
onClick={() => {
|
||||
confirm(
|
||||
t(
|
||||
"case:you-are-watching-label"
|
||||
) +
|
||||
item.pinswg_name +
|
||||
"?"
|
||||
) &&
|
||||
selectWatchedCase(
|
||||
props
|
||||
.accountDetails
|
||||
.loggedinUserId,
|
||||
item.incidentid,
|
||||
item.pinswg_appealcasetype
|
||||
);
|
||||
}}
|
||||
title={t(
|
||||
"case:watch-this-case-link"
|
||||
)}
|
||||
>
|
||||
<span className="eye"></span>
|
||||
</button>
|
||||
)}
|
||||
</dd>
|
||||
)}
|
||||
|
||||
{(showLoginCheck == "true" ||
|
||||
showLoginCheck == true) &&
|
||||
!session && (
|
||||
<dd className="govuk-summary-list__value govuk-!-font-size-14 govuk-summary-list__action">
|
||||
<span className="results-visually-hidden">
|
||||
{t(
|
||||
"case:watch-this-case-link"
|
||||
)}
|
||||
</span>
|
||||
|
||||
<button
|
||||
className="govuk-summary-list__actionLink watchLink"
|
||||
onClick={() => {
|
||||
confirm(
|
||||
t(
|
||||
"case:trying-to-watch-case-label"
|
||||
) +
|
||||
item.pinswg_name +
|
||||
"\n\n" +
|
||||
t(
|
||||
"case:trying-to-watch-case-redirect-label"
|
||||
)
|
||||
) &&
|
||||
// signIn("email");
|
||||
signIn(undefined, {
|
||||
callbackUrl:
|
||||
"/myportal/addresssearchresults?" +
|
||||
new URLSearchParams(
|
||||
searchString
|
||||
) +
|
||||
"&toWatch=" +
|
||||
item.incidentid +
|
||||
"_" +
|
||||
item.pinswg_appealcasetype,
|
||||
});
|
||||
}}
|
||||
title={t(
|
||||
"case:watch-this-case-link"
|
||||
)}
|
||||
>
|
||||
<span className="eye"></span>
|
||||
</button>
|
||||
</dd>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</dl>
|
||||
|
||||
<PaginationControl
|
||||
showNoOfRecords={selectedOption}
|
||||
currentPage={currentPage}
|
||||
searchResultsObj={searchResultsObj}
|
||||
orderBy={orderByState}
|
||||
fieldSort={fieldSortState}
|
||||
spinnerState={spinnerState}
|
||||
getSearchPageResults={getSearchPageResults}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const pagesCount = Math.ceil(searchResultsObj["@odata.count"] / 10);
|
||||
|
||||
const getSearchPageResults = useCallback(
|
||||
(pageNumber, orderBy, fieldSort) => {
|
||||
// setSearchDetails(data);
|
||||
|
||||
setCurrentPage(pageNumber);
|
||||
|
||||
resultsArr = _.sortBy(resultsArr, [
|
||||
function (o) {
|
||||
return o[orderBy];
|
||||
},
|
||||
]);
|
||||
|
||||
fieldSort == "desc" && resultsArr.reverse();
|
||||
|
||||
setShowSpinnerState(false);
|
||||
setResultsArr(resultsArr);
|
||||
|
||||
console.log(
|
||||
"================================\n",
|
||||
resultsArr,
|
||||
"sort done",
|
||||
"\n=================================\n"
|
||||
);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const sortDataBy = (whichField) => {
|
||||
setOrderbyState(whichField);
|
||||
setfieldSortState("asc");
|
||||
|
||||
setShowSpinnerState(true);
|
||||
console.log(
|
||||
"================================\n",
|
||||
"sort start",
|
||||
"\n=================================\n"
|
||||
);
|
||||
getSearchPageResults(1, whichField, fieldSortState);
|
||||
whichField == orderByState
|
||||
? fieldSortState == "desc"
|
||||
? setfieldSortState("asc")
|
||||
: setfieldSortState("desc")
|
||||
: setfieldSortState("asc");
|
||||
setCurrentPage(1);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const selectWatchedCase = (loggedInUser, incidentID, appealType) => {
|
||||
let updateBody = {
|
||||
"pinswg_WatchedCase@odata.bind":
|
||||
"/incidents(" + incidentID + ")",
|
||||
"pinswg_Contact@odata.bind": "/contacts(" + loggedInUser + ")",
|
||||
"pinswg_appealcasetype": +appealType,
|
||||
};
|
||||
|
||||
createWatchedCases(updateBody)
|
||||
.then((data) => data)
|
||||
.then(() => {
|
||||
getWatchedCasesProxy(
|
||||
props.accountDetails.loggedinUserId
|
||||
).then((data) => {
|
||||
setWatchedCases(data),
|
||||
getDetails(data, "myWatchedCases").then((data) => {
|
||||
setWatchedCasesDetails(data);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// if (searchLoaded) {
|
||||
// if (selectedOption) {
|
||||
// setShowSpinnerState(true);
|
||||
// getSearchPageResults(1, orderByState, fieldSortState);
|
||||
// }
|
||||
// } else {
|
||||
// setSearchLoaded(true);
|
||||
// }
|
||||
if (loginToWatch && router.query.hasOwnProperty("toWatch")) {
|
||||
console.log("am in here");
|
||||
let now = new Date();
|
||||
let expDate = new Date(now);
|
||||
|
||||
expDate.setDate(now.getDate() + 1);
|
||||
|
||||
setLoggedInUserId(props.accountDetails.loggedinUserId);
|
||||
setCookie(null, "pinsUser", props.accountDetails.loggedinUserId, {
|
||||
path: "/",
|
||||
expires: expDate,
|
||||
});
|
||||
selectWatchedCase(
|
||||
props.accountDetails.loggedinUserId,
|
||||
router.query.toWatch.split("_")[0],
|
||||
router.query.toWatch.split("_")[1]
|
||||
);
|
||||
getSearchPageResults(1, orderByState, fieldSortState);
|
||||
setLoginToWatch(false);
|
||||
} else {
|
||||
//console.log("or am in here");
|
||||
setLoginToWatch(false);
|
||||
}
|
||||
}, [
|
||||
selectedOption,
|
||||
fieldSortState,
|
||||
orderByState,
|
||||
searchLoaded,
|
||||
loginToWatch,
|
||||
setWatchedCases,
|
||||
getSearchPageResults,
|
||||
setWatchedCasesDetails,
|
||||
props.accountDetails.loggedinUserId,
|
||||
router.query,
|
||||
]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-full">
|
||||
<h1 className="govuk-heading-xl govuk-!-margin-bottom-7">
|
||||
{isLinkedCase
|
||||
? t("search:searchresults-title-label-linked-case")
|
||||
: t("search:searchresults-title-label")}
|
||||
</h1>
|
||||
|
||||
{!isLinkedCase && (
|
||||
<p className="govuk-body">
|
||||
{resultsArr.length > 200
|
||||
? t("search:searchresults-max-count-label")
|
||||
: t("search:searchresults-count-label", {
|
||||
count: searchResultsObj["@odata.count"],
|
||||
})}
|
||||
.
|
||||
{advancedSearch != true ? (
|
||||
<>
|
||||
<span>
|
||||
{t(
|
||||
"search:searchresults-case-count-label"
|
||||
)}{" "}
|
||||
{" "}
|
||||
<em>"{searchString}"</em>
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{searchResultsObj["@odata.count"] > 5 && (
|
||||
<div id="recordCountSelect" className="">
|
||||
<div className="govuk-form-group">
|
||||
<label
|
||||
className="govuk-label-s "
|
||||
htmlFor="showNumberOfRecords"
|
||||
>
|
||||
{t(
|
||||
"search:searchresults-show-records-label-a"
|
||||
)}
|
||||
<select
|
||||
onChange={(e) => {
|
||||
setSelectedOption(e.target.value);
|
||||
// setCurrentPage(1);
|
||||
}}
|
||||
value={selectedOption}
|
||||
className="govuk-select"
|
||||
id="showNumberOfRecords"
|
||||
name="showNumberOfRecords"
|
||||
>
|
||||
<option value="5">5</option>
|
||||
<option value="10">10</option>
|
||||
<option value="20">20</option>
|
||||
<option value="30">30</option>
|
||||
<option value="50">50</option>
|
||||
</select>{" "}
|
||||
{t(
|
||||
"search:searchresults-show-records-label-b"
|
||||
)}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{resultsArr.length > 0 ? (
|
||||
ResultsView(resultsArr)
|
||||
) : (
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-two-thirds">
|
||||
<h3>
|
||||
{t("search:searchresults-no-records-label")}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
setCurrentReference: (currentReference) => {
|
||||
dispatch(setCurrentReference(currentReference));
|
||||
},
|
||||
setSearchResults: (searchResultsObj) => {
|
||||
dispatch(setSearchResults(searchResultsObj));
|
||||
},
|
||||
setSearchDetails: (searchDetailsObj) => {
|
||||
dispatch(setSearchDetails(searchDetailsObj));
|
||||
},
|
||||
setWatchedCases: (watchedCases) => {
|
||||
dispatch(setWatchedCases(watchedCases));
|
||||
},
|
||||
setWatchedCasesDetails: (watchedCasesDetails) => {
|
||||
dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
||||
},
|
||||
// setCurrentPage: (currentPage) => {
|
||||
// dispatch(setCurrentPage(currentPage));
|
||||
// },
|
||||
};
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
// currentView: state.currentView,
|
||||
accountDetails: state.accountDetails,
|
||||
// search: state.search,
|
||||
// searchResultsObj: state.searchResultsObj,
|
||||
};
|
||||
};
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(SearchResults);
|
||||
@@ -0,0 +1,130 @@
|
||||
//import fs from "fs";
|
||||
import _ from "lodash";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import { connect } from "react-redux";
|
||||
import { getAppealsTypes, getLPA } from "../actions";
|
||||
import Breadcrumbs from "../components/breadcrumbs";
|
||||
import CookieBanner from "../components/cookieBanner";
|
||||
import CRMError from "../components/crmError";
|
||||
import Footer from "../components/footer";
|
||||
import Header from "../components/header";
|
||||
import Search from "../components/addresssearch";
|
||||
import { setAppealType } from "../store/appealType/action";
|
||||
import { setLPA } from "../store/lpa/action";
|
||||
import { wrapper } from "../store/store";
|
||||
|
||||
const Home = (props) => {
|
||||
const { footerLinks, pages } = props;
|
||||
let { t, lang } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
const { appealtypes } = router.query;
|
||||
|
||||
var hasError =
|
||||
_.has(props.LPAData.LPAData, "errorCode") ||
|
||||
_.has(props.appealType.appealType, "errorCode")
|
||||
? true
|
||||
: false;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
<title>
|
||||
{t("search:page-title")} - {t("common:service-name")}
|
||||
</title>
|
||||
{/* Language by default is EN, if multilingual site this will need updated */}
|
||||
<>
|
||||
<link
|
||||
rel="canonical"
|
||||
href={t("common:gov-wales-link") + router.asPath}
|
||||
/>
|
||||
<meta
|
||||
key="og:locale"
|
||||
property="og:locale"
|
||||
content={router.locale}
|
||||
/>
|
||||
{/* If they have a Twitter Handle, include the meta details below */}
|
||||
<meta
|
||||
key="og:site_name"
|
||||
property="og:site_name"
|
||||
content={t("common:service-name")}
|
||||
/>
|
||||
<meta
|
||||
key="twitter:site"
|
||||
property="twitter:site"
|
||||
content="@UKGovWales"
|
||||
/>
|
||||
|
||||
<meta
|
||||
name="description"
|
||||
content={t("common:service-description")}
|
||||
/>
|
||||
<meta
|
||||
property="og:site_name"
|
||||
content={t("common:gov-wales-label")}
|
||||
/>
|
||||
<meta
|
||||
property="og:title"
|
||||
content={t("search:page-title")}
|
||||
/>
|
||||
<meta
|
||||
property="og:description"
|
||||
content={t("common:service-description")}
|
||||
/>
|
||||
<meta property="og:type" content="website" />
|
||||
<meta
|
||||
property="og:url"
|
||||
content={t("common:gov-wales-link")}
|
||||
/>
|
||||
<meta
|
||||
property="og:image"
|
||||
content="https://gov.wales/themes/custom/govwales/images/content/og-global-1200.png"
|
||||
/>
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta
|
||||
name="twitter:title"
|
||||
content={t("common:gov-wales-label")}
|
||||
/>
|
||||
<meta
|
||||
name="twitter:url"
|
||||
content={t("common:gov-wales-link") + router.asPath}
|
||||
/>
|
||||
<meta
|
||||
name="twitter:image"
|
||||
content="https://gov.wales/themes/custom/govwales/images/content/og-global-120.png"
|
||||
/>
|
||||
</>
|
||||
</Head>
|
||||
<div id="page_wrapper">
|
||||
<CookieBanner />
|
||||
<Header courseName={t("common:service-name")} />
|
||||
<div className="govuk-width-container">
|
||||
<Breadcrumbs slug={appealtypes} />
|
||||
{hasError ? (
|
||||
<CRMError props={props} whichError="advancedSearch" />
|
||||
) : (
|
||||
<Search />
|
||||
)}
|
||||
</div>
|
||||
<Footer footerLinks={footerLinks} ticketnumber={props} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
search: state.search,
|
||||
searchResultsObj: state.searchResultsObj,
|
||||
formData: state.formData,
|
||||
appealType: state.appealType,
|
||||
LPAData: state.LPAData,
|
||||
//form: state.form,
|
||||
accountDetails: state.accountDetails,
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(Home);
|
||||
@@ -0,0 +1,160 @@
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import { connect } from "react-redux";
|
||||
import {
|
||||
getAddressSearch,
|
||||
getIncidentbyID,
|
||||
getIsPublishedbyID,
|
||||
} from "../actions";
|
||||
import Breadcrumbs from "../components/breadcrumbs";
|
||||
import CookieBanner from "../components/cookieBanner";
|
||||
import Footer from "../components/footer";
|
||||
import Header from "../components/header";
|
||||
import SearchResults from "../components/addresssearchresults";
|
||||
import { getSearchDetails } from "../components/utils";
|
||||
import { setSearch } from "../store/search/action";
|
||||
import {
|
||||
setSearchDetails,
|
||||
setSearchResults,
|
||||
} from "../store/searchOutput/action";
|
||||
import { setShowReps } from "../store/currentView/action";
|
||||
|
||||
import { wrapper } from "../store/store";
|
||||
|
||||
const Home = (props) => {
|
||||
const { footerLinks, pages } = props;
|
||||
let { t, lang } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
const { appealtypes } = router.query;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
<title>
|
||||
{t("search:page-title")} - {t("common:service-name")}
|
||||
</title>
|
||||
<>
|
||||
<link
|
||||
rel="canonical"
|
||||
href={t("common:gov-wales-link") + router.asPath}
|
||||
/>
|
||||
<meta
|
||||
key="og:locale"
|
||||
property="og:locale"
|
||||
content={router.locale}
|
||||
/>
|
||||
{/* If they have a Twitter Handle, include the meta details below */}
|
||||
<meta
|
||||
key="og:site_name"
|
||||
property="og:site_name"
|
||||
content={t("common:service-name")}
|
||||
/>
|
||||
<meta
|
||||
key="twitter:site"
|
||||
property="twitter:site"
|
||||
content="@UKGovWales"
|
||||
/>
|
||||
|
||||
<meta
|
||||
name="description"
|
||||
content={t("common:service-description")}
|
||||
/>
|
||||
<meta
|
||||
property="og:site_name"
|
||||
content={t("common:gov-wales-label")}
|
||||
/>
|
||||
<meta
|
||||
property="og:title"
|
||||
content={t("search:page-title")}
|
||||
/>
|
||||
<meta
|
||||
property="og:description"
|
||||
content={t("common:service-description")}
|
||||
/>
|
||||
<meta property="og:type" content="website" />
|
||||
<meta
|
||||
property="og:url"
|
||||
content={t("common:gov-wales-link")}
|
||||
/>
|
||||
<meta
|
||||
property="og:image"
|
||||
content="https://gov.wales/themes/custom/govwales/images/content/og-global-1200.png"
|
||||
/>
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta
|
||||
name="twitter:title"
|
||||
content={t("common:gov-wales-label")}
|
||||
/>
|
||||
<meta
|
||||
name="twitter:url"
|
||||
content={t("common:gov-wales-link") + router.asPath}
|
||||
/>
|
||||
<meta
|
||||
name="twitter:image"
|
||||
content="https://gov.wales/themes/custom/govwales/images/content/og-global-120.png"
|
||||
/>
|
||||
</>
|
||||
</Head>
|
||||
<div id="page_wrapper">
|
||||
<CookieBanner />
|
||||
<Header courseName={t("common:service-name")} />
|
||||
<div className="govuk-width-container">
|
||||
<Breadcrumbs slug={appealtypes} />
|
||||
<SearchResults
|
||||
searchString={props.search.searchString}
|
||||
searchResultsObj={props.searchResultsObj}
|
||||
advancedSearch={true}
|
||||
showLoginCheck={props.showLoginCheck}
|
||||
/>
|
||||
</div>
|
||||
<Footer footerLinks={footerLinks} ticketnumber={props} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) =>
|
||||
async ({ query, req, res }) => {
|
||||
const searchResultsObj = await getAddressSearch(query);
|
||||
const searchDetailsObj = searchResultsObj;
|
||||
const showLoginCheck = process.env.SHOWLOGIN || false;
|
||||
const showReps = process.env.SHOWREPRESENTATIONS || false;
|
||||
store.dispatch(setShowReps(showReps, showLoginCheck));
|
||||
|
||||
// store.dispatch(setSearchResults(searchResultsObj));
|
||||
// store.dispatch(setSearchDetails(searchDetailsObj));
|
||||
store.dispatch(setSearch(Object.entries(query)));
|
||||
|
||||
return {
|
||||
props: {
|
||||
searchResultsObj: {
|
||||
searchResultsObj: searchResultsObj,
|
||||
searchDetailsObj: searchDetailsObj,
|
||||
},
|
||||
currentType: "directResultsObj",
|
||||
showLoginCheck: showLoginCheck,
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
currentView: state.currentView,
|
||||
search: state.search,
|
||||
//searchResultsObj: state.searchResultsObj,
|
||||
formData: state.formData,
|
||||
appealType: state.appealType,
|
||||
form: state.form,
|
||||
myCases: state.myCases,
|
||||
watchedCases: state.watchedCases,
|
||||
myRepresentations: state.myRepresentations,
|
||||
awaitingSubmission: state.awaitingSubmission,
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(Home);
|
||||
@@ -0,0 +1,221 @@
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import { connect } from "react-redux";
|
||||
import {
|
||||
getBasicSearch,
|
||||
getIncidentbyID,
|
||||
getIP,
|
||||
getPortalLogin,
|
||||
getPersonalAccount,
|
||||
} from "../../../actions";
|
||||
import CookieBanner from "../../../components/cookieBanner";
|
||||
import Footer from "../../../components/footer";
|
||||
import Header from "../../../components/header";
|
||||
import { getSearchDetails } from "../../../components/utils";
|
||||
import { setCurrentReference } from "../../../store/currentView/action";
|
||||
import { setSearch } from "../../../store/search/action";
|
||||
import {
|
||||
setSearchDetails,
|
||||
setSearchResults,
|
||||
} from "../../../store/searchOutput/action";
|
||||
import { wrapper } from "../../../store/store";
|
||||
import Case from "../../../components/case";
|
||||
import Breadcrumbs from "../../../components/breadcrumbs";
|
||||
import { getSession, useSession } from "next-auth/react";
|
||||
import {
|
||||
setAccountDetails,
|
||||
setContainerID,
|
||||
setLoggedInUserId,
|
||||
} from "../../../store/accountDetails/action";
|
||||
|
||||
const CaseHome = (props) => {
|
||||
const { footerLinks, pages } = props;
|
||||
let { t, lang } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
const { incident } = router.query;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
<title>
|
||||
Reference:{" "}
|
||||
{props.currentView.caseReference.currentReference}{" "}
|
||||
</title>
|
||||
</Head>
|
||||
<div id="page_wrapper">
|
||||
<CookieBanner />
|
||||
<Header serviceName="Developments of National Significance" />
|
||||
<div className="govuk-width-container">
|
||||
<Breadcrumbs slug={props.ticketnumber} props={props} />
|
||||
|
||||
<Case
|
||||
props={props}
|
||||
myCases={props.myCases.myCases}
|
||||
myCasesDetails={props.myCases.myCasesDetails}
|
||||
directSearchResultsObj={
|
||||
props.searchResultsObj.searchResultsObj
|
||||
}
|
||||
searchDetailsObj={
|
||||
props.searchResultsObj.searchDetailsObj
|
||||
}
|
||||
documentDetailsObj={props.documentDetailsObj}
|
||||
myRepresentations={
|
||||
props.myRepresentations.myRepresentations
|
||||
}
|
||||
watchedCases={props.watchedCases.watchedCases}
|
||||
watchedCasesDetails={
|
||||
props.watchedCases.watchedCasesDetails
|
||||
}
|
||||
awaitingSubmission={
|
||||
props.awaitingSubmission.awaitingSubmission
|
||||
}
|
||||
caseReference={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.ticketnumber
|
||||
}
|
||||
currentType={props.currentType}
|
||||
appealTypeID={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.pinswg_appealcasetype
|
||||
}
|
||||
incidentid={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.incidentid
|
||||
}
|
||||
representationsObj={
|
||||
props.searchResultsObj.representationsObj
|
||||
}
|
||||
showLoginCheck={true}
|
||||
/>
|
||||
</div>
|
||||
<Footer
|
||||
footerLinks={footerLinks}
|
||||
props={props}
|
||||
ticketnumber={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.ticketnumber
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) => async (ctx) => {
|
||||
const { query, req, res } = ctx;
|
||||
getIP(req);
|
||||
const { cookies } = req;
|
||||
|
||||
console.log(cookies);
|
||||
console.log("the query :", query.incident);
|
||||
|
||||
let thisSession = await getSession(ctx);
|
||||
let loggedInUser = {};
|
||||
|
||||
if (thisSession) {
|
||||
console.log(" has sesssion.......");
|
||||
[loggedInUser] = await Promise.all([
|
||||
await getPortalLogin(thisSession.user.email),
|
||||
]);
|
||||
|
||||
loggedInUser = loggedInUser.value[0].contactid;
|
||||
|
||||
const accountDetails = await getPersonalAccount(loggedInUser);
|
||||
store.dispatch(setAccountDetails(accountDetails));
|
||||
} else {
|
||||
console.log("not has sesssion.......");
|
||||
}
|
||||
|
||||
const searchResultsObj = await getIncidentbyID(query.incident);
|
||||
const searchDetailsObj = await getSearchDetails(searchResultsObj);
|
||||
|
||||
// console.log(
|
||||
// "\n======================================\n",
|
||||
// searchResultsObj,
|
||||
// "\n======================================\n"
|
||||
// );
|
||||
// console.log(
|
||||
// "\n======================================\n",
|
||||
// searchDetailsObj[0],
|
||||
// "\n======================================\n"
|
||||
// );
|
||||
|
||||
store.dispatch(setSearch(req.headers.referer.split("?")[1]));
|
||||
|
||||
console.log(
|
||||
searchResultsObj["@odata.count"] > 1 ||
|
||||
searchResultsObj["@odata.count"] < 1
|
||||
);
|
||||
|
||||
if (searchResultsObj["@odata.count"] < 1) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/404",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
if (searchResultsObj["@odata.count"] > 1) {
|
||||
return {
|
||||
redirect: {
|
||||
//destination: "/dns-not-found",
|
||||
destination: "/404",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
store.dispatch(
|
||||
setCurrentReference({
|
||||
"ticketnumber": searchResultsObj.value[0].ticketnumber,
|
||||
"currentReference": searchResultsObj.value[0].title,
|
||||
"currentType": "searchResultsObj",
|
||||
"incidentid": searchResultsObj.value[0].incidentid,
|
||||
"appealType":
|
||||
searchResultsObj.value[0].pinswg_appealcasetype,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
// console.log(searchResultsObj);
|
||||
return {
|
||||
props: {
|
||||
searchResultsObj: {
|
||||
searchResultsObj: searchResultsObj,
|
||||
searchDetailsObj: searchDetailsObj,
|
||||
},
|
||||
currentType: "directResultsObj",
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
accountDetails: state.accountDetails,
|
||||
currentView: state.currentView,
|
||||
search: state.search,
|
||||
//searchResultsObj: state.searchResultsObj,
|
||||
documentDetailsObj: state.searchResultsObj.documentDetailsObj,
|
||||
formData: state.formData,
|
||||
appealType: state.appealType,
|
||||
form: state.form,
|
||||
myCases: state.myCases,
|
||||
watchedCases: state.watchedCases,
|
||||
myRepresentations: state.myRepresentations,
|
||||
awaitingSubmission: state.awaitingSubmission,
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
setCurrentReference: (currentReference) => {
|
||||
dispatch(setCurrentReference(refno));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(CaseHome);
|
||||
@@ -0,0 +1,129 @@
|
||||
//import fs from "fs";
|
||||
import _ from "lodash";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import { connect } from "react-redux";
|
||||
import Breadcrumbs from "../../components/breadcrumbs";
|
||||
import CookieBanner from "../../components/cookieBanner";
|
||||
import CRMError from "../../components/crmError";
|
||||
import Footer from "../../components/footer";
|
||||
import Header from "../../components/header";
|
||||
import Search from "../../components/myportal/addresssearch";
|
||||
import { setAppealType } from "../../store/appealType/action";
|
||||
import { setLPA } from "../../store/lpa/action";
|
||||
import { wrapper } from "../../store/store";
|
||||
|
||||
const Home = (props) => {
|
||||
const { footerLinks, pages } = props;
|
||||
let { t, lang } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
const { appealtypes } = router.query;
|
||||
|
||||
var hasError =
|
||||
_.has(props.LPAData.LPAData, "errorCode") ||
|
||||
_.has(props.appealType.appealType, "errorCode")
|
||||
? true
|
||||
: false;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
<title>
|
||||
{t("search:page-title")} - {t("common:service-name")}
|
||||
</title>
|
||||
{/* Language by default is EN, if multilingual site this will need updated */}
|
||||
<>
|
||||
<link
|
||||
rel="canonical"
|
||||
href={t("common:gov-wales-link") + router.asPath}
|
||||
/>
|
||||
<meta
|
||||
key="og:locale"
|
||||
property="og:locale"
|
||||
content={router.locale}
|
||||
/>
|
||||
{/* If they have a Twitter Handle, include the meta details below */}
|
||||
<meta
|
||||
key="og:site_name"
|
||||
property="og:site_name"
|
||||
content={t("common:service-name")}
|
||||
/>
|
||||
<meta
|
||||
key="twitter:site"
|
||||
property="twitter:site"
|
||||
content="@UKGovWales"
|
||||
/>
|
||||
|
||||
<meta
|
||||
name="description"
|
||||
content={t("common:service-description")}
|
||||
/>
|
||||
<meta
|
||||
property="og:site_name"
|
||||
content={t("common:gov-wales-label")}
|
||||
/>
|
||||
<meta
|
||||
property="og:title"
|
||||
content={t("search:page-title")}
|
||||
/>
|
||||
<meta
|
||||
property="og:description"
|
||||
content={t("common:service-description")}
|
||||
/>
|
||||
<meta property="og:type" content="website" />
|
||||
<meta
|
||||
property="og:url"
|
||||
content={t("common:gov-wales-link")}
|
||||
/>
|
||||
<meta
|
||||
property="og:image"
|
||||
content="https://gov.wales/themes/custom/govwales/images/content/og-global-1200.png"
|
||||
/>
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta
|
||||
name="twitter:title"
|
||||
content={t("common:gov-wales-label")}
|
||||
/>
|
||||
<meta
|
||||
name="twitter:url"
|
||||
content={t("common:gov-wales-link") + router.asPath}
|
||||
/>
|
||||
<meta
|
||||
name="twitter:image"
|
||||
content="https://gov.wales/themes/custom/govwales/images/content/og-global-120.png"
|
||||
/>
|
||||
</>
|
||||
</Head>
|
||||
<div id="page_wrapper">
|
||||
<CookieBanner />
|
||||
<Header courseName={t("common:service-name")} />
|
||||
<div className="govuk-width-container">
|
||||
<Breadcrumbs slug={appealtypes} />
|
||||
{hasError ? (
|
||||
<CRMError props={props} whichError="advancedSearch" />
|
||||
) : (
|
||||
<Search myportal={true} />
|
||||
)}
|
||||
</div>
|
||||
<Footer footerLinks={footerLinks} ticketnumber={props} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
search: state.search,
|
||||
searchResultsObj: state.searchResultsObj,
|
||||
formData: state.formData,
|
||||
appealType: state.appealType,
|
||||
LPAData: state.LPAData,
|
||||
//form: state.form,
|
||||
accountDetails: state.accountDetails,
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(Home);
|
||||
@@ -0,0 +1,249 @@
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import { connect } from "react-redux";
|
||||
import {
|
||||
getAddressSearch,
|
||||
getIncidentbyID,
|
||||
getIsPublishedbyID,
|
||||
getAdvancedSearch,
|
||||
getPortalModuleDetails,
|
||||
getWatchedCases,
|
||||
getPersonalAccount,
|
||||
getIP,
|
||||
} from "../../actions";
|
||||
import Breadcrumbs from "../../components/breadcrumbs";
|
||||
import CookieBanner from "../../components/cookieBanner";
|
||||
import Footer from "../../components/footer";
|
||||
import Header from "../../components/header";
|
||||
import SearchResults from "../../components/addresssearchresults";
|
||||
import {
|
||||
getFormCollectionByID,
|
||||
getSearchDetails,
|
||||
} from "../../components/utils";
|
||||
import { setSearch } from "../../store/search/action";
|
||||
import {
|
||||
setSearchDetails,
|
||||
setSearchResults,
|
||||
} from "../../store/searchOutput/action";
|
||||
import {
|
||||
setAccountDetails,
|
||||
setContainerID,
|
||||
setLoggedInUserId,
|
||||
} from "../../store/accountDetails/action";
|
||||
import { setShowReps } from "../../store/currentView/action";
|
||||
import TimeOut from "../../components/timeout";
|
||||
import {
|
||||
setWatchedCases,
|
||||
setWatchedCasesDetails,
|
||||
} from "../../store/watchedCases/action";
|
||||
import { getSession, useSession, signIn, signOut } from "next-auth/react";
|
||||
|
||||
import { wrapper } from "../../store/store";
|
||||
|
||||
const Home = (props) => {
|
||||
const { footerLinks, pages } = props;
|
||||
let { t, lang } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
const { appealtypes } = router.query;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
<title>
|
||||
{t("search:page-title")} - {t("common:service-name")}
|
||||
</title>
|
||||
<>
|
||||
<link
|
||||
rel="canonical"
|
||||
href={t("common:gov-wales-link") + router.asPath}
|
||||
/>
|
||||
<meta
|
||||
key="og:locale"
|
||||
property="og:locale"
|
||||
content={router.locale}
|
||||
/>
|
||||
{/* If they have a Twitter Handle, include the meta details below */}
|
||||
<meta
|
||||
key="og:site_name"
|
||||
property="og:site_name"
|
||||
content={t("common:service-name")}
|
||||
/>
|
||||
<meta
|
||||
key="twitter:site"
|
||||
property="twitter:site"
|
||||
content="@UKGovWales"
|
||||
/>
|
||||
|
||||
<meta
|
||||
name="description"
|
||||
content={t("common:service-description")}
|
||||
/>
|
||||
<meta
|
||||
property="og:site_name"
|
||||
content={t("common:gov-wales-label")}
|
||||
/>
|
||||
<meta
|
||||
property="og:title"
|
||||
content={t("search:page-title")}
|
||||
/>
|
||||
<meta
|
||||
property="og:description"
|
||||
content={t("common:service-description")}
|
||||
/>
|
||||
<meta property="og:type" content="website" />
|
||||
<meta
|
||||
property="og:url"
|
||||
content={t("common:gov-wales-link")}
|
||||
/>
|
||||
<meta
|
||||
property="og:image"
|
||||
content="https://gov.wales/themes/custom/govwales/images/content/og-global-1200.png"
|
||||
/>
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta
|
||||
name="twitter:title"
|
||||
content={t("common:gov-wales-label")}
|
||||
/>
|
||||
<meta
|
||||
name="twitter:url"
|
||||
content={t("common:gov-wales-link") + router.asPath}
|
||||
/>
|
||||
<meta
|
||||
name="twitter:image"
|
||||
content="https://gov.wales/themes/custom/govwales/images/content/og-global-120.png"
|
||||
/>
|
||||
</>
|
||||
</Head>
|
||||
<div id="page_wrapper">
|
||||
<CookieBanner />
|
||||
<Header courseName={t("common:service-name")} />
|
||||
<div className="govuk-width-container">
|
||||
<Breadcrumbs slug={appealtypes} props={props} />
|
||||
<SearchResults
|
||||
searchString={props.search.searchString}
|
||||
searchResultsObj={props.searchResultsObj}
|
||||
advancedSearch={true}
|
||||
watchedCases={props.watchedCases}
|
||||
showLoginCheck={props.showLoginCheck}
|
||||
myportal={true}
|
||||
/>
|
||||
</div>
|
||||
<Footer footerLinks={footerLinks} ticketnumber={props} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) => async (ctx) => {
|
||||
const { query, req, res } = ctx;
|
||||
getIP(req);
|
||||
const searchResultsObj = await getAddressSearch(query);
|
||||
const searchDetailsObj = searchResultsObj;
|
||||
const showLoginCheck = process.env.SHOWLOGIN || false;
|
||||
const showReps = process.env.SHOWREPRESENTATIONS || false;
|
||||
store.dispatch(setShowReps(showReps, showLoginCheck));
|
||||
store.dispatch(setSearch(Object.entries(query)));
|
||||
|
||||
const { cookies } = req;
|
||||
|
||||
let loggedInUser = cookies.pinsUser;
|
||||
let thisSession = await getSession(ctx);
|
||||
|
||||
if (!thisSession) {
|
||||
console.log("not has sesssion.......");
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
thisSession != false &&
|
||||
store.dispatch(setContainerID(thisSession.user.id));
|
||||
|
||||
const [accountDetails, searchResultsObj, watchedCases] =
|
||||
await Promise.all([
|
||||
await getPersonalAccount(loggedInUser),
|
||||
await getAdvancedSearch(query),
|
||||
await getWatchedCases(loggedInUser),
|
||||
]);
|
||||
|
||||
console.log(accountDetails);
|
||||
|
||||
const [searchDetailsObj, watchedCasesDetails] = await Promise.all([
|
||||
await getSearchDetails(searchResultsObj),
|
||||
await getDetails(watchedCases, "myWatchedCases"),
|
||||
]);
|
||||
|
||||
store.dispatch(setAccountDetails(accountDetails));
|
||||
store.dispatch(setSearchResults(searchResultsObj));
|
||||
store.dispatch(setSearchDetails(searchDetailsObj));
|
||||
store.dispatch(setWatchedCases(watchedCases));
|
||||
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
||||
store.dispatch(setSearch(Object.entries(query)));
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
searchResultsObj: {
|
||||
searchResultsObj: searchResultsObj,
|
||||
searchDetailsObj: searchDetailsObj,
|
||||
},
|
||||
currentType: "directResultsObj",
|
||||
showLoginCheck: showLoginCheck,
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
const getDetails = (resultsObj, detailsType) => {
|
||||
//console.log(resultsObj);
|
||||
let detailsArr = [];
|
||||
resultsObj = resultsObj.value;
|
||||
const detailsObj = resultsObj.map((searchDetail, index) => {
|
||||
if (searchDetail.pinswg_appealcasetype == null) {
|
||||
console.log(
|
||||
detailsType != "myWatchedCases"
|
||||
? searchDetail.ticketnumber
|
||||
: searchDetail[
|
||||
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
]
|
||||
);
|
||||
} else {
|
||||
detailsArr.push(
|
||||
getPortalModuleDetails(
|
||||
getFormCollectionByID(searchDetail.pinswg_appealcasetype)
|
||||
.LogicalCollectionName,
|
||||
detailsType != "myWatchedCases"
|
||||
? searchDetail.ticketnumber
|
||||
: searchDetail[
|
||||
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
//console.log(detailsArr);
|
||||
return Promise.all(detailsArr);
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
currentView: state.currentView,
|
||||
search: state.search,
|
||||
//searchResultsObj: state.searchResultsObj,
|
||||
formData: state.formData,
|
||||
appealType: state.appealType,
|
||||
form: state.form,
|
||||
myCases: state.myCases,
|
||||
watchedCases: state.watchedCases,
|
||||
myRepresentations: state.myRepresentations,
|
||||
awaitingSubmission: state.awaitingSubmission,
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(Home);
|
||||
@@ -0,0 +1,216 @@
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import { connect } from "react-redux";
|
||||
import {
|
||||
getBasicSearch,
|
||||
getIncidentbyID,
|
||||
getIP,
|
||||
getPortalLogin,
|
||||
getPersonalAccount,
|
||||
} from "../../../../actions";
|
||||
import CookieBanner from "../../../../components/cookieBanner";
|
||||
import Footer from "../../../../components/footer";
|
||||
import Header from "../../../../components/header";
|
||||
import { getSearchDetails } from "../../../../components/utils";
|
||||
import { setCurrentReference } from "../../../../store/currentView/action";
|
||||
import { setSearch } from "../../../../store/search/action";
|
||||
import {
|
||||
setSearchDetails,
|
||||
setSearchResults,
|
||||
} from "../../../../store/searchOutput/action";
|
||||
import { wrapper } from "../../../../store/store";
|
||||
import Case from "../../../../components/case";
|
||||
import Breadcrumbs from "../../../../components/breadcrumbs";
|
||||
import { getSession, useSession } from "next-auth/react";
|
||||
import {
|
||||
setAccountDetails,
|
||||
setContainerID,
|
||||
setLoggedInUserId,
|
||||
} from "../../../../store/accountDetails/action";
|
||||
|
||||
const CaseHome = (props) => {
|
||||
const { footerLinks, pages } = props;
|
||||
let { t, lang } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
const { incident } = router.query;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
<title>
|
||||
Reference:{" "}
|
||||
{props.currentView.caseReference.currentReference}{" "}
|
||||
</title>
|
||||
</Head>
|
||||
<div id="page_wrapper">
|
||||
<CookieBanner />
|
||||
<Header serviceName="Developments of National Significance" />
|
||||
<div className="govuk-width-container">
|
||||
<Breadcrumbs slug={props.ticketnumber} props={props} />
|
||||
|
||||
<Case
|
||||
props={props}
|
||||
myCases={props.myCases.myCases}
|
||||
myCasesDetails={props.myCases.myCasesDetails}
|
||||
directSearchResultsObj={
|
||||
props.searchResultsObj.searchResultsObj
|
||||
}
|
||||
searchDetailsObj={
|
||||
props.searchResultsObj.searchDetailsObj
|
||||
}
|
||||
documentDetailsObj={props.documentDetailsObj}
|
||||
myRepresentations={
|
||||
props.myRepresentations.myRepresentations
|
||||
}
|
||||
watchedCases={props.watchedCases.watchedCases}
|
||||
watchedCasesDetails={
|
||||
props.watchedCases.watchedCasesDetails
|
||||
}
|
||||
awaitingSubmission={
|
||||
props.awaitingSubmission.awaitingSubmission
|
||||
}
|
||||
caseReference={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.ticketnumber
|
||||
}
|
||||
currentType={props.currentType}
|
||||
appealTypeID={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.pinswg_appealcasetype
|
||||
}
|
||||
incidentid={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.incidentid
|
||||
}
|
||||
representationsObj={
|
||||
props.searchResultsObj.representationsObj
|
||||
}
|
||||
showLoginCheck={true}
|
||||
/>
|
||||
</div>
|
||||
<Footer
|
||||
footerLinks={footerLinks}
|
||||
props={props}
|
||||
ticketnumber={
|
||||
props.searchResultsObj.searchResultsObj.value[0]
|
||||
.ticketnumber
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) => async (ctx) => {
|
||||
const { query, req, res } = ctx;
|
||||
getIP(req);
|
||||
const { cookies } = req;
|
||||
|
||||
console.log(cookies);
|
||||
console.log("the query :", query.incident);
|
||||
|
||||
let thisSession = await getSession(ctx);
|
||||
let loggedInUser = {};
|
||||
|
||||
if (thisSession) {
|
||||
console.log(" has sesssion.......");
|
||||
[loggedInUser] = await Promise.all([
|
||||
await getPortalLogin(thisSession.user.email),
|
||||
]);
|
||||
|
||||
loggedInUser = loggedInUser.value[0].contactid;
|
||||
|
||||
const accountDetails = await getPersonalAccount(loggedInUser);
|
||||
store.dispatch(setAccountDetails(accountDetails));
|
||||
} else {
|
||||
console.log("not has sesssion.......");
|
||||
}
|
||||
|
||||
const searchResultsObj = await getIncidentbyID(query.incident);
|
||||
const searchDetailsObj = await getSearchDetails(searchResultsObj);
|
||||
|
||||
// console.log(
|
||||
// "\n======================================\n",
|
||||
// searchResultsObj,
|
||||
// "\n======================================\n"
|
||||
// );
|
||||
// console.log(
|
||||
// "\n======================================\n",
|
||||
// searchDetailsObj[0],
|
||||
// "\n======================================\n"
|
||||
// );
|
||||
|
||||
store.dispatch(setSearch(req.headers.referer.split("?")[1]));
|
||||
|
||||
if (searchResultsObj["@odata.count"] < 1) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/404",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
if (searchResultsObj["@odata.count"] > 1) {
|
||||
return {
|
||||
redirect: {
|
||||
//destination: "/dns-not-found",
|
||||
destination: "/404",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
store.dispatch(
|
||||
setCurrentReference({
|
||||
"ticketnumber": searchResultsObj.value[0].ticketnumber,
|
||||
"currentReference": searchResultsObj.value[0].title,
|
||||
"currentType": "searchResultsObj",
|
||||
"incidentid": searchResultsObj.value[0].incidentid,
|
||||
"appealType":
|
||||
searchResultsObj.value[0].pinswg_appealcasetype,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
// console.log(searchResultsObj);
|
||||
return {
|
||||
props: {
|
||||
searchResultsObj: {
|
||||
searchResultsObj: searchResultsObj,
|
||||
searchDetailsObj: searchDetailsObj,
|
||||
},
|
||||
currentType: "directResultsObj",
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
accountDetails: state.accountDetails,
|
||||
currentView: state.currentView,
|
||||
search: state.search,
|
||||
//searchResultsObj: state.searchResultsObj,
|
||||
documentDetailsObj: state.searchResultsObj.documentDetailsObj,
|
||||
formData: state.formData,
|
||||
appealType: state.appealType,
|
||||
form: state.form,
|
||||
myCases: state.myCases,
|
||||
watchedCases: state.watchedCases,
|
||||
myRepresentations: state.myRepresentations,
|
||||
awaitingSubmission: state.awaitingSubmission,
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
setCurrentReference: (currentReference) => {
|
||||
dispatch(setCurrentReference(refno));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(CaseHome);
|
||||
Reference in New Issue
Block a user