From c372e5f80812455df5c5c463e081388fb30781c3 Mon Sep 17 00:00:00 2001 From: "sumathi.thirumani" Date: Wed, 19 Jun 2024 00:29:02 -0700 Subject: [PATCH 1/2] Email checks to enable send + add applicant email as default first element. --- .../ContactApplicant/index.tsx | 30 ++++++++++++++--- .../ContactApplicant/types.ts | 1 + .../customComponents/CorrespondenceEmail.js | 33 ++++++++++++++----- .../FOIApplicantCorrespondenceEmails.py | 19 +++++++++++ .../models/FOICorrespondenceEmails.py | 2 ++ .../applicantcorrespondencelog.py | 8 +++++ 6 files changed, 81 insertions(+), 12 deletions(-) diff --git a/forms-flow-web/src/components/FOI/customComponents/ContactApplicant/index.tsx b/forms-flow-web/src/components/FOI/customComponents/ContactApplicant/index.tsx index 6c68764dd..c753789dc 100644 --- a/forms-flow-web/src/components/FOI/customComponents/ContactApplicant/index.tsx +++ b/forms-flow-web/src/components/FOI/customComponents/ContactApplicant/index.tsx @@ -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, @@ -96,8 +98,15 @@ export const ContactApplicant = ({ } const addCorrespondence = () => { + console.log(requestDetails); setShowEditor(true); setModal(false); + setEditMode(false); + setFiles([]); + setEditorValue(""); + setDraftCorrespondence({}); + setSelectedEmails([]); + setCurrentTemplate(0); } const handleConfirmationClose = () => { @@ -152,7 +161,8 @@ export const ContactApplicant = ({ const formHistory: Array = 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"; @@ -427,6 +437,7 @@ export const ContactApplicant = ({ setEditMode(true); setShowEditor(true); setEditorValue(i.text); + setSelectedEmails(i.emails); if (i.attachments) setFiles(i.attachments); setCorrespondenceId(i.applicantcorrespondenceid); @@ -497,8 +508,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", @@ -532,7 +544,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)); }, ); @@ -791,6 +810,7 @@ export const ContactApplicant = ({ ministryId={ministryId} selectedEmails={selectedEmails} setSelectedEmails={setSelectedEmails} + defaultEmail={requestDetails.email} /> @@ -835,12 +855,14 @@ export const ContactApplicant = ({ handleDraftSave={saveDraft} attachments={files} templateInfo={templates[currentTemplate]} + enableSend={selectedEmails.length > 0} /> diff --git a/forms-flow-web/src/components/FOI/customComponents/ContactApplicant/types.ts b/forms-flow-web/src/components/FOI/customComponents/ContactApplicant/types.ts index 63bb89602..cd4f81500 100644 --- a/forms-flow-web/src/components/FOI/customComponents/ContactApplicant/types.ts +++ b/forms-flow-web/src/components/FOI/customComponents/ContactApplicant/types.ts @@ -29,4 +29,5 @@ export type previewParams = { handleDraftSave: () => void; attachments: Array templateInfo: any; + enableSend: boolean; } diff --git a/forms-flow-web/src/components/FOI/customComponents/CorrespondenceEmail.js b/forms-flow-web/src/components/FOI/customComponents/CorrespondenceEmail.js index 3da1ad318..162c6e553 100644 --- a/forms-flow-web/src/components/FOI/customComponents/CorrespondenceEmail.js +++ b/forms-flow-web/src/components/FOI/customComponents/CorrespondenceEmail.js @@ -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 = { @@ -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(); @@ -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) => { @@ -110,7 +127,7 @@ export default function CorrespondenceEmail({ onChange={handleNewCorrespondenceEmailChange} />
-
diff --git a/request-management-api/request_api/models/FOIApplicantCorrespondenceEmails.py b/request-management-api/request_api/models/FOIApplicantCorrespondenceEmails.py index 9f756a1b2..294f1aa57 100644 --- a/request-management-api/request_api/models/FOIApplicantCorrespondenceEmails.py +++ b/request-management-api/request_api/models/FOIApplicantCorrespondenceEmails.py @@ -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 @@ -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: diff --git a/request-management-api/request_api/models/FOICorrespondenceEmails.py b/request-management-api/request_api/models/FOICorrespondenceEmails.py index 74bace7b5..ed6e507be 100644 --- a/request-management-api/request_api/models/FOICorrespondenceEmails.py +++ b/request-management-api/request_api/models/FOICorrespondenceEmails.py @@ -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: diff --git a/request-management-api/request_api/services/applicantcorrespondence/applicantcorrespondencelog.py b/request-management-api/request_api/services/applicantcorrespondence/applicantcorrespondencelog.py index 2fd4b6856..ab5a9b66f 100644 --- a/request-management-api/request_api/services/applicantcorrespondence/applicantcorrespondencelog.py +++ b/request-management-api/request_api/services/applicantcorrespondence/applicantcorrespondencelog.py @@ -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 @@ -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 = [] @@ -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() From 46199b57f146bc3834279249cef5b62f494e9b7d Mon Sep 17 00:00:00 2001 From: "sumathi.thirumani" Date: Wed, 19 Jun 2024 08:47:15 -0700 Subject: [PATCH 2/2] Changes to validations of correspondence --- .../ContactApplicant/PreviewModal.tsx | 5 +- .../ContactApplicant/index.tsx | 59 +++++++++++++++---- .../customComponents/CorrespondenceEmail.js | 2 +- .../customComponents/CorrespondenceEmail.scss | 6 ++ 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/forms-flow-web/src/components/FOI/customComponents/ContactApplicant/PreviewModal.tsx b/forms-flow-web/src/components/FOI/customComponents/ContactApplicant/PreviewModal.tsx index 6371a45b1..87f269df7 100644 --- a/forms-flow-web/src/components/FOI/customComponents/ContactApplicant/PreviewModal.tsx +++ b/forms-flow-web/src/components/FOI/customComponents/ContactApplicant/PreviewModal.tsx @@ -22,7 +22,8 @@ export const PreviewModal = React.memo(({ innerhtml, handleDraftSave, attachments, - templateInfo + templateInfo, + enableSend }: previewParams) => { const dispatch = useDispatch(); @@ -96,7 +97,7 @@ export const PreviewModal = React.memo(({ />
diff --git a/forms-flow-web/src/components/FOI/customComponents/CorrespondenceEmail.scss b/forms-flow-web/src/components/FOI/customComponents/CorrespondenceEmail.scss index ed6d7e2b7..42745ec77 100644 --- a/forms-flow-web/src/components/FOI/customComponents/CorrespondenceEmail.scss +++ b/forms-flow-web/src/components/FOI/customComponents/CorrespondenceEmail.scss @@ -44,6 +44,12 @@ width: 188px; } +.foi-email-all { + padding-top: 5px; + display: flex; + width: 188px; +} + .foi-watcher-select { padding-top: 8px; width: 100px;