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/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..b0056368b 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} />
-
@@ -126,7 +143,7 @@ export default function CorrespondenceEmail({ return ( <>
-
+
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; 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()