Invite exp fix (#2520)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-01-18 23:54:27 +06:00 committed by GitHub
parent 077b7b3f0d
commit 44ae8f2e81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 71 additions and 35 deletions

View File

@ -28,7 +28,7 @@
export let file: string export let file: string
export let name: string export let name: string
export let contentType: string | undefined export let contentType: string | undefined
export let options: PopupOptions export let popupOptions: PopupOptions
export let value: Attachment export let value: Attachment
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -47,7 +47,7 @@
<Panel <Panel
isHeader={false} isHeader={false}
isAside={options && options.fullSize} isAside={popupOptions && popupOptions.fullSize}
isFullSize isFullSize
on:fullsize on:fullsize
on:close={() => { on:close={() => {

View File

@ -136,7 +136,7 @@
_class={props._class} _class={props._class}
rightSection={props.rightSection} rightSection={props.rightSection}
position={props.element} position={props.element}
bind:options bind:popupOptions={options}
on:close={_close} on:close={_close}
on:update={_update} on:update={_update}
/> />

View File

@ -137,7 +137,7 @@
this={is} this={is}
bind:this={componentInstance} bind:this={componentInstance}
{...props} {...props}
bind:options bind:popupOptions={options}
on:update={(ev) => { on:update={(ev) => {
_update(ev.detail) _update(ev.detail)
}} }}

View File

@ -35,7 +35,7 @@
export let placeholder: IntlString export let placeholder: IntlString
export let editable: boolean | undefined = undefined export let editable: boolean | undefined = undefined
export let openable: boolean = false export let openable: boolean = false
export let options: PopupOptions export let popupOptions: PopupOptions
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let input: HTMLInputElement let input: HTMLInputElement
@ -79,9 +79,9 @@
let dir: string = 'bottom' let dir: string = 'bottom'
const vDir = (d: string): string => d.split('|')[0] const vDir = (d: string): string => d.split('|')[0]
const fitEditor = (): void => { const fitEditor = (): void => {
if (options) dir = vDir(options.direction) if (popupOptions) dir = vDir(popupOptions.direction)
} }
$: if (options) dir = vDir(options.direction) $: if (popupOptions) dir = vDir(popupOptions.direction)
afterUpdate(() => { afterUpdate(() => {
fitEditor() fitEditor()
}) })

View File

@ -24,10 +24,11 @@
"Copied": "Copied", "Copied": "Copied",
"Close": "Close", "Close": "Close",
"InviteDescription": "Share this link to invite other users", "InviteDescription": "Share this link to invite other users",
"InviteNote": "Link is valid for 1 hour",
"WantAnotherWorkspace": "Want to create another workspace?", "WantAnotherWorkspace": "Want to create another workspace?",
"ChangeAccount": "Change account", "ChangeAccount": "Change account",
"NotSeeingWorkspace": "Not seeing your workspace?", "NotSeeingWorkspace": "Not seeing your workspace?",
"WorksaceNameRule": "The workspace name can contains lowercase letters, numbers, and symbols !@#%&^-" "WorkspaceNameRule": "The workspace name can contains lowercase letters, numbers, and symbols !@#%&^-",
"LinkValidHours": "Link valid (hours):",
"GetLink": "Get invite link"
} }
} }

View File

@ -24,10 +24,11 @@
"Copied": "Скопировано", "Copied": "Скопировано",
"Close": "Закрыть", "Close": "Закрыть",
"InviteDescription": "Поделитесь ссылкой чтобы пригласить других участников", "InviteDescription": "Поделитесь ссылкой чтобы пригласить других участников",
"InviteNote": "Ссылка действительна 1 час",
"WantAnotherWorkspace": "Хотите создать другое рабочее пространство?", "WantAnotherWorkspace": "Хотите создать другое рабочее пространство?",
"ChangeAccount": "Сменить пользователя", "ChangeAccount": "Сменить пользователя",
"NotSeeingWorkspace": "Не видите ваше рабочее пространство?", "NotSeeingWorkspace": "Не видите ваше рабочее пространство?",
"WorksaceNameRule": "Название рабочего пространства должно состояить из строчных латинских букв, цифр и символов !@#%&^-" "WorkspaceNameRule": "Название рабочего пространства должно состояить из строчных латинских букв, цифр и символов !@#%&^-",
"LinkValidHours": "Ссылка действительна (часов):",
"GetLink": "Получить ссылку"
} }
} }

View File

@ -34,7 +34,7 @@
name: 'workspace', name: 'workspace',
i18n: login.string.Workspace, i18n: login.string.Workspace,
rule: /^[0-9a-z#%&^\-!)(]{3,63}$/, rule: /^[0-9a-z#%&^\-!)(]{3,63}$/,
ruleDescr: login.string.WorksaceNameRule ruleDescr: login.string.WorkspaceNameRule
} }
] ]

View File

