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-01-31 09:06:30 +00:00
|
|
|
import { Data, generateId } from '@anticrm/core'
|
|
|
|
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-01-31 09:06:30 +00:00
|
|
|
import { EditBox } from '@anticrm/ui'
|
2021-12-06 10:07:08 +00:00
|
|
|
|
2022-01-31 09:06:30 +00:00
|
|
|
import { Channel, combineName, Person } from '@anticrm/contact'
|
2021-12-06 10:07:08 +00:00
|
|
|
import contact from '../plugin'
|
2022-01-31 09:06:30 +00:00
|
|
|
import Channels from './Channels.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
|
|
|
|
}
|
|
|
|
|
2021-12-07 09:05:52 +00:00
|
|
|
async function createPerson () {
|
2022-01-12 09:52:22 +00:00
|
|
|
const uploadFile = await getResource(attachment.helper.UploadFile)
|
2022-01-14 09:05:24 +00:00
|
|
|
const avatarProp = avatar !== undefined
|
|
|
|
? { avatar: await uploadFile(avatar) }
|
|
|
|
: {}
|
2022-01-12 09:52:22 +00:00
|
|
|
|
2021-12-06 10:07:08 +00:00
|
|
|
const person: Data<Person> = {
|
|
|
|
name: combineName(firstName, lastName),
|
|
|
|
city: object.city,
|
2022-01-14 09:05:24 +00:00
|
|
|
...avatarProp
|
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
|
|
|
|
|
|
|
let channels: Channel[] = []
|
2021-12-06 10:07:08 +00:00
|
|
|
</script>
|
|
|
|
|
2021-12-07 09:05:52 +00:00
|
|
|
<Card
|
|
|
|
label={contact.string.CreatePerson}
|
|
|
|
okAction={createPerson}
|
|
|
|
canSave={firstName.length > 0 && lastName.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')
|
|
|
|
}}
|
|
|
|
>
|
2021-12-06 10:07:08 +00:00
|
|
|
<div class="flex-row-center">
|
|
|
|
<div class="mr-4">
|
2022-01-12 09:52:22 +00:00
|
|
|
<EditableAvatar avatar={object.avatar} size={'large'} on:done={onAvatarDone} />
|
2021-12-06 10:07:08 +00:00
|
|
|
</div>
|
|
|
|
<div class="flex-col">
|
2022-01-19 09:09:08 +00:00
|
|
|
<div class="fs-title"><EditBox placeholder={contact.string.PersonFirstNamePlaceholder} maxWidth="12rem" bind:value={firstName} /></div>
|
|
|
|
<div class="fs-title mb-1"><EditBox placeholder={contact.string.PersonLastNamePlaceholder} maxWidth="12rem" bind:value={lastName} /></div>
|
2022-02-01 09:13:01 +00:00
|
|
|
<div class="text-sm"><EditBox placeholder={contact.string.PersonLocationPlaceholder} maxWidth="12rem" bind:value={object.city} /></div>
|
2021-12-06 10:07:08 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex-row-center channels">
|
2022-01-31 09:06:30 +00:00
|
|
|
<Channels bind:channels={channels} on:change={(e) => { channels = e.detail }} />
|
2021-12-06 10:07:08 +00:00
|
|
|
</div>
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.channels {
|
|
|
|
margin-top: 1.25rem;
|
|
|
|
}
|
|
|
|
</style>
|