Skip to content

Commit

Permalink
Merge pull request #5284 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 19, 2024
2 parents afa967a + 46199b5 commit e766b47
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const PreviewModal = React.memo(({
innerhtml,
handleDraftSave,
attachments,
templateInfo
templateInfo,
enableSend
}: previewParams) => {

const dispatch = useDispatch();
Expand Down Expand Up @@ -96,7 +97,7 @@ export const PreviewModal = React.memo(({
/>
<button
className="btn-bottom btn-save"
disabled={(attachments?.length <= 0)}
disabled={!enableSend}
onClick={handleSend}
>
Send Email
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle';
import CloseIcon from '@material-ui/icons/Close';



export const ContactApplicant = ({
requestNumber,
requestState,
Expand Down Expand Up @@ -98,6 +100,34 @@ export const ContactApplicant = ({
const addCorrespondence = () => {
setShowEditor(true);
setModal(false);
setEditMode(false);
setFiles([]);
setEditorValue("");
setDraftCorrespondence({});
setSelectedEmails([]);
setCurrentTemplate(0);
}

const cancelCorrespondence = () => {
if (currentTemplate> 0) {
setOpenConfirmationModal(true);
setConfirmationFor("cancel-correspondence");
setConfirmationTitle("Cancel")
setConfirmationMessage("Any unsaved changes will be lost.Are you sure you want to proceed? ");
} else {
setShowEditor(false);
}
}

const clearcorrespondence = () => {
setShowEditor(false);
setModal(false);
setEditMode(false);
setFiles([]);
setEditorValue("");
setDraftCorrespondence({});
setSelectedEmails([]);
setCurrentTemplate(0);
}

const handleConfirmationClose = () => {
Expand All @@ -108,11 +138,13 @@ export const ContactApplicant = ({
}

const handleConfirmationContinue = () => {
setConfirmationFor("");
setConfirmationMessage("");
setOpenConfirmationModal(false);
if (confirmationFor === "delete-draft") {
setConfirmationFor("");
setConfirmationMessage("");
setOpenConfirmationModal(false);
deleteDraftAction();
deleteDraftAction();
} else if (confirmationFor === "cancel-correspondence") {
clearcorrespondence();
}
}

Expand Down Expand Up @@ -152,7 +184,8 @@ export const ContactApplicant = ({
const formHistory: Array<any> = useSelector((state: any) => state.foiRequests.foiRequestCFRFormHistory);
const approvedForm = formHistory?.find(form => form?.status?.toLowerCase() === 'approved');
const existingCorrespondence = applicantCorrespondence?.find((correspondence: any) => correspondence?.id === approvedForm?.cfrfeeid)
const previewButtonValue = existingCorrespondence ? "Preview & Resend" : "Preview & Send";
//const previewButtonValue = existingCorrespondence ? "Preview & Resend" : "Preview & Send";
const previewButtonValue = "Preview & Send";
const [editMode, setEditMode] = useState(false);
const draftButtonValue = editMode ? "Edit Draft" : "Save Draft";

Expand Down Expand Up @@ -427,6 +460,7 @@ export const ContactApplicant = ({
setEditMode(true);
setShowEditor(true);
setEditorValue(i.text);
setSelectedEmails(i.emails);
if (i.attachments)
setFiles(i.attachments);
setCorrespondenceId(i.applicantcorrespondenceid);
Expand All @@ -452,9 +486,10 @@ export const ContactApplicant = ({
setDisablePreview(true);
setPreviewModal(false);
let callback = (_res: string) => {
setEditorValue("")
setCurrentTemplate(0)
setFiles([])
setEditorValue("");
setCurrentTemplate(0);
setFiles([]);
setSelectedEmails([]);
setShowEditor(false)
setEditMode(false);
setDraftCorrespondence({});
Expand All @@ -473,10 +508,11 @@ export const ContactApplicant = ({
dispatch,
callback,
(errorMessage: string) => {
setEditorValue("")
setCurrentTemplate(0)
setFiles([])
setShowEditor(false)
setEditorValue("");
setCurrentTemplate(0);
setFiles([]);
setSelectedEmails([]);
setShowEditor(false);
setEditMode(false);
setDraftCorrespondence({});
dispatch(fetchApplicantCorrespondence(requestId, ministryId));
Expand All @@ -497,8 +533,9 @@ export const ContactApplicant = ({
const attachments = await saveAttachments(files);
let callback = (_res: string) => {
setEditorValue("");
setCurrentTemplate(0)
setFiles([])
setCurrentTemplate(0);
setFiles([]);
setSelectedEmails([]);
setShowEditor(false);
toast.success("Message has been saved to draft successfully", {
position: "top-right",
Expand Down Expand Up @@ -532,7 +569,14 @@ export const ContactApplicant = ({
dispatch,
callback,
(errorMessage: string) => {
errorToast(errorMessage)
errorToast(errorMessage);
setEditorValue("")
setCurrentTemplate(0)
setFiles([])
setShowEditor(false)
setEditMode(false);
setDraftCorrespondence({});
setSelectedEmails([]);
dispatch(setFOICorrespondenceLoader(false));
},
);
Expand Down Expand Up @@ -791,6 +835,7 @@ export const ContactApplicant = ({
ministryId={ministryId}
selectedEmails={selectedEmails}
setSelectedEmails={setSelectedEmails}
defaultEmail={requestDetails.email}
/>
</Grid>
</Grid>
Expand Down Expand Up @@ -835,12 +880,22 @@ export const ContactApplicant = ({
handleDraftSave={saveDraft}
attachments={files}
templateInfo={templates[currentTemplate]}
/>
enableSend={selectedEmails.length > 0}
/>
<button
className="btn addCorrespondence"
data-variant="contained"
onClick={cancelCorrespondence}
color="primary"
>
Cancel
</button>
<button
className="btn addCorrespondence"
data-variant="contained"
onClick={ editMode ? editCorrespondence : saveDraft}
color="primary"
disabled={(currentTemplate <= 0)}
>
{draftButtonValue}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export type previewParams = {
handleDraftSave: () => void;
attachments: Array<any>
templateInfo: any;
enableSend: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { saveCorrespondenceEmail, fetchCorrespondenceEmailList } from "../../../
import _ from 'lodash';
import TextField from "@material-ui/core/TextField";



const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
Expand Down Expand Up @@ -39,8 +41,11 @@ const useStyles = makeStyles((theme) => ({
export default function CorrespondenceEmail({
ministryId,
selectedEmails,
setSelectedEmails
}) {
setSelectedEmails,
defaultEmail
}) {


const classes = useStyles();
const dispatch = useDispatch();
const [newCorrespondenceEmail, setNewCorrespondenceEmail] = React.useState();
Expand All @@ -50,19 +55,31 @@ export default function CorrespondenceEmail({
React.useEffect(() => {
dispatch(
fetchCorrespondenceEmailList(ministryId, (_err, res) => {
setRequestemailList(res);

setRequestemailList( [{"email": defaultEmail}, ...res]);
})
);
},[ministryId])
);
},[ministryId, defaultEmail, dispatch])

const isEmailPresent = (email) => {
let hasMatch =false;
for (let requestemail of requestemailList) {
if(requestemail.email === email){
hasMatch = true;
break;
}
}
return hasMatch;
}

const handleEmailSave = (e) => {
if (newCorrespondenceEmail && !isEmailPresent(newCorrespondenceEmail)) {
dispatch(
saveCorrespondenceEmail(ministryId, {"email": newCorrespondenceEmail}, (_err, res) => {
setRequestemailList((oldArray) => [...oldArray, {"email": newCorrespondenceEmail}]);
setNewCorrespondenceEmail("");
})
);
);
}
}

const handleChange = (event) => {
Expand Down Expand Up @@ -110,7 +127,7 @@ export default function CorrespondenceEmail({
onChange={handleNewCorrespondenceEmailChange}
/>
<div>
<button className="btn-bottom btn-save" onClick={handleEmailSave}>
<button className="btn-bottom btn-save" onClick={handleEmailSave} disabled={!newCorrespondenceEmail || isEmailPresent(newCorrespondenceEmail)}>
Save
</button>
</div>
Expand All @@ -126,7 +143,7 @@ export default function CorrespondenceEmail({
return (
<>
<div>
<div className="foi-watcher-all">
<div className="foi-email-all">
<button className="foi-eye-container email-correspondence-button"> <i className="fa fa-envelope"></i> Email To</button>
<div className="foi-watcher-select">
<i className="fa fa-user-o"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
width: 188px;
}

.foi-email-all {
padding-top: 5px;
display: flex;
width: 188px;
}

.foi-watcher-select {
padding-top: 8px;
width: 100px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .default_method_result import DefaultMethodResult
from sqlalchemy.sql.expression import distinct
from sqlalchemy import or_,and_,text
import logging

class FOIApplicantCorrespondenceEmail(db.Model):
# Name of the table in our database
Expand Down Expand Up @@ -34,6 +35,24 @@ def saveapplicantcorrespondenceemail(cls, applicantcorrespondenceid, corresponde
db.session.commit()
return DefaultMethodResult(True,'applicant correpondence emails are added', applicantcorrespondenceid)

@classmethod
def getapplicantcorrespondenceemails(cls,ministryrequestid):
correspondence_emails = []
try:
sql = """select correspondence_to,
applicantcorrespondence_id, applicantcorrespondence_version from "FOIApplicantCorrespondenceEmails" fce join "FOIApplicantCorrespondences" fc
on fce.applicantcorrespondence_id = fc.applicantcorrespondenceid and fce.applicantcorrespondence_version = fc."version"
where fc.foiministryrequest_id = :ministryrequestid;"""
rs = db.session.execute(text(sql), {'ministryrequestid': ministryrequestid})
for row in rs:
correspondence_emails.append({"correspondence_to": row["correspondence_to"], "applicantcorrespondence_id": row["applicantcorrespondence_id"],
"applicantcorrespondence_version": row["applicantcorrespondence_version"]})
except Exception as ex:
logging.error(ex)
raise ex
finally:
db.session.close()
return correspondence_emails

class FOIApplicantCorrespondenceEmailSchema(ma.Schema):
class Meta:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def getcorrespondenceemails(cls,ministryrequestid):
query = db.session.query(FOICorrespondenceEmail.email).filter(FOICorrespondenceEmail.foiministryrequest_id == ministryrequestid).order_by(FOICorrespondenceEmail.email.desc()).all()
return email_schema.dump(query)



@classmethod
def savecorrespondenceemail(cls,correpondenceemail)->DefaultMethodResult:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from request_api.models.FOIApplicantCorrespondences import FOIApplicantCorrespondence
from request_api.models.FOIApplicantCorrespondenceAttachments import FOIApplicantCorrespondenceAttachment
from request_api.models.FOIApplicantCorrespondenceResponses import FOIApplicantCorrespondenceResponse
from request_api.models.FOIApplicantCorrespondenceEmails import FOIApplicantCorrespondenceEmail

from request_api.models.FOIMinistryRequests import FOIMinistryRequest

import maya
Expand All @@ -25,6 +27,7 @@ def getapplicantcorrespondencelogs(self,ministryrequestid):
"""
_correspondencelogs = FOIApplicantCorrespondence.getapplicantcorrespondences(ministryrequestid)
_correspondenceattachments = FOIApplicantCorrespondenceAttachment.getcorrespondenceattachmentsbyministryid(ministryrequestid)
_correspondenceemails = FOIApplicantCorrespondenceEmail.getapplicantcorrespondenceemails(ministryrequestid)
correspondencelogs =[]
for _correpondencelog in _correspondencelogs:
attachments = []
Expand All @@ -36,12 +39,17 @@ def getapplicantcorrespondencelogs(self,ministryrequestid):
}
attachments.append(attachment)
correpondencelog = self.__createcorrespondencelog(_correpondencelog, attachments)
#Email block - Begin
correpondencelog['emails'] = self.__getcorrespondenceemailbyid(_correspondenceemails, _correpondencelog['applicantcorrespondenceid'], _correpondencelog['version'])
#Email block - End
correspondencelogs.append(correpondencelog)
return correspondencelogs

def __getattachmentsbyid(self, attachments, correspondenceid, correspondenceversion):
return [x for x in attachments if x['applicantcorrespondenceid'] == correspondenceid and x['applicantcorrespondence_version'] == correspondenceversion]

def __getcorrespondenceemailbyid(self, emails, correspondenceid, correspondenceversion):
return [x['correspondence_to'] for x in emails if x['applicantcorrespondence_id'] == correspondenceid and x['applicantcorrespondence_version'] == correspondenceversion]

def saveapplicantcorrespondencelog(self, requestid, ministryrequestid, data, userid, isdraft=False):
applicantcorrespondence = FOIApplicantCorrespondence()
Expand Down

0 comments on commit e766b47

Please sign in to comment.