Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1249 Submit project details for new project #1292

Closed
wants to merge 9 commits into from
4 changes: 2 additions & 2 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -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*
Expand Down
64 changes: 0 additions & 64 deletions client/app/components/packages/projects/new.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@
Planning will contact you with the next steps.
</p>
</section>
<Packages::Projects::ProjectsNewInformation @form={{saveableProjectsNewForm}} />
<Projects::ProjectsNewInformation
@project={{saveableProjectsNewForm.data}}
@form={{saveableProjectsNewForm}}
@boroughOptions={{this.boroughOptions}}
@onBoroughChange={{this.handleBoroughChange}}
@selectedBorough={{this.selectedBorough}}
@onApplicantTypeSelection={{this.handleApplicantTypeChange}}
@selectedApplicantType={{this.selectedApplicantType}}
@applicantOptions={{this.applicantOptions}}
/>
<Projects::ProjectsNewAddContacts
@form={{saveableProjectsNewForm}} />
</div>

<div class="cell large-4 sticky-sidebar">
<saveableProjectsNewForm.PageNav>
<saveableProjectsNewForm.SubmitButton @isEnabled={{saveableProjectsNewForm.isSubmittable}} data-test-save-button />
</saveableProjectsNewForm.PageNav>
<saveableProjectsNewForm.ConfirmationModal @action={{component saveableProjectsNewForm.SubmitButton
isEnabled=saveableProjectsNewForm.isSubmittable onClick=this.submitPackage class="no-margin" }}
isEnabled=saveableProjectsNewForm.isSubmittable onClick=this.submitProject class="no-margin" }}
@continueButtonTitle="Continue Editing" data-test-confirm-submit-button={{true}}>
<h6>Confirm New Project Submission</h6>
<p class="header-large medium-margin-top small-margin-bottom">
Expand Down
127 changes: 127 additions & 0 deletions client/app/components/projects/new.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
{{#let @form as |form|}}
<form.Section @title="Project Information">
<Ui::Question @required={{true}} as |Q|>
<Q.Label>
Project Name
</Q.Label>

<form.Field
@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>
Expand Down Expand Up @@ -76,7 +61,8 @@
<h3>Applicant</h3>
<p>The owner, entity, or representative of the project described in this application.</p>
<p class="q-help">
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: <b>First Name:</b> NYC, <b>Last Name:</b> Planning
</p>
<Ui::Question @required={{true}} as |Q|>
Expand Down
64 changes: 64 additions & 0 deletions client/app/components/projects/projects-new-information.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{{#let @form as |form|}}
<form.Section @title='Project Information'>
<Ui::Question @required={{true}} as |Q|>
<Q.Label>
Project Name
</Q.Label>
<form.Field
@attribute='projectName'
@type='text-input'
id={{Q.questionId}}
@showCounter={{true}}
@maxlength='50'
placeholder="project name"
/>
</Ui::Question>
<Ui::Question @required={{true}} as |Q|>
<Q.Label data-test-projects-new-borough-dropdown>
Borough
</Q.Label>
<PowerSelect
supportsDataTestProperties={{true}}
@attribute='borough'
@options={{@boroughOptions}}
@onChange={{fn (mut @project.borough)}}
@selected={{@project.borough}}
@searchField='label'
data-test-id='project-new-borough-dropdown'
@placeholder='select a borough' as |borough|>
{{borough.label}}
</PowerSelect>
{{#if form.errors.borough}}
{{#each form.errors.borough.validation as |message|}}
<div class="form-error is-visible" data-test-validation-message="select a borough">{{message}}</div>
{{/each}}
{{/if}}
</Ui::Question>
<Ui::Question @required={{true}} as |Q|>
<Q.Label data-test-projects-new-applicant-type>
Applicant Type
</Q.Label>
<p class='q-help'>
Identify if you represent a public agency or are a private entity.
</p>
<PowerSelect
supportsDataTestProperties={{true}}
@attribute='applicantType'
@options={{@applicantOptions}}
@onChange={{fn (mut @project.applicantType)}}
@selected={{@project.applicantType}}
@searchField='label'
data-test-id='projects-new-applicant-type'
@placeholder='select applicant type' as |dcpApplicantType| >
{{dcpApplicantType.label}}
</PowerSelect>
{{#if form.errors.applicantType}}
{{#each form.errors.applicantType.validation as |message|}}
<div class="form-error is-visible" data-test-validation-message="select an Applicant Type"> {{message}}
</div>
{{/each}}
{{/if}}
</Ui::Question>
</form.Section>
{{/let}}

Loading
Loading