-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a form through which users may submit a project Finish the side navigation section for new project closes #1249 closes #1250 Co-authored-by: horatio <[email protected]>
- Loading branch information
1 parent
ef11f66
commit bc52b26
Showing
15 changed files
with
384 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
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 config from '../../config/environment'; | ||
|
||
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 primaryContactInput = { | ||
first: this.args.package.primaryContactFirstName, | ||
last: this.args.package.primaryContactLastName, | ||
email: this.args.package.primaryContactEmail, | ||
phone: this.args.package.primaryContactPhone, | ||
}; | ||
|
||
const applicantInput = { | ||
first: this.args.package.applicantFirstName, | ||
last: this.args.package.applicantLastName, | ||
email: this.args.package.applicantEmail, | ||
phone: this.args.package.applicantPhone, | ||
}; | ||
|
||
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; | ||
}); | ||
|
||
const [verifiedPrimaryContact, verifiedApplicant] = await Promise.all( | ||
verifiedContactPromises, | ||
); | ||
|
||
const authSessionRaw = localStorage.getItem('ember_simple_auth-session'); | ||
|
||
if (authSessionRaw === null) { | ||
throw new Error('unauthorized'); | ||
} | ||
const authSession = JSON.parse(authSessionRaw); | ||
const { | ||
authenticated: { access_token: accessToken }, | ||
} = authSession; | ||
if (accessToken === undefined) { | ||
throw new Error('unauthorized'); | ||
} | ||
|
||
const response = await fetch(`${config.host}/projects`, { | ||
method: 'POST', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
body: JSON.stringify({ | ||
data: { | ||
attributes: { | ||
dcpProjectname: this.args.package.projectName, | ||
dcpBorough: this.args.package.borough.code, | ||
dcpApplicanttype: this.args.package.applicantType.code, | ||
dcpProjectbrief: this.args.package.projectBrief, | ||
_dcpApplicantadministratorCustomerValue: | ||
verifiedPrimaryContact.id, | ||
_dcpApplicantCustomerValue: verifiedApplicant.id, | ||
}, | ||
}, | ||
}), | ||
}); | ||
const { data: project } = await response.json(); | ||
this.router.transitionTo('project', project.id); | ||
} catch { | ||
/* eslint-disable-next-line no-console */ | ||
console.error('Error while creating project'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
client/app/components/projects/projects-new-information.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} | ||
|
16 changes: 16 additions & 0 deletions
16
client/app/components/projects/projects-new-project-description.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{{#let @form as |form|}} | ||
<form.Section @title="Project Description"> | ||
<Ui::Question @required={{true}} as |Q|> | ||
<Q.Label> | ||
Please replace information in the brackets to the best of your ability. | ||
</Q.Label> | ||
|
||
<form.Field | ||
@attribute="projectBrief" | ||
@type="text-area" | ||
id={{Q.questionId}} | ||
@maxlength='500' | ||
value={{"A [action(s)] [ZR#'s for ZR, ZS, ZA] to facilitate a [new] [# of max stories], [total zsf, (# DU's)], [use] development, including [sf for each use, sf open space], is being sought by [public/private] [applicant] at [address] in [neighborhood], [Community District], [Borough]."}} /> | ||
</Ui::Question> | ||
</form.Section> | ||
{{/let}} |
Oops, something went wrong.