/saveContact.ts Secret
Last active
September 21, 2020 01:07
Star
You must be signed in to star a gist
Save Contact
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
public saveContact(fields: ContactFormField[], form: FormGroup): Observable<any> { | |
this.getFieldValuesFromForm(fields, form); | |
const firstName = fields.find(f => f.key === 'first_name').value; | |
const lastName = fields.find(f => f.key === 'last_name').value; | |
let contactPostBody = { | |
slug: `${firstName}-${lastName}-${new Date().getTime()}`, | |
type_slug: "contacts", | |
title: `${firstName} ${lastName}`, | |
metafields: fields, | |
write_key: config.writeKey | |
}; | |
return this.http.post(`${this.cosmicUrl}${this.bucketSlug}/add-object`, contactPostBody); | |
} | |
private getFieldValuesFromForm(fields: ContactFormField[], form: FormGroup) { | |
fields.forEach(f => { | |
f.value = form.controls[f.key].value; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment