Skip to content

Commit

Permalink
feat: quick add with email (#5182)
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveitaly authored Jan 1, 2022
1 parent 60cf334 commit 80001fc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ private function createForm(Request $request, bool $isContactMissing = false)
->withDefaultGender(auth()->user()->account->default_gender_id)
->withFormNameOrder(FormHelper::getNameOrderForForms(auth()->user()))
->withFirstName($request->input('first_name'))
->withLastName($request->input('last_name'));
->withLastName($request->input('last_name'))
->withEmail($request->input('email'));
}

/**
Expand Down
25 changes: 21 additions & 4 deletions resources/js/components/people/ContactSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,25 @@ export default {
if (contact.item.id > 0) {
window.location = contact.item.route;
} else {
const names = contact.item.keyword.split(' ').map(name => _.capitalize(name));
// contact with ID = -1 is the 'add person' contact
let first_name;
let last_name;
const keyword = contact.item.keyword.trim();
let names, email;
// attempt to extract name and email from 'first last <email@example.com>' format
// https://stackoverflow.com/questions/9558608/regex-for-parsing-name-and-email-from-a-single-string
const emailAndNameMatch = keyword.match(/(.*[^\s*<])?\s*<(.*)>/);
if(emailAndNameMatch === null) {
names = keyword;
} else {
names = emailAndNameMatch[1];
email = emailAndNameMatch[2];
}
names = names.split(' ').map(name => _.capitalize(name));
let first_name, last_name;
if (this.formNameOrder == 'firstname') {
first_name = names[0];
last_name = names.slice(1).join(' ');
Expand All @@ -65,14 +80,16 @@ export default {
last_name = names[0];
}
const params = new URLSearchParams();
if (first_name) {
params.set('first_name', first_name);
}
if (last_name) {
params.set('last_name', last_name);
}
if (email) {
params.set('email', email);
}
window.location = 'people/add' + (params != '' ? '?' + params : '');
}
Expand Down
3 changes: 2 additions & 1 deletion resources/views/people/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@
:id="'email'"
:input-type="'text'"
:required="false"
:title="'{{ trans('people.people_add_email') }}'">
:title="'{{ trans('people.people_add_email') }}'"
:value="'{{ $email }}'">
</form-input>
</div>

Expand Down

0 comments on commit 80001fc

Please sign in to comment.