You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

invitation-link.tsx 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use client'
  2. import React, { useCallback, useEffect, useState } from 'react'
  3. import { t } from 'i18next'
  4. import copy from 'copy-to-clipboard'
  5. import s from './index.module.css'
  6. import type { SuccessInvitationResult } from '.'
  7. import Tooltip from '@/app/components/base/tooltip'
  8. type IInvitationLinkProps = {
  9. value: SuccessInvitationResult
  10. }
  11. const InvitationLink = ({
  12. value,
  13. }: IInvitationLinkProps) => {
  14. const [isCopied, setIsCopied] = useState(false)
  15. const copyHandle = useCallback(() => {
  16. // No prefix is needed here because the backend has already processed it
  17. copy(`${!value.url.startsWith('http') ? window.location.origin : ''}${value.url}`)
  18. setIsCopied(true)
  19. }, [value])
  20. useEffect(() => {
  21. if (isCopied) {
  22. const timeout = setTimeout(() => {
  23. setIsCopied(false)
  24. }, 1000)
  25. return () => {
  26. clearTimeout(timeout)
  27. }
  28. }
  29. }, [isCopied])
  30. return (
  31. <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'>
  32. <div className="flex h-5 grow items-center">
  33. <div className='relative h-full grow text-[13px]'>
  34. <Tooltip
  35. popupContent={isCopied ? `${t('appApi.copied')}` : `${t('appApi.copy')}`}
  36. >
  37. <div className='r-0 absolute left-0 top-0 w-full cursor-pointer truncate pl-2 pr-2 text-text-primary' onClick={copyHandle}>{value.url}</div>
  38. </Tooltip>
  39. </div>
  40. <div className="h-4 shrink-0 border bg-divider-regular" />
  41. <Tooltip
  42. popupContent={isCopied ? `${t('appApi.copied')}` : `${t('appApi.copy')}`}
  43. >
  44. <div className="shrink-0 px-0.5">
  45. <div className={`box-border flex h-[30px] w-[30px] cursor-pointer items-center justify-center rounded-lg hover:bg-state-base-hover ${s.copyIcon} ${isCopied ? s.copied : ''}`} onClick={copyHandle}>
  46. </div>
  47. </div>
  48. </Tooltip>
  49. </div>
  50. </div>
  51. )
  52. }
  53. export default InvitationLink