From 79486e1b8c4f57cb8beaa4d25a85c47d1170b19b Mon Sep 17 00:00:00 2001
From: Andrey Sobolev <haiodo@users.noreply.github.com>
Date: Sat, 27 May 2023 16:44:38 +0700
Subject: [PATCH] UBER-267: Fix Users popup (#3268)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
---
 packages/presentation/src/components/DocPopup.svelte       | 1 +
 plugins/contact-resources/src/components/UsersPopup.svelte | 7 ++++---
 .../src/components/CreateCandidate.svelte                  | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/packages/presentation/src/components/DocPopup.svelte b/packages/presentation/src/components/DocPopup.svelte
index 7ca29add39..b9aaacca06 100644
--- a/packages/presentation/src/components/DocPopup.svelte
+++ b/packages/presentation/src/components/DocPopup.svelte
@@ -130,6 +130,7 @@
         const newPerson = await client.findOne(_class, { _id: res })
         if (newPerson !== undefined) {
           search = c.update?.(newPerson) ?? ''
+          dispatch('search', search)
         }
       }
     })
diff --git a/plugins/contact-resources/src/components/UsersPopup.svelte b/plugins/contact-resources/src/components/UsersPopup.svelte
index 1ddafa6a69..41042e0734 100644
--- a/plugins/contact-resources/src/components/UsersPopup.svelte
+++ b/plugins/contact-resources/src/components/UsersPopup.svelte
@@ -13,7 +13,7 @@
 // limitations under the License.
 -->
 <script lang="ts">
-  import { Contact, getFirstName, Person } from '@hcengineering/contact'
+  import { Contact, getFirstName, getLastName, Person } from '@hcengineering/contact'
   import type { Class, Doc, DocumentQuery, FindOptions, Ref } from '@hcengineering/core'
   import type { Asset, IntlString } from '@hcengineering/platform'
   import presentation, { getClient, ObjectCreate, ObjectPopup } from '@hcengineering/presentation'
@@ -37,14 +37,15 @@
   export let readonly = false
 
   const hierarchy = getClient().getHierarchy()
+  // const dispatch = createEventDispatcher()
 
   $: _create =
     create !== undefined
       ? {
           ...create,
           update: (doc: Doc) => {
-            const name = getFirstName((doc as Contact).name)
-            return name.length > 0 ? name : (doc as Contact).name
+            const name = getFirstName((doc as Contact).name).split(' ')[0]
+            return name.length > 0 ? name : getLastName((doc as Contact).name).split(' ')[0]
           }
         }
       : undefined
diff --git a/plugins/recruit-resources/src/components/CreateCandidate.svelte b/plugins/recruit-resources/src/components/CreateCandidate.svelte
index 09bbd93901..80e9c75738 100644
--- a/plugins/recruit-resources/src/components/CreateCandidate.svelte
+++ b/plugins/recruit-resources/src/components/CreateCandidate.svelte
@@ -270,7 +270,7 @@
 
     await applyOps.commit()
     draftController.remove()
-    dispatch('close', object._id)
+    dispatch('close', _id)
     resetObject()
   }