diff --git a/client/.gitignore b/client/.gitignore index 5108621b..3da6f6e2 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -1,12 +1,12 @@ # See https://help.github.com/ignore-files/ for more about ignoring files. # compiled output -/dist/ +**/dist /tmp/ # dependencies /bower_components/ -/node_modules/ +**/node_modules # misc /.env* diff --git a/client/app/components/packages/projects/new.js b/client/app/components/packages/projects/new.js deleted file mode 100644 index 9d68fd65..00000000 --- a/client/app/components/packages/projects/new.js +++ /dev/null @@ -1,64 +0,0 @@ -import Component from '@glimmer/component'; -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, - }; - - @service - router; - - @service - store; - - @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 { - 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/new.hbs b/client/app/components/projects/new.hbs similarity index 76% rename from client/app/components/packages/projects/new.hbs rename to client/app/components/projects/new.hbs index 589721b5..b3c0a282 100644 --- a/client/app/components/packages/projects/new.hbs +++ b/client/app/components/projects/new.hbs @@ -20,15 +20,25 @@ Planning will contact you with the next steps.
-diff --git a/client/app/components/projects/new.js b/client/app/components/projects/new.js new file mode 100644 index 00000000..a6f8c7aa --- /dev/null +++ b/client/app/components/projects/new.js @@ -0,0 +1,127 @@ +/* eslint-disable no-console */ +import Component from '@glimmer/component'; +import { action } from '@ember/object'; +import { inject as service } from '@ember/service'; +import SubmittableProjectsNewForm from '../../validations/submittable-projects-new-form'; +import { optionset } from '../../helpers/optionset'; +import { DCPAPPLICANTROLE } from '../../optionsets/project-applicant'; + +export default class ProjectsNewFormComponent extends Component { + validations = { + SubmittableProjectsNewForm, + }; + + @service + router; + + @service + store; + + get boroughOptions() { + return optionset(['project', 'boroughs', 'list']); + } + + get applicantOptions() { + return optionset(['applicant', 'dcpApplicantType', 'list']); + } + + @action + async submitProject() { + const projectInformation = { + projectName: this.args.package.projectName, + borough: this.args.package.borough.code, + applicantType: this.args.package.applicantType.code, + }; + + const primaryContactInput = { + first: this.args.package.primaryContactFirstName, + last: this.args.package.primaryContactLastName, + email: this.args.package.primaryContactEmail, + phone: this.args.package.primaryContactPhone, + role: DCPAPPLICANTROLE.PRIMARY_CONTACT.code, + }; + + const applicantInput = { + first: this.args.package.applicantFirstName, + last: this.args.package.applicantLastName, + email: this.args.package.applicantEmail, + phone: this.args.package.applicantPhone, + role: DCPAPPLICANTROLE.PRIMARY_APPLICANT.code, + }; + + const contactInputs = [primaryContactInput, applicantInput]; + + try { + const projectModel = this.store.createRecord('project', { + dcpProjectname: projectInformation.projectName, + dcpBorough: projectInformation.borough, + dcpApplicanttype: projectInformation.applicantType, + }); + + await projectModel.save(); + + const projects = await this.store.findAll('project'); + const sortedProjects = projects.sortBy('createdAt').reverse(); + const mostRecentProject = sortedProjects.get('firstObject'); + + console.log('Resolved most recent project:', mostRecentProject); + + 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; + }); + + const verifiedContacts = await Promise.all(verifiedContactPromises); + + const applicantRoleCodes = [ + DCPAPPLICANTROLE.PRIMARY_CONTACT.code, + DCPAPPLICANTROLE.PRIMARY_APPLICANT.code, + ]; + + const applicants = applicantRoleCodes.map((code) => { + const applicant = this.store.createRecord('project-applicant', { + dcpApplicantrole: code, + }); + const input = contactInputs.find((input) => input.role === code); + if (input === undefined) throw new Error('Applicant role not found'); + const { email } = input; + const contact = verifiedContacts.find((contact) => contact.emailaddress1 === email); + if (contact === undefined) throw new Error('Contact for applicant role not found'); + applicant.contact = contact; + return applicant; + }); + + console.log('applicants', applicants); + + applicants.forEach( + (applicant) => mostRecentProject.projectApplicants.pushObject(applicant), + ); + applicants.forEach((applicant) => { + applicant.mostRecentProject = mostRecentProject; + applicant.save(); + }); + + await mostRecentProject.save(); + } catch (error) { + console.log('Save new project package error', error.message); + console.log('the error', error); + } + } +} diff --git a/client/app/components/packages/projects/projects-new-information.hbs b/client/app/components/projects/projects-new-add-contacts.hbs similarity index 87% rename from client/app/components/packages/projects/projects-new-information.hbs rename to client/app/components/projects/projects-new-add-contacts.hbs index 50a16594..d09319e5 100644 --- a/client/app/components/packages/projects/projects-new-information.hbs +++ b/client/app/components/projects/projects-new-add-contacts.hbs @@ -1,19 +1,4 @@ {{#let @form as |form|}} -
This contact is the person who will respond to public inquiries regarding the application.
@@ -76,7 +61,8 @@The owner, entity, or representative of the project described in this application.
- If using a company or organization, please split the name in the "First Name" and "Last Name" fields. For example, "NYC + If using a company or organization, please split the name in the "First Name" and "Last Name" fields. For example, + "NYC Planning" would be: First Name: NYC, Last Name: Planning
+ Identify if you represent a public agency or are a private entity. +
+