Skip to content

Instantly share code, notes, and snippets.

@JIntrocaso
Last active Sep 21, 2020
Embed
What would you like to do?
Save Contact
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