Skip to content

Commit

Permalink
Submit new project details
Browse files Browse the repository at this point in the history
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
TangoYankee and horatiorosa committed Nov 15, 2024
1 parent ef11f66 commit bc52b26
Show file tree
Hide file tree
Showing 15 changed files with 384 additions and 148 deletions.
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,28 @@
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}} />
<Projects::ProjectsNewProjectDescription
@form={{saveableProjectsNewForm}} />
</div>

<div class="cell large-4 sticky-sidebar">
<saveableProjectsNewForm.PageNav>
<saveableProjectsNewForm.SubmitButton @isEnabled={{saveableProjectsNewForm.isSubmittable}} data-test-save-button />
</saveableProjectsNewForm.PageNav>
<Messages::Assistance class="large-margin-top" />
<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
112 changes: 112 additions & 0 deletions client/app/components/projects/new.js
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');
}
}
}
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 @@ -70,13 +55,15 @@
id={{Q.questionId}}
@showCounter={{true}}
@maxlength="10"
placeholder='2125551212'
/>
</Ui::Question>

<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 Expand Up @@ -132,7 +119,8 @@
id={{Q.questionId}}
@showCounter={{true}}
@maxlength="10"
placeholder='2125551212'
/>
</Ui::Question>
</form.Section>
{{/let}}
{{/let}}
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}}

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}}
Loading

0 comments on commit bc52b26

Please sign in to comment.