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

View File

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

View File

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

View File

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

View File

@ -24,10 +24,11 @@
"Copied": "Copied",
"Close": "Close",
"InviteDescription": "Share this link to invite other users",
"InviteNote": "Link is valid for 1 hour",
"WantAnotherWorkspace": "Want to create another workspace?",
"ChangeAccount": "Change account",
"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": "Скопировано",
"Close": "Закрыть",
"InviteDescription": "Поделитесь ссылкой чтобы пригласить других участников",
"InviteNote": "Ссылка действительна 1 час",
"WantAnotherWorkspace": "Хотите создать другое рабочее пространство?",
"ChangeAccount": "Сменить пользователя",
"NotSeeingWorkspace": "Не видите ваше рабочее пространство?",
"WorksaceNameRule": "Название рабочего пространства должно состояить из строчных латинских букв, цифр и символов !@#%&^-"
"WorkspaceNameRule": "Название рабочего пространства должно состояить из строчных латинских букв, цифр и символов !@#%&^-",
"LinkValidHours": "Ссылка действительна (часов):",
"GetLink": "Получить ссылку"
}
}

View File

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

View File

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

View File

@ -48,7 +48,8 @@ export default mergeIds(loginId, login, {
WantAnotherWorkspace: '' as IntlString,
NotSeeingWorkspace: '' as IntlString,
ChangeAccount: '' as IntlString,
InviteNote: '' as IntlString,
WorksaceNameRule: '' as IntlString
WorkspaceNameRule: '' 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 exp = 1000 * 60 * 60
const exp = expHours * 1000 * 60 * 60
const emailMask = ''
const limit = -1

View File

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