import Link from "next/link";
import _ from "lodash";
import { useRouter } from "next/router";
import useTranslation from "next-translate/useTranslation";
import { connect } from "react-redux";
import { Field, reduxForm, formValueSelector } from "redux-form";
import {
RenderPickList,
RenderTextfield,
RenderRadioList,
RenderMultiline,
RenderCondtionalRadioList,
RenderLPACondtionalRadioList,
FileUploadField,
RenderRichMultiline,
RenderDatePicker,
} from "./representationElements";
import { getFormCollectionByID, formatDates } from "../../utils";
import {
setRepresentationCapacity,
setRepresentationSubmit,
} from "../../../store/currentView/action";
import { useDropzone } from "react-dropzone";
import { select } from "xpath";
import { JSONPath as jsonpath } from "jsonpath-plus";
import { useState } from "react";
import Enforcement_Questionnaire from "./representationQuestionnaires/representationLPAQuestionnaire_enforcement";
import S78_Questionnaire from "./representationQuestionnaires/representationLPAQuestionnaire_s78";
import RepresentationProgress_s78 from "./representationProgress/representationProgress_s78";
import RepresentationProgress_enforcement from "./representationProgress/representationProgress_enforcement";
import transLookup from "../../../data/lookuptranslations.json";
let RepLPA = (props) => {
let { t } = useTranslation();
const router = useRouter();
const { locale } = router;
const {
onSubmit,
handleSubmit,
formObj,
appellantApplicantRepresentationArr,
setRepresentationCapacity,
setRepresentationSubmit,
currentView,
procedureTypeValue,
onBehalfOfLPA,
setShowQuestionnaireSection,
showQuestionnaireSection,
questionnaireCount,
setQuestionnaireCount,
setRepFileName,
updateRepresentation,
} = props;
const { acceptedFiles, getRootProps, getInputProps } = useDropzone();
const files = acceptedFiles.map((file) => (
{file.path} - {file.size} bytes
));
const required = (value) => (value ? undefined : "Required");
const updateQuestionnaireCount = () => {
{
switch (currentView.caseReference.appealType) {
case 846040000:
case 846040001:
case 846040006:
case 846040025:
case 846040004:
case 846040018:
case 846040003:
case 846040009:
case 846040008:
setQuestionnaireCount(7);
break;
case 846040005:
case 846040006:
case 846040007:
setQuestionnaireCount(9);
break;
default:
setQuestionnaireCount(7);
break;
}
}
};
const whichQuestionnaire = () => {
{
switch (currentView.caseReference.appealType) {
case 846040000:
case 846040001:
case 846040006:
case 846040025:
case 846040004:
case 846040018:
case 846040003:
case 846040009:
case 846040008:
updateQuestionnaireCount();
return (
);
break;
case 846040005:
case 846040006:
case 846040007:
updateQuestionnaireCount();
return (
);
break;
default:
return <>>;
break;
}
}
};
const whichProgress = () => {
{
switch (currentView.caseReference.appealType) {
case 846040000:
case 846040001:
case 846040006:
case 846040025:
case 846040004:
case 846040018:
case 846040003:
case 846040009:
case 846040008:
return (
);
break;
case 846040005:
case 846040006:
case 846040007:
return (
);
break;
default:
return <>>;
break;
}
}
};
let setCaseDetailsObj = router.query.hasOwnProperty("state")
? router.query.state == "edit"
? props.props.myRepresentations.myRepresentations
: props.props.searchResultsObj.searchDetailsObj
: props.props.searchResultsObj.searchDetailsObj;
var detailsObj = {};
detailsObj = jsonpath(
'$..[?(@.pinswg_name=="' +
currentView.caseReference.currentReference +
'")]',
setCaseDetailsObj
);
let setCaseResultssObj = router.query.hasOwnProperty("state")
? router.query.state == "edit"
? props.props.myRepresentations.myRepresentations
: props.props.searchResultsObj.searchResultsObj
: props.props.searchResultsObj.searchResultsObj;
detailsObj = detailsObj[0];
var resultsObj = {};
resultsObj = jsonpath(
'$..[?(@.pinswg_name=="' +
currentView.caseReference.currentReference +
'")]',
setCaseResultssObj
);
resultsObj = resultsObj[0];
props.formObj["representationForm"].hasOwnProperty("values") &&
props.formObj["representationForm"].values.hasOwnProperty(
"representationCapacity"
) &&
props.formObj["representationForm"].values.hasOwnProperty(
"representationType"
) &&
setRepFileName(props.formObj["representationForm"].values);
return (
<>
{!_.has(
formObj["representationForm"],
["values", "representationType"] ||
typeof props.representationType != "undefined"
) ? (
<>
>
) : (
)}
{/* {!formObj["representationForm"].hasOwnProperty("values") ||
typeof formObj.representationForm.values
.representationType == "undefined" ? (
<>
{typeof props.representationType !=
"undefined" ||
typeof formObj.representationForm.values
.representationType != "undefined"
? props.representationType ==
"Questionnaire"
? locale == "cy"
? "Holiadur"
: props.representationType
: props.representationType
: locale == "cy"
? "Cynrychioliadau"
: "Representation"}{" "}
{locale == "cy"
? "o ACLI am a"
: "from an LPA for a"}{" "}
{locale == "cy"
? jsonpath(
'$..[?(@.attributevalue=="' +
currentView.caseReference
.appealType +
'")].value_cy',
transLookup
)
: getFormCollectionByID(
currentView.caseReference.appealType
).value}
>
) : (
)} */}
{(_.has(formObj["representationForm"], [
"values",
"representationType",
]) ||
typeof props.representationType != "undefined") &&
(props.representationType != "Questionnaire" ? (
<>
{t("myrepresentations:enter-comment-label")}
>
) : (
whichQuestionnaire()
))}
{" "}
>
);
};
const selector = formValueSelector("representationForm"); // <-- same as form name
RepLPA = connect((state) => {
const representationType = selector(state, "representationType");
const procedureType = selector(state, "procedureType");
return {
procedureType,
representationType,
};
})(RepLPA);
const mapStateToProps = (state, props) => {
let initialValuesTemp = Object.assign(
state.currentView.caseReference.hasOwnProperty("repDetails")
? state.currentView.caseReference.repDetails
: state.currentView.caseReference,
{
"representationCapacity": "lpa",
"onBehalfOfLPA":
props.props.props.accountDetails.accountDetails[
"pinswg_contact_associatedlpa@OData.Community.Display.V1.FormattedValue"
],
"firstname":
props.props.props.accountDetails.accountDetails.firstname,
"lastname":
props.props.props.accountDetails.accountDetails.lastname,
}
);
return {
search: state.search,
searchResultsObj: state.searchResultsObj,
formData: state.formData,
appealType: state.appealType,
currentView: state.currentView,
myRepresentations: state.myRepresentations,
watchedCases: state.watchedCases,
initialValues: initialValuesTemp,
};
};
export default connect(mapStateToProps)(
reduxForm({
form: "representationForm",
enableReinitialize: true,
destroyOnUnmount: false,
})(RepLPA)
);