-
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.
1254 Create Artifact Record as part of Project Creation
- Added artifact creation endpoint and returning artifact id from server to client - Create a form through which users may submit and attach documents (client) Co-authored-by: horatio <[email protected]> Co-authored-by: tangoyankee <[email protected]> lala
- Loading branch information
1 parent
e0965b5
commit 2af2f4b
Showing
36 changed files
with
1,150 additions
and
291 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 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
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,115 @@ | ||
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.args.package.saveAttachedFiles(project.attributes['dcp-artifactsid']); | ||
|
||
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
22 changes: 22 additions & 0 deletions
22
client/app/components/projects/projects-new-attached-documents.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,22 @@ | ||
{{#let @form as |form|}} | ||
<@form.Section @title='Attached Documents'> | ||
<p> | ||
Please attach the required items list on the | ||
<Ui::ExternalLink @href="https://www.nyc.gov/assets/planning/download/pdf/applicants/applicant-portal/interest_checklist.pdf"> | ||
Informational Interest Meeting checklist | ||
</Ui::ExternalLink> in one PDF document. The maximum | ||
size for a document is 50MB. | ||
</p> | ||
|
||
<SaveableForm::FieldValidationMessage | ||
@attribute='documents' | ||
@validation={{@form.errors.documents.validation}} /> | ||
|
||
<Projects::ProjectsNewAttachments | ||
@package={{@form.data}} | ||
@artifact={{@artifact}} | ||
@fileManager={{@model.fileManager}} | ||
data-test-section='attachments' /> | ||
</@form.Section> | ||
|
||
{{/let}} |
Oops, something went wrong.