Skip to content

Instantly share code, notes, and snippets.

@JIntrocaso
Last active September 21, 2020 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JIntrocaso/718f11a701c7901e9bc326ec5a6969b8 to your computer and use it in GitHub Desktop.
Save JIntrocaso/718f11a701c7901e9bc326ec5a6969b8 to your computer and use it in GitHub Desktop.
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