Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

invitation-link.tsx 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use client'
  2. import React, { useCallback, useEffect, useRef, 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. import { randomString } from '@/utils'
  9. type IInvitationLinkProps = {
  10. value: SuccessInvitationResult
  11. }
  12. const InvitationLink = ({
  13. value,
  14. }: IInvitationLinkProps) => {
  15. const [isCopied, setIsCopied] = useState(false)
  16. const selector = useRef(`invite-link-${randomString(4)}`)
  17. const copyHandle = useCallback(() => {
  18. // No prefix is needed here because the backend has already processed it
  19. copy(`${!value.url.startsWith('http') ? window.location.origin : ''}${value.url}`)
  20. setIsCopied(true)
  21. }, [value])
  22. useEffect(() => {
  23. if (isCopied) {
  24. const timeout = setTimeout(() => {
  25. setIsCopied(false)
  26. }, 1000)
  27. return () => {
  28. clearTimeout(timeout)
  29. }
  30. }
  31. }, [isCopied])
  32. return (
  33. <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'>
  34. <div className="flex h-5 grow items-center">
  35. <div className='relative h-full grow text-[13px]'>
  36. <Tooltip
  37. popupContent={isCopied ? `${t('appApi.copied')}` : `${t('appApi.copy')}`}
  38. >
  39. <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>
  40. </Tooltip>
  41. </div>
  42. <div className="h-4 shrink-0 border bg-divider-regular" />
  43. <Tooltip
  44. popupContent={isCopied ? `${t('appApi.copied')}` : `${t('appApi.copy')}`}
  45. >
  46. <div className="shrink-0 px-0.5">
  47. <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}>
  48. </div>
  49. </div>
  50. </Tooltip>
  51. </div>
  52. </div>
  53. )
  54. }
  55. export default InvitationLink