Skip to content

Commit

Permalink
Submit contact details
Browse files Browse the repository at this point in the history
Request the creation of a new contact if it does not exist

closes #1248

Co-authored-by: horatio <[email protected]>
  • Loading branch information
TangoYankee and horatiorosa committed Oct 18, 2024
1 parent dcd5e9c commit 7e2d128
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 12 deletions.
46 changes: 42 additions & 4 deletions client/app/components/packages/projects/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');

Check warning on line 61 in client/app/components/packages/projects/new.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Unexpected console statement

Check warning on line 61 in client/app/components/packages/projects/new.js

View workflow job for this annotation

GitHub Actions / 🧪 Test client code

Unexpected console statement
}
}
}
120 changes: 118 additions & 2 deletions client/app/components/packages/projects/projects-new-information.hbs
Original file line number Diff line number Diff line change
@@ -1,18 +1,134 @@
{{#let @form as |form|}}
<form.Section @title="Project Information">

<Ui::Question @required={{true}} as |Q|>
<Q.Label>
Project Name
</Q.Label>

<form.Field
@attribute="dcpProjectname"
@attribute="projectName"
@type="text-input"
id={{Q.questionId}}
@showCounter={{true}}
@maxlength="50"
/>
</Ui::Question>
</form.Section>
<form.Section @title="Contact Information">
<h3>Primary Contact</h3>
<p>This contact is the person who will respond to public inquiries regarding the application.</p>
<Ui::Question @required={{true}} as |Q|>
<Q.Label>
First Name
</Q.Label>

<form.Field
@attribute="primaryContactFirstName"
@type="text-input"
id={{Q.questionId}}
@showCounter={{true}}
@maxlength="50"
/>
</Ui::Question>
<Ui::Question @required={{true}} as |Q|>
<Q.Label>
Last Name
</Q.Label>

<form.Field
@attribute="primaryContactLastName"
@type="text-input"
id={{Q.questionId}}
@showCounter={{true}}
@maxlength="50"
/>
</Ui::Question>
<Ui::Question @required={{true}} as |Q|>
<Q.Label>
Email
</Q.Label>

<form.Field
@attribute="primaryContactEmail"
@type="text-input"
id={{Q.questionId}}
@showCounter={{true}}
@maxlength="50"
/>
</Ui::Question>
<Ui::Question @required={{false}} as |Q|>
<Q.Label>
Phone
</Q.Label>
<p class="q-help">
No dashes, parentheses, or special characters.
</p>

<form.Field
@attribute="primaryContactPhone"
@type="text-input"
id={{Q.questionId}}
@showCounter={{true}}
@maxlength="10"
/>
</Ui::Question>

<h3>Applicant</h3>
<p>The owner, entity, or representative of the project described in this application.</p>
<Ui::Question @required={{true}} as |Q|>
<Q.Label>
First Name
</Q.Label>

<form.Field
@attribute="applicantFirstName"
@type="text-input"
id={{Q.questionId}}
@showCounter={{true}}
@maxlength="50"
/>
</Ui::Question>
<Ui::Question @required={{true}} as |Q|>
<Q.Label>
Last Name
</Q.Label>

<form.Field
@attribute="applicantLastName"
@type="text-input"
id={{Q.questionId}}
@showCounter={{true}}
@maxlength="50"
/>
</Ui::Question>
<Ui::Question @required={{true}} as |Q|>
<Q.Label>
Email
</Q.Label>

<form.Field
@attribute="applicantEmail"
@type="text-input"
id={{Q.questionId}}
@showCounter={{true}}
@maxlength="50"
/>
</Ui::Question>
<Ui::Question @required={{false}} as |Q|>
<Q.Label>
Phone
</Q.Label>
<p class="q-help">
No dashes, parentheses, or special characters.
</p>

<form.Field
@attribute="applicantPhone"
@type="text-input"
id={{Q.questionId}}
@showCounter={{true}}
@maxlength="10"
/>
</Ui::Question>
</form.Section>
{{/let}}
4 changes: 0 additions & 4 deletions client/app/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,4 @@ export default class ProjectModel extends Model {
.sortBy('dcpPackageversion')
.reverse();
}

async submit() {
await super.save();
}
}
12 changes: 11 additions & 1 deletion client/app/routes/projects/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
};
}
}
101 changes: 100 additions & 1 deletion client/app/validations/submittable-projects-new-form.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 7e2d128

Please sign in to comment.