Skip to content

Commit

Permalink
1249 Submit project details for new project
Browse files Browse the repository at this point in the history
 - refactored projects-new-information.hbs
   -  extracted all contact form fields into a new template: projects-new-add-contacts.hbs
 - added boroughs to projects-new-information template using ember powerselect
 - added functions to projects/new..js to handle dropdown actions
 - updated project optionset to include boroughs and imported into optionsets.js
  • Loading branch information
horatiorosa authored and TangoYankee committed Nov 7, 2024
1 parent 4f21199 commit 34ac7fe
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
Planning will contact you with the next steps.
</p>
</section>
<Packages::Projects::ProjectsNewInformation
<Projects::ProjectsNewInformation
@project={{saveableProjectsNewForm.data}}
@form={{saveableProjectsNewForm}}
@boroughOptions={{this.boroughOptions}}
@onBoroughChange={{this.handleBoroughChange}}
Expand All @@ -29,15 +30,15 @@
@selectedApplicantType={{this.selectedApplicantType}}
@applicantOptions={{this.applicantOptions}}
/>
<Packages::Projects::ProjectsNewAddContacts
<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
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/* eslint-disable no-console */
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import fetch from 'fetch';
import SubmittableProjectsNewForm from '../../../validations/submittable-projects-new-form';
import { optionset } from '../../../helpers/optionset';
import config from '../../../config/environment';

import SubmittableProjectsNewForm from '../../validations/submittable-projects-new-form';
import { optionset } from '../../helpers/optionset';
import config from '../../config/environment';

export default class ProjectsNewFormComponent extends Component {
validations = {
Expand All @@ -19,12 +17,6 @@ export default class ProjectsNewFormComponent extends Component {
@service
store;

@tracked
selectedBorough = null;

@tracked
selectedApplicantType = null;

get boroughOptions() {
return optionset(['project', 'boroughs', 'list']);
}
Expand All @@ -34,51 +26,29 @@ export default class ProjectsNewFormComponent extends Component {
}

@action
handleBoroughChange(selectedBorough) {
console.log('Selected borough:', selectedBorough);

this.selectedBorough = selectedBorough;

if (this.args.form) {
this.args.form.set('borough', selectedBorough);
}
}

@action
handleApplicantTypeChange(selectedApplicantType) {
console.log('Selected Applicant Type:', selectedApplicantType);

this.selectedApplicantType = selectedApplicantType;

if (this.args.form) {
this.args.form.set('dcpApplicantType', selectedApplicantType);
}
}

@action
async submitPackage() {
async submitProject() {
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 contactPromises = contactInputs.map((contact) => this.store.queryRecord('contact',
{
email: contact.email,
includeAllStatusCodes: true,
}));

const contacts = await Promise.all(contactPromises);

Expand All @@ -95,6 +65,7 @@ export default class ProjectsNewFormComponent extends Component {
}
return contact;
});

const [verifiedPrimaryContact, verifiedApplicant] = await Promise.all(verifiedContactPromises);

const authSessionRaw = localStorage.getItem('ember_simple_auth-session');
Expand All @@ -119,18 +90,18 @@ export default class ProjectsNewFormComponent extends Component {
data: {
attributes: {
dcpProjectname: this.args.package.projectName,
dcpBorough: this.selectedBorough.code,
dcpApplicanttype: this.selectedApplicantType.code,
dcpBorough: this.args.package.borough.code,
dcpApplicanttype: this.args.package.applicantType.code,
dcpProjectbrief: '',
_dcpApplicantadministratorCustomerValue: verifiedPrimaryContact.id,
_dcpApplicantCustomerValue: verifiedApplicant.id,
_dcpLeadplannerValue: verifiedApplicant.id,
},
},
}),
});
} catch (e) {
console.log('Save new project package error', e);
} 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
Expand Up @@ -60,6 +60,11 @@

<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
Planning" would be: <b>First Name:</b> NYC, <b>Last Name:</b> Planning
</p>
<Ui::Question @required={{true}} as |Q|>
<Q.Label>
First Name
Expand Down Expand Up @@ -116,4 +121,4 @@
/>
</Ui::Question>
</form.Section>
{{/let}}
{{/let}}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<Q.Label>
Project Name
</Q.Label>

<form.Field
@attribute='projectName'
@type='text-input'
Expand All @@ -18,17 +17,22 @@
<Q.Label data-test-projects-new-borough-dropdown>
Borough
</Q.Label>
<PowerSelect
supportsDataTestProperties={{true}}
@attribute='borough'
@options={{@boroughOptions}}
@onChange={{@onBoroughChange}}
@selected={{@selectedBorough}}
@searchField='label'
data-test-id='project-new-borough-dropdown'
@placeholder='select a borough' as |borough| >
{{borough.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>
Expand All @@ -39,15 +43,22 @@
</p>
<PowerSelect
supportsDataTestProperties={{true}}
@attribute='dcpApplicantType'
@attribute='applicantType'
@options={{@applicantOptions}}
@onChange={{@onApplicantTypeSelection}}
@selected={{@selectedApplicantType}}
@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

0 comments on commit 34ac7fe

Please sign in to comment.