diff --git a/actions/azurestorage.js b/actions/azurestorage.js index 360cc9d9..f9bc1001 100644 --- a/actions/azurestorage.js +++ b/actions/azurestorage.js @@ -782,6 +782,18 @@ export const getCaseBlob = async ( return blobName; }; +export const getTempCaseBlob = async (containerName, caseReference) => { + const blobName = caseReference + "/case/" + caseReference + "_case.json"; + const containerToken = await createContainerSas(containerName); + const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`; + const containerClient = new ContainerClient(sasUrl); + const blobClient = containerClient.getBlobClient(blobName); + const downloadedBlob = await blobClient.download(0); + + const downloaded = await streamToBuffer(downloadedBlob.readableStreamBody); + return JSON.parse(downloaded.toString()); +}; + export const getProgressBlobs = async (containerName, caseReference) => { const containerToken = await createContainerSas(containerName); diff --git a/actions/index.js b/actions/index.js index 1500cbed..0e1250a4 100644 --- a/actions/index.js +++ b/actions/index.js @@ -1388,7 +1388,8 @@ export const generateAppealPDF = async ( formValues, containerID, casefolderID, - appealType + appealType, + fileList ) => { //let files = filesObj; @@ -1396,7 +1397,11 @@ export const generateAppealPDF = async ( // var formData = new FormData(); // formValues.append("appealData", JSON.stringify(formValues)); // formValues.append("containerID", containerID); - // formValues.append("casefolderID", casefolderID); + //formValues.append("filesList", fileList); + + Object.assign(formValues, { + "filesList": fileList.hasOwnProperty("value") ? fileList.value : [], + }); var queryUrl = "/api/file/generateappealpdf?appealType=" + appealType; diff --git a/components/newappeal/aboutyou.js b/components/newappeal/aboutyou.js index 04fc7098..a0265407 100644 --- a/components/newappeal/aboutyou.js +++ b/components/newappeal/aboutyou.js @@ -1,14 +1,9 @@ import useTranslation from "next-translate/useTranslation"; import { useRouter } from "next/router"; import { connect } from "react-redux"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import { Field, formValueSelector, reduxForm, change } from "redux-form"; -import { - FieldsTranslations, - Radiofield, - Textfield, - MultiLinefield, -} from "../elements"; +import { tr } from "date-fns/locale"; const RenderTextfield = ({ id, @@ -24,7 +19,7 @@ const RenderTextfield = ({ meta: { touched, error }, ...custom }) => { - console.log(custom); + //console.log(custom); return ( <>
{ + return ( + <> +
+
+ + + + {touched && error && ( + + + Error: + {" "} + {errorMsg} + + )} +
+ {Object.keys(options).map((key, index) => ( +
+ + +
+ ))} +
+
+
+ + ); +}; + +const RenderRadio = ({ + datafieldname, + name, + label, + id, + errorMsg, + options, + input: { onChange, value }, + meta: { touched, error }, + ...custom +}) => { + let { t } = useTranslation(); + const required = (value) => (value ? undefined : "Required"); + + return ( + <> +
+
+ + + + {touched && error && ( + + + Error: + {" "} + {errorMsg} + + )} +
+ {" "} + {custom.hint != false || + (custom.hint != undefined && ( +
+ {t(custom.hint)} +
+ ))} + {Object.keys(options).map((key, index) => ( +
+ { + let docListObj = custom.documentList; + if ( + custom.requiredDocumentValue == + "Yes" + ) { + e.target.value != "846040000" + ? (docListObj = Object.assign( + docListObj, + { + ["documentCheckList_" + + id]: + custom.requiredDocumentLabel, + } + )) + : delete docListObj[ + "documentCheckList_" + id + ]; + custom.setDocumentsList(docListObj); + } + }} + /> + +
+ ))} +
+
+
+ + ); +}; + +function Radiofield(props) { + const { + name, + label, + datafieldname, + parentField, + form, + formProps, + parentFieldShowOnValue, + validation, + } = props; + + const router = useRouter(); + const required = (value) => (value ? undefined : "Required"); + // console.log(props.options); + + const fieldOptions = props.options + .slice(1, props.options.length - 1) + .split(","); + + //parentFieldShowOnValue + var showIfHasParentShowValue = parentField != false; + //debugger; + // parentField != false && + // !_.isEmpty(formProps[form]) && + // _.has(formProps[form].values, parentField) && + // parentFieldShowOnValue.indexOf( + // formProps[form].values[parentField].toString() + // ) > -1; + + (showIfHasParentShowValue == parentField) != false && + showIfHasParentShowValue; + + // console.log( + // datafieldname, + // showIfHasParentShowValue, + // formProps[form].values[parentField] + // ); + let { t } = useTranslation(); + + return ( + <> + {parentField != false ? ( + showIfHasParentShowValue && ( + + ) + ) : ( + + )} + + ); +} let AboutYou = (props) => { let { t } = useTranslation(); @@ -122,6 +389,8 @@ let AboutYou = (props) => { updateField, } = props; + const [isAgent, setIsAgent] = useState(false); + const yesNo = router.locale == "cy" ? ["Ydw", "Na"] : ["Yes", "No"]; const appellantAgent = router.locale == "cy" ? ["Apelydd", "Asiant"] : ["Appellant", "Agent"]; @@ -142,282 +411,6 @@ let AboutYou = (props) => { ? "Invalid phone number" : undefined; - const RenderYesNo = ({ - datafieldname, - name, - label, - id, - errorMsg, - options, - input: { onChange, value }, - meta: { touched, error }, - ...custom - }) => { - return ( - <> -
-
- - - - {touched && error && ( - - - Error: - {" "} - {errorMsg} - - )} -
- {Object.keys(options).map((key, index) => ( -
- - -
- ))} -
-
-
- - ); - }; - - const RenderRadio = ({ - datafieldname, - name, - label, - id, - errorMsg, - options, - input: { onChange, value }, - meta: { touched, error }, - ...custom - }) => { - let { t } = useTranslation(); - const required = (value) => (value ? undefined : "Required"); - - return ( - <> -
-
- - - - {touched && error && ( - - - Error: - {" "} - {errorMsg} - - )} -
- {" "} - {custom.hint != false || - (custom.hint != undefined && ( -
- {t(custom.hint)} -
- ))} - {Object.keys(options).map((key, index) => ( -
- { - let docListObj = - custom.documentList; - if ( - custom.requiredDocumentValue == - "Yes" - ) { - e.target.value != "846040000" - ? (docListObj = - Object.assign( - docListObj, - { - ["documentCheckList_" + - id]: - custom.requiredDocumentLabel, - } - )) - : delete docListObj[ - "documentCheckList_" + - id - ]; - custom.setDocumentsList( - docListObj - ); - } - }} - /> - -
- ))} -
-
-
- - ); - }; - - function Radiofield(props) { - const { - name, - label, - datafieldname, - parentField, - form, - formProps, - parentFieldShowOnValue, - validation, - } = props; - - const router = useRouter(); - const required = (value) => (value ? undefined : "Required"); - // console.log(props.options); - - const fieldOptions = props.options - .slice(1, props.options.length - 1) - .split(","); - - //parentFieldShowOnValue - var showIfHasParentShowValue = parentField != false; - //debugger; - // parentField != false && - // !_.isEmpty(formProps[form]) && - // _.has(formProps[form].values, parentField) && - // parentFieldShowOnValue.indexOf( - // formProps[form].values[parentField].toString() - // ) > -1; - - (showIfHasParentShowValue == parentField) != false && - showIfHasParentShowValue; - - // console.log( - // datafieldname, - // showIfHasParentShowValue, - // formProps[form].values[parentField] - // ); - - return ( - <> - {parentField != false ? ( - showIfHasParentShowValue && ( - - ) - ) : ( - - )} - - ); - } const onHandleSubmit = (values) => { event.preventDefault(); console.log(JSON.stringify(values)); @@ -425,39 +418,39 @@ let AboutYou = (props) => { }; const handlePartialUpdate = () => { - if (appellantAgentValue == "846040001") { + if (appellantAgentValue == "846040001" && isAgent == false) { updateField("caseForm", "pinswg_appellantfirstname", ""); updateField("caseForm", "pinswg_appellantlastname", ""); updateField("caseForm", "pinswg_appellantemailaddress", ""); updateField("caseForm", "pinswg_appellantaddress", ""); updateField("caseForm", "pinswg_appellantphonenumber", ""); - } else { - updateField( - "caseForm", - "pinswg_appellantfirstname", - props.initialValues.pinswg_appellantfirstname - ); - updateField( - "caseForm", - "pinswg_appellantlastname", - props.initialValues.pinswg_appellantlastname - ); - updateField( - "caseForm", - "pinswg_appellantemailaddress", - props.initialValues.pinswg_appellantemailaddress - ); - updateField( - "caseForm", - "pinswg_appellantaddress", - props.initialValues.pinswg_appellantaddress - ); - updateField( - "caseForm", - "pinswg_appellantphonenumber", - props.initialValues.pinswg_appellantphonenumber - ); - } + setIsAgent(true); + } //else { + // updateField( + // "caseForm", + // "pinswg_appellantfirstname", + // props.initialValues.pinswg_appellantfirstname + // ); + // updateField( + // "caseForm", + // "pinswg_appellantlastname", + // props.initialValues.pinswg_appellantlastname + // ); + // updateField( + // "caseForm", + // "pinswg_appellantemailaddress", + // props.initialValues.pinswg_appellantemailaddress + // ); + // updateField( + // "caseForm", + // "pinswg_appellantaddress", + // props.initialValues.pinswg_appellantaddress + // ); + // updateField( + // "caseForm", + // "pinswg_appellantphonenumber", + // props.initialValues.pinswg_appellantphonenumber + // ); }; useEffect(() => { @@ -506,7 +499,7 @@ let AboutYou = (props) => { {t("newappeal:about-you-appellant-contact-details")} { { pdfObj, props.props.accountDetails.containerID, props.appealType.caseReference.ticketnumber, - router.query.appealtypes + router.query.appealtypes, + props.appealType.fileList ), props.setNewAppealProgress( getProgressObj(formXML, titleList, mandatoryFieldsData, props) diff --git a/components/pdftemplates/appealRow_pdf.js b/components/pdftemplates/appealRow_pdf.js index 82898afa..752896de 100644 --- a/components/pdftemplates/appealRow_pdf.js +++ b/components/pdftemplates/appealRow_pdf.js @@ -9,6 +9,7 @@ import { getFormCollectionByID, getPickListLabel, getRadioLabel, + bytesToSize, } from "../../components/utils"; import ReactPDF, { @@ -178,9 +179,17 @@ export const AppealRow_pdf = (props) => { var rows = xpath.select("//label/@description", doc); var fieldtype = xpath.select("//@classid", doc); var datafieldname = xpath.select("//@datafieldname", doc); - var datafieldcontent = xpath.select("//@datafieldcontent", doc); + var parentField = xpath.select("//@parentField", doc); + var parentFieldShowOnValue = xpath.select( + "//@parentFieldShowOnValue", + doc + ); + var documentTypeCode = xpath.select( + "//@ishareDocumentCode", + doc + ); console.log(datafieldname[0].value); return ( @@ -380,6 +389,52 @@ export const AppealRow_pdf = (props) => { ); break; + case "{16D63FD6-119B-4353-BDCA-18358721C3FE}": + const blobList = jsonpath.query( + props.filesList, + "$..[?(@.documentType=='" + + documentTypeCode[0].value + + "')]" + ); + return ( + + + + {rows[0].value} + + + + {blobList.map((blob, i) => ( + + {blob.name} -{" "} + {bytesToSize( + blob.contentLength + )} + + ))} + + + ); + break; default: return ( { }} > - {/* {FieldsTranslations(rows[0].value)} */} {rows[0].value} diff --git a/components/pdftemplates/planningappeals78_pdf.js b/components/pdftemplates/planningappeals78_pdf.js index 518e2d8a..5c926aad 100644 --- a/components/pdftemplates/planningappeals78_pdf.js +++ b/components/pdftemplates/planningappeals78_pdf.js @@ -10,7 +10,7 @@ import ReactPDF, { } from "@react-pdf/renderer"; import { createElement } from "react"; import Html from "react-pdf-html"; -import { getFormCollectionByID } from "../utils"; +import { getFormCollectionByID, bytesToSize } from "../utils"; import fs from "fs"; import xpath from "xpath"; import renderers, { renderBlock } from "react-pdf-html/dist/renderers"; @@ -36,7 +36,11 @@ const styles = StyleSheet.create({ }, logoImage: { width: "200pt" }, questionBullet: { width: "5%", fontSize: 12 }, - questionText: { width: "30%", fontSize: 12 }, + questionText: { + width: "35%", + fontSize: 12, + fontFamily: "Helvetica-Bold", + }, questionTextMid: { width: "80%", fontSize: 12 }, questionTextWide: { width: "95%", fontSize: 12, marginBottom: 5 }, questionAnswer: { @@ -139,7 +143,7 @@ export const planningappeals78_pdf = ({ docProps, pickListData }) => { doc ); - //console.log(titles); + console.log("\n//////////\n The Case:\n", docProps.caseObj); return ( @@ -177,6 +181,326 @@ export const planningappeals78_pdf = ({ docProps, pickListData }) => { /> + + + Case Details + + + + + + Appeal submitted on behalf of: + + + {" "} + { + values.caseObj + .pinswg_onbehalfof + } + + + + + Appellant or Agent + + + {" "} + {values.caseObj + .pinswg_appellantagent == + "846040000" + ? "Appellant" + : "Agent"} + + + + + Appellant name + + + {values.caseObj + .pinswg_appellantfirstname + + " " + + values.caseObj + .pinswg_appellantlastname} + + + + + Appellant email address + + + { + values.caseObj + .pinswg_appellantemailaddress + } + + + + + Appellant address + + + { + values.caseObj + .pinswg_appellantaddress + } + + + + + Appellant phone number + + + {" "} + { + values.caseObj + .pinswg_appellantphonenumber + } + + + {values.caseObj.pinswg_appellantagent != + "846040000" && ( + <> + + + Company name + + + { + values.caseObj + .pinswg_agentcompanyname + } + + + + + Agent name + + + { + values.caseObj + .pinswg_agentfirstname + }{" "} + { + values.caseObj + .pinswg_agentlastname + } + + + + + Agent email address + + + { + values.caseObj + .pinswg_agentemailaddress + } + + + + + Agent address + + + { + values.caseObj + .pinswg_agentaddress + } + + + + + Agent phone number + + + {" "} + { + values.caseObj + .pinswg_agentphonenumber + } + + + + )} + + + LPA + + + {values.caseObj.pinswg_lpaname} + + + + + Contact Preference + + + {values.caseObj + .pinswg_contactprefs == + "846040000" + ? "Email" + : "Post"} + + + + + Language Preference + + + {values.caseObj + .pinswg_contactprefs == + "846040000" + ? "English" + : "Welsh"} + + + + + + + + {Object.keys(titles).map((key) => ( { key={key} mandatoryFieldsData={null} pickListData={pickListData} + filesList={values.filesList} /> @@ -218,7 +543,7 @@ export const planningappeals78_pdf = ({ docProps, pickListData }) => { ))} - + {/* { - 11. - - List of attached files - + + List of attached files + + + {values.hasOwnProperty("filesList") && - values.filesList.map(function (p) { - return ( - - - {p.name} - {p.size} - - - ); - })} + values.filesList.map((key) => ( + + {key.name} -{" "} + {bytesToSize(key.contentLength)} + + ))} - + */} { console.log("Progress blob path:", data); @@ -172,6 +178,15 @@ export default async function handler(req, res) { } ); + let newFileListArr = blobProgress.filesList.concat( + appealBodyObj.filesList[0] + ); + + Object.assign(blobProgress, { + "filesList": newFileListArr, + "caseObj": tempCaseBlob, + }); + //console.log(blobProgress); //if (hashAPIPath(checkquerypath) == "?hash=" + checkHash) { // //createContainer(containerID).then((containerName) => {