Skip to content

Commit

Permalink
Merge pull request #5288 from bcgov/dev-marshal-ST-3968
Browse files Browse the repository at this point in the history
Dev marshal st 3968
  • Loading branch information
sumathi-thirumani authored Jun 20, 2024
2 parents 80f4986 + a7a03a2 commit b921d83
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,15 @@ const CommentStructure = ({ i, reply, parentId, totalcommentCount, currentIndex,
} catch (error) {
console.log(error)
}
const element = document.querySelector(`[data-msg-halfdiv-id="${currentIndex}"]`);
html2pdf().from(element).outputPdf('blob').then(async (blob) => {
if (isEmail && i.category !== "response") {
const element = document.querySelector(`[data-msg-halfdiv-id="${currentIndex}"]`);
html2pdf().from(element).outputPdf('blob').then(async (blob) => {
blobs.push({name: "Email Body.pdf", lastModified: new Date(), input: blob})
const zipfile = await downloadZip(blobs).blob()
saveAs(zipfile, fullName + " " + i.date.replace("|", "") + ".zip");
});
}
const zipfile = await downloadZip(blobs).blob()
saveAs(zipfile, fullName + " " + i.date.replace("|", "") + ".zip");
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

.template-list-item {
border: ridge;
border-right: none;
border-right: ridge;
border-bottom: none;
cursor: pointer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const ContactApplicant = ({


const [files, setFiles] = useState([]);
const [templates, setTemplates] = useState<any[]>([{ value: "", label: "", templateid: null, text: "", disabled: true }]);
const [templates, setTemplates] = useState<any[]>([{ value: "", label: "", templateid: null, text: "", disabled: true, created_at:"" }]);

React.useEffect(() => {
applicantCorrespondenceTemplates.forEach((item: any) => {
Expand All @@ -169,11 +169,11 @@ export const ContactApplicant = ({
label: item.description,
templateid: item.templateid,
text: await new Response(response.data).text(),
disabled: false
disabled: false,
created_at: item.created_at
}
setTemplates((oldArray) => [...oldArray, templateItem]);
});

});
});
}
});
Expand Down Expand Up @@ -254,10 +254,12 @@ export const ContactApplicant = ({

//When templates are selected from list
const handleTemplateSelection = (index: number) => {
setCurrentTemplate(index)
setCurrentTemplate(index);
const templateVariables = getTemplateVariables(requestDetails, templates[index]);
const finalTemplate = applyVariables(templates[index].text || "", templateVariables);
setEditorValue(finalTemplate)
setEditorValue(finalTemplate);
changeCorrespondenceFilter("log");

}

const removeFile = (index: number) => {
Expand Down Expand Up @@ -358,11 +360,8 @@ export const ContactApplicant = ({
setPreviewModal(false);
const attachments = await saveAttachments(files);
let callback = (_res: string) => {
setEditorValue("")
setCurrentTemplate(0)
setFiles([])
setShowEditor(false)
setEditMode(false);
clearcorrespondence();
changeCorrespondenceFilter("draft");
toast.success("Message has been saved to draft successfully", {
position: "top-right",
autoClose: 3000,
Expand Down Expand Up @@ -394,11 +393,8 @@ export const ContactApplicant = ({
dispatch,
callback,
(errorMessage: string) => {
setEditorValue("")
setCurrentTemplate(0)
setFiles([])
setShowEditor(false)
setEditMode(false);
clearcorrespondence();
changeCorrespondenceFilter("draft");
dispatch(fetchApplicantCorrespondence(requestId, ministryId));
},
);
Expand All @@ -415,11 +411,8 @@ export const ContactApplicant = ({
setPreviewModal(false);
const responseattachments = await saveAttachments(_files);
let callback = (_res: string) => {
setEditorValue("")
setCurrentTemplate(0)
setFiles([])
setShowEditor(false)
setEditMode(false);
clearcorrespondence();
changeCorrespondenceFilter("log");
dispatch(fetchApplicantCorrespondence(requestId, ministryId));
}
let data = {
Expand All @@ -431,28 +424,19 @@ export const ContactApplicant = ({
dispatch,
callback,
(errorMessage: string) => {
setEditorValue("")
setCurrentTemplate(0)
setFiles([])
setShowEditor(false)
setEditMode(false);
clearcorrespondence();
changeCorrespondenceFilter("log");
dispatch(fetchApplicantCorrespondence(requestId, ministryId));
},
);
setFOICorrespondenceLoader(false);
setDisablePreview(false);
}
setModal(false);
setEditorValue("")
setCurrentTemplate(0)
setFiles([])
setShowEditor(false)
setEditMode(false);
clearcorrespondence();
changeCorrespondenceFilter("log");
};

const editResponse = async () => {

}


const [correspondenceId, setCorrespondenceId] = useState(0);

Expand Down Expand Up @@ -486,13 +470,8 @@ export const ContactApplicant = ({
setDisablePreview(true);
setPreviewModal(false);
let callback = (_res: string) => {
setEditorValue("");
setCurrentTemplate(0);
setFiles([]);
setSelectedEmails([]);
setShowEditor(false)
setEditMode(false);
setDraftCorrespondence({});
clearcorrespondence();
changeCorrespondenceFilter("draft");
toast.success("Draft has been deleted successfully", {
position: "top-right",
autoClose: 3000,
Expand All @@ -508,13 +487,8 @@ export const ContactApplicant = ({
dispatch,
callback,
(errorMessage: string) => {
setEditorValue("");
setCurrentTemplate(0);
setFiles([]);
setSelectedEmails([]);
setShowEditor(false);
setEditMode(false);
setDraftCorrespondence({});
clearcorrespondence();
changeCorrespondenceFilter("draft");
dispatch(fetchApplicantCorrespondence(requestId, ministryId));
setFOICorrespondenceLoader(false);
setDisablePreview(false);
Expand All @@ -532,11 +506,8 @@ export const ContactApplicant = ({
setPreviewModal(false);
const attachments = await saveAttachments(files);
let callback = (_res: string) => {
setEditorValue("");
setCurrentTemplate(0);
setFiles([]);
setSelectedEmails([]);
setShowEditor(false);
clearcorrespondence();
changeCorrespondenceFilter("draft");
toast.success("Message has been saved to draft successfully", {
position: "top-right",
autoClose: 3000,
Expand Down Expand Up @@ -570,13 +541,8 @@ export const ContactApplicant = ({
callback,
(errorMessage: string) => {
errorToast(errorMessage);
setEditorValue("")
setCurrentTemplate(0)
setFiles([])
setShowEditor(false)
setEditMode(false);
setDraftCorrespondence({});
setSelectedEmails([]);
clearcorrespondence();
changeCorrespondenceFilter("draft");
dispatch(setFOICorrespondenceLoader(false));
},
);
Expand Down Expand Up @@ -627,6 +593,7 @@ export const ContactApplicant = ({
let templatesList;
const parser = new DOMParser();
let templateListItems = templates.map((template: any, index: any) => {
if (template.label !== "") {
let lastItemInList = false
if (templates.length === index + 1) lastItemInList = true;
const htmlEmail = parser.parseFromString(template.text, 'text/html');
Expand All @@ -643,15 +610,16 @@ export const ContactApplicant = ({
key={template.value}
>
<Grid container spacing={2}>
<Grid item xs={4}>
<Grid item xs={8}>
<ListItemText primary={template.label}/>
</Grid>
<Grid item xs={8}>
<ListItemText secondary={htmlEmailText?.slice(0,300) + ellipses} />
<Grid item xs={4}>
<ListItemText secondary={template.created_at}/>
</Grid>
</Grid>
</ListItem>
)
}
})
templatesList = (
<List>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface Template {
templateid: number;
text: string;
disabled: boolean;
created_at: string;
}

export type params = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ class applicantcorrespondenceservice:
def getapplicantcorrespondencetemplates(self):
""" Returns the active applicant correspondence templates
"""
return ApplicationCorrespondenceTemplate.getapplicantcorrespondencetemplates()
templates = ApplicationCorrespondenceTemplate.getapplicantcorrespondencetemplates()
for template in templates:
template["created_at"] = self.__pstformat(template['created_at'])
return templates

def gettemplatebyid(self, templateid):
""" Returns the active applicant correspondence templates
Expand Down Expand Up @@ -156,7 +159,7 @@ def __getjsonobject(self, correspondencemessagejson):
return data, True

def __getvaluefromjson(self, jsonobject, property):
return jsonobject[property] if jsonobject is not None else None
return jsonobject[property] if jsonobject is not None and property in jsonobject else None

def __pstformat(self, _date):
return maya.parse(_date).datetime(to_timezone='America/Vancouver', naive=False).strftime('%Y %b %d | %I:%M %p')
Expand Down

0 comments on commit b921d83

Please sign in to comment.