Skip to content

Commit

Permalink
passing borough and applicant type to form args working
Browse files Browse the repository at this point in the history
  • Loading branch information
horatiorosa committed Oct 29, 2024
1 parent d889e6b commit cfb56c5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 51 deletions.
3 changes: 2 additions & 1 deletion client/app/components/packages/projects/new.hbs
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
<Packages::Projects::ProjectsNewInformation
@project={{saveableProjectsNewForm.data}}
@form={{saveableProjectsNewForm}}
@boroughOptions={{this.boroughOptions}}
@onBoroughChange={{this.handleBoroughChange}}
Expand Down
72 changes: 36 additions & 36 deletions client/app/components/packages/projects/new.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import SubmittableProjectsNewForm from '../../../validations/submittable-projects-new-form';
import { optionset } from '../../../helpers/optionset';
Expand All @@ -17,12 +16,6 @@ export default class ProjectsNewFormComponent extends Component {
@service
store;

@tracked
selectedBorough = null;

@tracked
selectedApplicantType = null;

get boroughOptions() {
return optionset(['project', 'boroughs', 'list']);
}
Expand All @@ -32,29 +25,16 @@ 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;
async submitPackage() {
/* eslint-disable no-console */
console.log('this dot args dot packages?', this.args.package);

if (this.args.form) {
this.args.form.set('dcpApplicantType', selectedApplicantType);
}
}
const projectInformation = {
projectName: this.args.package.projectName,
borough: this.args.package.borough.code,
applicantType: this.args.package.applicantType.code,
};

@action
async submitPackage() {
const primaryContactInput = {
first: this.args.package.primaryContactFirstName,
last: this.args.package.primaryContactLastName,
Expand All @@ -72,12 +52,14 @@ export default class ProjectsNewFormComponent extends Component {
};

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,9 +77,27 @@ export default class ProjectsNewFormComponent extends Component {
}
return contact;
});
await Promise.all(verifiedContactPromises);
} catch {
console.log('Save new project package error');

const saveProjectInformation = () => {
const projectModel = this.store.createRecord('project', {
dcpProjectName: projectInformation.projectName,
dcpBorough: projectInformation.borough,
dcoApplicantType: projectInformation.applicantType,
});
return projectModel.save();
};

await Promise.all(
[
verifiedContactPromises,
saveProjectInformation,
],
)
.then(
await this.args.package.submit(),
);
} catch (error) {
console.log('Save new project package error', error);
}
}
}
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,18 +17,19 @@
<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>
</Ui::Question>

<Ui::Question @required={{true}} as |Q|>
<Q.Label data-test-projects-new-applicant-type>
Applicant Type
Expand All @@ -39,10 +39,10 @@
</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| >
Expand Down
4 changes: 4 additions & 0 deletions client/app/routes/projects/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ export default class ProjectsNewRoute extends Route.extend(AuthenticatedRouteMix
@service store;

async model() {
// console.log(`store`, this.store);
// console.log(`model`, this.model);
return {
projectName: '',
borough: '',
applicantType: '',
primaryContactFirstName: '',
primaryContactLastName: '',
primaryContactEmail: '',
Expand Down

0 comments on commit cfb56c5

Please sign in to comment.