@ -15,17 +15,18 @@
<script lang="ts"> <script lang="ts">
import { Timestamp } from '@hcengineering/core' import { Timestamp } from '@hcengineering/core'
import { copyTextToClipboard } from '@hcengineering/presentation' import { copyTextToClipboard } from '@hcengineering/presentation'
import { Button, getCurrentLocation, Label, locationToUrl, ticker } from '@hcengineering/ui' import { Button, EditBox, getCurrentLocation, Label, Loading, locationToUrl, ticker } from '@hcengineering/ui'
import { getInviteLink } from '../utils' import { getInviteLink } from '../utils'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher, onMount } from 'svelte'
import login from '../plugin' import login from '../plugin'
import InviteWorkspace from './icons/InviteWorkspace.svelte' import InviteWorkspace from './icons/InviteWorkspace.svelte'
import { loginId } from '@hcengineering/login' import { loginId } from '@hcengineering/login'
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
async function getLink (): Promise<string> { async function getLink (expHours: number): Promise<void> {
const inviteId = await getInviteLink() loading = true
const inviteId = await getInviteLink(expHours)
const loc = getCurrentLocation() const loc = getCurrentLocation()
loc.path[0] = loginId loc.path[0] = loginId
loc.path[1] = 'join' loc.path[1] = 'join'
@ -35,8 +36,9 @@
} }
loc.fragment = undefined loc.fragment = undefined
const link = locationToUrl(loc) const url = locationToUrl(loc)
return document.location.origin + link link = document.location.origin + url
loading = false
} }
let copiedTime: Timestamp | undefined let copiedTime: Timestamp | undefined
@ -48,11 +50,29 @@
} }
} }
} }
function copy (link: string): void { function copy (): void {
if (link === undefined) return
copyTextToClipboard(link) copyTextToClipboard(link)
copied = true copied = true
copiedTime = Date.now() copiedTime = Date.now()
} }
let expHours = 1
function _onchange (ev: Event) {
const value = (ev.target as HTMLInputElement).valueAsNumber
if (Number.isFinite(value)) {
expHours = value
getLink(expHours)
}
}
onMount(() => {
getLink(expHours)
})
let link: string | undefined
let loading = false
</script> </script>
<div class="antiPopup popup"> <div class="antiPopup popup">
@ -61,18 +81,21 @@
<InviteWorkspace size="large" /> <InviteWorkspace size="large" />
</div> </div>
<div class="mt-2"> <div class="mt-2">
<Label label={login.string.InviteNote} /> <EditBox
</div> label={login.string.LinkValidHours}
{#await getLink() then link} value={expHours}
<div class="over-underline link" on:click={() => copy(link)}>{link}</div> format={'number'}
<div class="buttons flex"> on:keypress={() => (link = undefined)}
<Button on:change={_onchange}
label={copied ? login.string.Copied : login.string.Copy}
size={'medium'}
on:click={() => {
copy(link)
}}
/> />
</div>
{#if loading}
<Loading />
{:else if link !== undefined}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div class="over-underline link" on:click={copy}>{link}</div>
<div class="buttons flex">
<Button label={copied ? login.string.Copied : login.string.Copy} size={'medium'} on:click={copy} />
<Button <Button
label={login.string.Close} label={login.string.Close}
size={'medium'} size={'medium'}
@ -82,7 +105,18 @@
}} }}
/> />
</div> </div>
{/await} {:else}
<div class="buttons flex">
<Button
label={login.string.GetLink}
size={'medium'}
kind={'primary'}
on:click={() => {
getLink(expHours)
}}
/>
</div>
{/if}
</div> </div>
<style lang="scss"> <style lang="scss">

View File

@ -48,7 +48,8 @@ export default mergeIds(loginId, login, {
WantAnotherWorkspace: '' as IntlString, WantAnotherWorkspace: '' as IntlString,
NotSeeingWorkspace: '' as IntlString, NotSeeingWorkspace: '' as IntlString,
ChangeAccount: '' as IntlString, ChangeAccount: '' as IntlString,
InviteNote: '' as IntlString, WorkspaceNameRule: '' as IntlString,
WorksaceNameRule: '' as IntlString LinkValidHours: '' as IntlString,
GetLink: '' as IntlString
} }
}) })

View File

@ -353,10 +353,10 @@ export async function checkJoined (inviteId: string): Promise<[Status, Workspace
} }
} }
export async function getInviteLink (): Promise<string> { export async function getInviteLink (expHours: number = 1): Promise<string> {
const accountsUrl = getMetadata(login.metadata.AccountsUrl) const accountsUrl = getMetadata(login.metadata.AccountsUrl)
const exp = 1000 * 60 * 60 const exp = expHours * 1000 * 60 * 60
const emailMask = '' const emailMask = ''
const limit = -1 const limit = -1

View File

@ -46,7 +46,6 @@
.yesno-container { .yesno-container {
max-width: fit-content; max-width: fit-content;
user-select: none; user-select: none;
cursor: pointer;
fill: #77818e; fill: #77818e;
&.yes { &.yes {