From 7e2d1280a53cf8de25434c39f0c1737e93f5a93f Mon Sep 17 00:00:00 2001 From: tangoyankee Date: Sat, 12 Oct 2024 14:42:59 -0400 Subject: [PATCH] Submit contact details Request the creation of a new contact if it does not exist closes #1248 Co-authored-by: horatio --- .../app/components/packages/projects/new.js | 46 ++++++- .../projects/projects-new-information.hbs | 120 +++++++++++++++++- client/app/models/project.js | 4 - client/app/routes/projects/new.js | 12 +- .../submittable-projects-new-form.js | 101 ++++++++++++++- 5 files changed, 271 insertions(+), 12 deletions(-) diff --git a/client/app/components/packages/projects/new.js b/client/app/components/packages/projects/new.js index 0c688125..9d68fd65 100644 --- a/client/app/components/packages/projects/new.js +++ b/client/app/components/packages/projects/new.js @@ -3,7 +3,6 @@ import { action } from '@ember/object'; import { inject as service } from '@ember/service'; import SubmittableProjectsNewForm from '../../../validations/submittable-projects-new-form'; - export default class ProjectsNewFormComponent extends Component { validations = { SubmittableProjectsNewForm, @@ -17,10 +16,49 @@ export default class ProjectsNewFormComponent extends Component { @action async submitPackage() { + const primaryContactInput = { + first: this.args.package.primaryContactFirstName, + last: this.args.package.primaryContactLastName, + email: this.args.package.primaryContactEmail, + phone: this.args.package.primaryContactPhone, + role: 'contact', + }; + + const applicantInput = { + first: this.args.package.applicantFirstName, + last: this.args.package.applicantLastName, + email: this.args.package.applicantEmail, + phone: this.args.package.applicantPhone, + role: 'applicant', + }; + + const contactInputs = [primaryContactInput, applicantInput]; try { - await this.args.package.submit(); - } catch (error) { - console.log('Save new project package error:', error); + const contactPromises = contactInputs + .map((contact) => this.store.queryRecord('contact', + { + email: contact.email, + includeAllStatusCodes: true, + })); + + const contacts = await Promise.all(contactPromises); + + const verifiedContactPromises = contacts.map((contact, index) => { + if (contact.id === '-1') { + const contactInput = contactInputs[index]; + const contactModel = this.store.createRecord('contact', { + firstname: contactInput.first, + lastname: contactInput.last, + emailaddress1: contactInput.email, + telephone1: contactInput.phone, + }); + return contactModel.save(); + } + return contact; + }); + await Promise.all(verifiedContactPromises); + } catch { + console.log('Save new project package error'); } } } diff --git a/client/app/components/packages/projects/projects-new-information.hbs b/client/app/components/packages/projects/projects-new-information.hbs index 7cd975ef..f0ebc796 100644 --- a/client/app/components/packages/projects/projects-new-information.hbs +++ b/client/app/components/packages/projects/projects-new-information.hbs @@ -1,18 +1,134 @@ {{#let @form as |form|}} - Project Name + + + +

Primary Contact

+

This contact is the person who will respond to public inquiries regarding the application.

+ + + First Name + + + + + + + Last Name + + + + + + + Email + + + + + + Phone + +

+ No dashes, parentheses, or special characters. +

+ + +
+ +

Applicant

+

The owner, entity, or representative of the project described in this application.

+ + + First Name + + + + + + + Last Name + + + + + + + Email + + + + + + + Phone + +

+ No dashes, parentheses, or special characters. +

+ + +
{{/let}} \ No newline at end of file diff --git a/client/app/models/project.js b/client/app/models/project.js index d3302998..dcf7ae07 100644 --- a/client/app/models/project.js +++ b/client/app/models/project.js @@ -233,8 +233,4 @@ export default class ProjectModel extends Model { .sortBy('dcpPackageversion') .reverse(); } - - async submit() { - await super.save(); - } } diff --git a/client/app/routes/projects/new.js b/client/app/routes/projects/new.js index 4483eec6..d2673806 100644 --- a/client/app/routes/projects/new.js +++ b/client/app/routes/projects/new.js @@ -6,6 +6,16 @@ export default class ProjectsNewRoute extends Route.extend(AuthenticatedRouteMix @service store; async model() { - return await this.store.createRecord('project'); + return { + projectName: '', + primaryContactFirstName: '', + primaryContactLastName: '', + primaryContactEmail: '', + primaryContactPhone: '', + applicantFirstName: '', + applicantLastName: '', + applicantEmail: '', + applicantPhone: '', + }; } } diff --git a/client/app/validations/submittable-projects-new-form.js b/client/app/validations/submittable-projects-new-form.js index 2c00a391..a532a024 100644 --- a/client/app/validations/submittable-projects-new-form.js +++ b/client/app/validations/submittable-projects-new-form.js @@ -1,10 +1,109 @@ import { + validateFormat, validateLength, validatePresence, } from 'ember-changeset-validations/validators'; export default { - dcpProjectname: [ + primaryContactFirstName: [ + validateLength({ + min: 0, + max: 50, + message: 'Text is too long (max {max} characters)', + }), + validatePresence({ + presence: true, + message: 'This field is required', + }), + ], + primaryContactLastName: [ + validateLength({ + min: 0, + max: 50, + message: 'Text is too long (max {max} characters)', + }), + validatePresence({ + presence: true, + message: 'This field is required', + }), + ], + primaryContactEmail: [ + validateLength({ + min: 0, + max: 50, + message: 'Text is too long (max {max} characters)', + }), + validatePresence({ + presence: true, + message: 'This field is required', + }), + validateFormat({ + type: 'email', + // Set allowBlank=true so that the validation message + // only appears after user first types something. + // This field still indicates it is 'required' + // through validatePresence + allowBlank: true, + message: 'Must be a valid email address', + }), + ], + primaryContactPhone: [ + validateLength({ + min: 0, + max: 10, + message: 'Text is too long (max {max} characters)', + }), + ], + applicantFirstName: [ + validateLength({ + min: 0, + max: 50, + message: 'Text is too long (max {max} characters)', + }), + validatePresence({ + presence: true, + message: 'This field is required', + }), + ], + applicantLastName: [ + validateLength({ + min: 0, + max: 50, + message: 'Text is too long (max {max} characters)', + }), + validatePresence({ + presence: true, + message: 'This field is required', + }), + ], + applicantEmail: [ + validateLength({ + min: 0, + max: 50, + message: 'Text is too long (max {max} characters)', + }), + validatePresence({ + presence: true, + message: 'This field is required', + }), + validateFormat({ + type: 'email', + // Set allowBlank=true so that the validation message + // only appears after user first types something. + // This field still indicates it is 'required' + // through validatePresence + allowBlank: true, + message: 'Must be a valid email address', + }), + ], + applicantPhone: [ + validateLength({ + min: 0, + max: 10, + message: 'Text is too long (max {max} characters)', + }), + ], + projectName: [ validateLength({ min: 0, max: 50,