Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

2.8 KB
Raw Blame
'use client'
import type { MemberInviteSuccessResponse } from '@dify/contracts/api/console/workspaces/types.gen'
import { Tooltip, TooltipContent, TooltipTrigger } from '@langgenius/dify-ui/tooltip'
import copy from 'copy-to-clipboard'
import * as React from 'react'
import { useCallback, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import s from './index.module.css'

type IInvitationLinkProps = {
  value: MemberInviteSuccessResponse
}

const InvitationLink = ({ value }: IInvitationLinkProps) => {
  const { t } = useTranslation(['appApi'])
  const [isCopied, setIsCopied] = useState(false)

  const copyHandle = useCallback(() => {
    // No prefix is needed here because the backend has already processed it
    copy(`${!value.url.startsWith('http') ? window.location.origin : ''}${value.url}`)
    setIsCopied(true)
  }, [value])

  useEffect(() => {
    if (isCopied) {
      const timeout = setTimeout(() => {
        setIsCopied(false)
      }, 1000)

      return () => {
        clearTimeout(timeout)
      }
    }
  }, [isCopied])

  return (
    <div className="flex items-center rounded-lg border border-components-input-border-active bg-components-input-bg-normal py-2 hover:bg-state-base-hover">
      <div className="flex h-5 grow items-center">
        <div className="relative h-full grow text-[13px]">
          <Tooltip>
            <TooltipTrigger
              render={
                <button
                  type="button"
                  className="absolute inset-x-0 top-0 block w-full cursor-pointer truncate border-none bg-transparent p-0 px-2 text-start text-text-primary"
                  onClick={copyHandle}
                >
                  <span dir="ltr">{value.url}</span>
                </button>
              }
            />
            <TooltipContent>
              {isCopied ? t(($) => $.copied, { ns: 'appApi' }) : t(($) => $.copy, { ns: 'appApi' })}
            </TooltipContent>
          </Tooltip>
        </div>
        <div className="h-4 shrink-0 border border-divider-regular bg-divider-regular" />
        <Tooltip>
          <TooltipTrigger
            render={
              <div className="shrink-0 px-0.5">
                <button
                  type="button"
                  aria-label={t(($) => $.copy, { ns: 'appApi' })}
                  className={`box-border flex h-7.5 w-7.5 cursor-pointer items-center justify-center rounded-lg border-none bg-transparent p-0 hover:bg-state-base-hover ${s.copyIcon} ${isCopied ? s.copied : ''}`}
                  onClick={copyHandle}
                />
              </div>
            }
          />
          <TooltipContent>
            {isCopied ? t(($) => $.copied, { ns: 'appApi' }) : t(($) => $.copy, { ns: 'appApi' })}
          </TooltipContent>
        </Tooltip>
      </div>
    </div>
  )
}

export default InvitationLink