2021-12-06 10:07:08 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
|
|
// Copyright © 2021 Hardcore Engineering Inc.
|
2021-12-15 09:15:43 +00:00
|
|
|
//
|
2021-12-06 10:07:08 +00:00
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
2021-12-15 09:15:43 +00:00
|
|
|
//
|
2021-12-06 10:07:08 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
2021-12-15 09:15:43 +00:00
|
|
|
//
|
2021-12-06 10:07:08 +00:00
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
2021-12-30 09:04:32 +00:00
|
|
|
import { createEventDispatcher, onMount, afterUpdate } from 'svelte'
|
2021-12-10 09:46:08 +00:00
|
|
|
import { getCurrentAccount, Ref, Space } from '@anticrm/core'
|
2021-12-15 09:15:43 +00:00
|
|
|
import { CircleButton, EditBox, showPopup, IconEdit, IconAdd, Label, IconActivity } from '@anticrm/ui'
|
|
|
|
import { getClient, createQuery, Channels, Avatar } from '@anticrm/presentation'
|
2021-12-10 09:46:08 +00:00
|
|
|
import setting from '@anticrm/setting'
|
|
|
|
import { IntegrationType } from '@anticrm/setting'
|
2021-12-06 10:07:08 +00:00
|
|
|
import contact from '../plugin'
|
2021-12-15 09:15:43 +00:00
|
|
|
import { combineName, getFirstName, getLastName, Person } from '@anticrm/contact'
|
2021-12-06 10:07:08 +00:00
|
|
|
|
2021-12-15 09:15:43 +00:00
|
|
|
export let object: Person
|
2021-12-06 10:07:08 +00:00
|
|
|
|
2021-12-15 09:15:43 +00:00
|
|
|
let firstName = getFirstName(object.name)
|
|
|
|
let lastName = getLastName(object.name)
|
2021-12-06 10:07:08 +00:00
|
|
|
|
|
|
|
const client = getClient()
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
|
2021-12-07 09:05:52 +00:00
|
|
|
function saveChannels (result: any) {
|
2021-12-06 10:07:08 +00:00
|
|
|
if (result !== undefined) {
|
|
|
|
object.channels = result
|
|
|
|
client.updateDoc(object._class, object.space, object._id, { channels: result })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-07 09:05:52 +00:00
|
|
|
function firstNameChange () {
|
|
|
|
client.updateDoc(object._class, object.space, object._id, {
|
|
|
|
name: combineName(firstName, getLastName(object.name))
|
|
|
|
})
|
2021-12-06 10:07:08 +00:00
|
|
|
}
|
|
|
|
|
2021-12-07 09:05:52 +00:00
|
|
|
function lastNameChange () {
|
|
|
|
client.updateDoc(object._class, object.space, object._id, {
|
|
|
|
name: combineName(getFirstName(object.name), lastName)
|
|
|
|
})
|
2021-12-06 10:07:08 +00:00
|
|
|
}
|
2021-12-10 09:46:08 +00:00
|
|
|
|
|
|
|
const accountId = getCurrentAccount()._id
|
|
|
|
let integrations: Set<Ref<IntegrationType>> = new Set<Ref<IntegrationType>>()
|
|
|
|
const settingsQuery = createQuery()
|
|
|
|
$: settingsQuery.query(setting.class.Integration, { space: accountId as string as Ref<Space> }, (res) => {
|
|
|
|
integrations = new Set(res.map((p) => p.type))
|
|
|
|
})
|
2021-12-15 09:15:43 +00:00
|
|
|
|
2021-12-30 09:04:32 +00:00
|
|
|
const sendOpen = () => dispatch('open', { ignoreKeys: ['comments', 'name', 'channels'] })
|
|
|
|
onMount(sendOpen)
|
|
|
|
afterUpdate(sendOpen)
|
2021-12-06 10:07:08 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if object !== undefined}
|
2021-12-15 09:15:43 +00:00
|
|
|
<div class="flex-row-center">
|
|
|
|
<div class="mr-8">
|
|
|
|
<Avatar avatar={object.avatar} size={'x-large'} />
|
|
|
|
</div>
|
|
|
|
<div class="flex-grow flex-col">
|
|
|
|
<div class="name">
|
|
|
|
<EditBox placeholder="John" maxWidth="20rem" bind:value={firstName} on:change={firstNameChange} />
|
2021-12-07 09:05:52 +00:00
|
|
|
</div>
|
2021-12-15 09:15:43 +00:00
|
|
|
<div class="name">
|
|
|
|
<EditBox placeholder="Appleseed" maxWidth="20rem" bind:value={lastName} on:change={lastNameChange} />
|
|
|
|
</div>
|
|
|
|
<div class="flex-between channels">
|
|
|
|
<div class="flex-row-center">
|
2021-12-07 09:05:52 +00:00
|
|
|
{#if !object.channels || object.channels.length === 0}
|
|
|
|
<CircleButton
|
|
|
|
icon={IconAdd}
|
|
|
|
size={'small'}
|
|
|
|
selected
|
|
|
|
on:click={(ev) =>
|
|
|
|
showPopup(contact.component.SocialEditor, { values: object.channels ?? [] }, ev.target, (result) => {
|
|
|
|
saveChannels(result)
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
<span><Label label={contact.string.AddSocialLinks} /></span>
|
|
|
|
{:else}
|
2021-12-15 09:15:43 +00:00
|
|
|
<Channels value={object.channels} size={'small'} {integrations} on:click />
|
2021-12-07 09:05:52 +00:00
|
|
|
<div class="ml-1">
|
|
|
|
<CircleButton
|
|
|
|
icon={IconEdit}
|
|
|
|
size={'small'}
|
|
|
|
selected
|
|
|
|
on:click={(ev) =>
|
|
|
|
showPopup(contact.component.SocialEditor, { values: object.channels ?? [] }, ev.target, (result) => {
|
|
|
|
saveChannels(result)
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2021-12-06 10:07:08 +00:00
|
|
|
|
2021-12-15 09:15:43 +00:00
|
|
|
<div class="flex-row-center">
|
|
|
|
<a href={'#'} class="flex-row-center" on:click>
|
|
|
|
<CircleButton icon={IconActivity} size={'small'} primary on:click />
|
|
|
|
<span class="ml-2 small-text">View activity</span>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-07 09:05:52 +00:00
|
|
|
</div>
|
2021-12-15 09:15:43 +00:00
|
|
|
</div>
|
2021-12-06 10:07:08 +00:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.name {
|
|
|
|
font-weight: 500;
|
|
|
|
font-size: 1.25rem;
|
|
|
|
color: var(--theme-caption-color);
|
|
|
|
}
|
|
|
|
.channels {
|
2021-12-07 09:05:52 +00:00
|
|
|
margin-top: 0.75rem;
|
|
|
|
span {
|
|
|
|
margin-left: 0.5rem;
|
|
|
|
}
|
2021-12-06 10:07:08 +00:00
|
|
|
}
|
|
|
|
</style>
|