2021-12-06 10:07:08 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
|
|
// Copyright © 2021 Hardcore Engineering Inc.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
|
|
|
import { createEventDispatcher } from 'svelte'
|
2022-02-25 13:23:50 +00:00
|
|
|
import { AttachedData, Data, FindResult, generateId } from '@anticrm/core'
|
2022-01-31 09:06:30 +00:00
|
|
|
import { getResource } from '@anticrm/platform'
|
2021-12-06 10:07:08 +00:00
|
|
|
|
2022-01-31 09:06:30 +00:00
|
|
|
import { getClient, Card, EditableAvatar } from '@anticrm/presentation'
|
2021-12-06 10:07:08 +00:00
|
|
|
|
2022-01-12 09:52:22 +00:00
|
|
|
import attachment from '@anticrm/attachment'
|
2022-04-13 04:25:59 +00:00
|
|
|
import { EditBox, IconInfo, Label, Button, showPopup } from '@anticrm/ui'
|
2021-12-06 10:07:08 +00:00
|
|
|
|
2022-02-25 13:23:50 +00:00
|
|
|
import { Channel, combineName, findPerson, Person } from '@anticrm/contact'
|
2021-12-06 10:07:08 +00:00
|
|
|
import contact from '../plugin'
|
2022-04-13 04:25:59 +00:00
|
|
|
import ChannelsView from './ChannelsView.svelte'
|
2022-02-25 13:23:50 +00:00
|
|
|
import PersonPresenter from './PersonPresenter.svelte'
|
2021-12-06 10:07:08 +00:00
|
|
|
|
|
|
|
let firstName = ''
|
|
|
|
let lastName = ''
|
|
|
|
|
2022-01-31 09:06:30 +00:00
|
|
|
const id = generateId()
|
|
|
|
|
2021-12-07 09:05:52 +00:00
|
|
|
export function canClose (): boolean {
|
2021-12-06 10:07:08 +00:00
|
|
|
return firstName === '' && lastName === ''
|
|
|
|
}
|
|
|
|
|
|
|
|
const object: Person = {} as Person
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
const client = getClient()
|
|
|
|
|
2022-01-12 09:52:22 +00:00
|
|
|
let avatar: File | undefined
|
|
|
|
|
|
|
|
function onAvatarDone (e: any) {
|
|
|
|
const { file } = e.detail
|
|
|
|
|
|
|
|
avatar = file
|
|
|
|
}
|
|
|
|
|
2022-03-28 15:25:39 +00:00
|
|
|
function removeAvatar (): void {
|
|
|
|
avatar = undefined
|
|
|
|
}
|
2022-01-12 09:52:22 +00:00
|
|
|
|
2022-03-28 15:25:39 +00:00
|
|
|
async function createPerson () {
|
2021-12-06 10:07:08 +00:00
|
|
|
const person: Data<Person> = {
|
|
|
|
name: combineName(firstName, lastName),
|
2022-03-28 15:25:39 +00:00
|
|
|
city: object.city
|
|
|
|
}
|
|
|
|
|
|
|
|
if (avatar !== undefined) {
|
|
|
|
const uploadFile = await getResource(attachment.helper.UploadFile)
|
|
|
|
person.avatar = await uploadFile(avatar)
|
2021-12-06 10:07:08 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 09:06:30 +00:00
|
|
|
await client.createDoc(contact.class.Person, contact.space.Contacts, person, id)
|
2021-12-06 10:07:08 +00:00
|
|
|
|
2022-01-31 09:06:30 +00:00
|
|
|
for (const channel of channels) {
|
|
|
|
await client.addCollection(contact.class.Channel, contact.space.Contacts, id, contact.class.Person, 'channels', {
|
|
|
|
value: channel.value,
|
|
|
|
provider: channel.provider
|
|
|
|
})
|
|
|
|
}
|
2021-12-06 10:07:08 +00:00
|
|
|
dispatch('close')
|
|
|
|
}
|
2022-01-31 09:06:30 +00:00
|
|
|
|
2022-02-07 09:03:14 +00:00
|
|
|
let channels: AttachedData<Channel>[] = []
|
2022-02-25 13:23:50 +00:00
|
|
|
|
2022-04-08 03:06:38 +00:00
|
|
|
let matches: Person[] = []
|
2022-02-25 13:23:50 +00:00
|
|
|
$: findPerson(client, { ...object, name: combineName(firstName, lastName) }, channels).then((p) => {
|
|
|
|
matches = p
|
|
|
|
})
|
2021-12-06 10:07:08 +00:00
|
|
|
</script>
|
|
|
|
|
2021-12-07 09:05:52 +00:00
|
|
|
<Card
|
|
|
|
label={contact.string.CreatePerson}
|
|
|
|
okAction={createPerson}
|
2022-02-25 13:23:50 +00:00
|
|
|
canSave={firstName.length > 0 && lastName.length > 0 && matches.length === 0}
|
2022-01-11 09:05:53 +00:00
|
|
|
bind:space={contact.space.Contacts}
|
2021-12-07 09:05:52 +00:00
|
|
|
on:close={() => {
|
|
|
|
dispatch('close')
|
|
|
|
}}
|
|
|
|
>
|
2022-04-13 04:25:59 +00:00
|
|
|
<svelte:fragment slot="error">
|
|
|
|
{#if matches.length > 0}
|
|
|
|
<div class="flex-row-center error-color">
|
2022-02-25 13:23:50 +00:00
|
|
|
<IconInfo size={'small'} />
|
2022-04-13 04:25:59 +00:00
|
|
|
<span class="text-sm overflow-label ml-2">
|
2022-02-25 13:23:50 +00:00
|
|
|
<Label label={contact.string.PersonAlreadyExists} />
|
2022-04-13 04:25:59 +00:00
|
|
|
</span>
|
|
|
|
<div class="ml-4"><PersonPresenter value={matches[0]} /></div>
|
2022-02-25 13:23:50 +00:00
|
|
|
</div>
|
2022-04-13 04:25:59 +00:00
|
|
|
{/if}
|
|
|
|
</svelte:fragment>
|
2021-12-06 10:07:08 +00:00
|
|
|
<div class="flex-row-center">
|
|
|
|
<div class="mr-4">
|
2022-03-28 15:25:39 +00:00
|
|
|
<EditableAvatar avatar={object.avatar} size={'large'} on:done={onAvatarDone} on:remove={removeAvatar} />
|
2021-12-06 10:07:08 +00:00
|
|
|
</div>
|
|
|
|
<div class="flex-col">
|
2022-04-13 04:25:59 +00:00
|
|
|
<EditBox placeholder={contact.string.PersonFirstNamePlaceholder} bind:value={firstName} kind={'large-style'} maxWidth={'32rem'} focus />
|
|
|
|
<EditBox placeholder={contact.string.PersonLastNamePlaceholder} bind:value={lastName} kind={'large-style'} maxWidth={'32rem'} />
|
|
|
|
<div class="mt-1">
|
|
|
|
<EditBox placeholder={contact.string.PersonLocationPlaceholder} bind:value={object.city} kind={'small-style'} maxWidth={'32rem'} />
|
2022-02-25 13:23:50 +00:00
|
|
|
</div>
|
2021-12-06 10:07:08 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-13 04:25:59 +00:00
|
|
|
{#if channels.length > 0}
|
|
|
|
<div class="ml-22"><ChannelsView value={channels} size={'small'} on:click /></div>
|
|
|
|
{/if}
|
|
|
|
<svelte:fragment slot="footer">
|
|
|
|
<Button
|
|
|
|
icon={contact.icon.SocialEdit}
|
|
|
|
kind={'transparent'}
|
|
|
|
on:click={(ev) =>
|
|
|
|
showPopup(contact.component.SocialEditor, { values: channels }, ev.target, (result) => {
|
|
|
|
if (result !== undefined) channels = result
|
|
|
|
})
|
|
|
|
}
|
2022-02-25 13:23:50 +00:00
|
|
|
/>
|
2022-04-13 04:25:59 +00:00
|
|
|
</svelte:fragment>
|
2021-12-06 10:07:08 +00:00
|
|
|
</Card>
|