invitation-link.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 'use client'
  2. import React, { useCallback, useEffect, useState } from 'react'
  3. import { t } from 'i18next'
  4. import s from './index.module.css'
  5. import Tooltip from '@/app/components/base/tooltip'
  6. import useCopyToClipboard from '@/hooks/use-copy-to-clipboard'
  7. type IInvitationLinkProps = {
  8. value?: string
  9. }
  10. const InvitationLink = ({
  11. value = '',
  12. }: IInvitationLinkProps) => {
  13. const [isCopied, setIsCopied] = useState(false)
  14. const [_, copy] = useCopyToClipboard()
  15. const copyHandle = useCallback(() => {
  16. copy(value)
  17. setIsCopied(true)
  18. }, [value, copy])
  19. useEffect(() => {
  20. if (isCopied) {
  21. const timeout = setTimeout(() => {
  22. setIsCopied(false)
  23. }, 1000)
  24. return () => {
  25. clearTimeout(timeout)
  26. }
  27. }
  28. }, [isCopied])
  29. return (
  30. <div className='flex rounded-lg bg-gray-100 hover:bg-gray-100 border border-gray-200 py-2 items-center'>
  31. <div className="flex items-center flex-grow h-5">
  32. <div className='flex-grow bg-gray-100 text-[13px] relative h-full'>
  33. <Tooltip
  34. selector="top-uniq"
  35. content={isCopied ? `${t('appApi.copied')}` : `${t('appApi.copy')}`}
  36. className='z-10'
  37. >
  38. <div className='absolute top-0 left-0 w-full pl-2 pr-2 truncate cursor-pointer r-0' onClick={copyHandle}>{value}</div>
  39. </Tooltip>
  40. </div>
  41. <div className="flex-shrink-0 h-4 bg-gray-200 border" />
  42. <Tooltip
  43. selector="top-uniq"
  44. content={isCopied ? `${t('appApi.copied')}` : `${t('appApi.copy')}`}
  45. className='z-10'
  46. >
  47. <div className="px-0.5 flex-shrink-0">
  48. <div className={`box-border w-[30px] h-[30px] flex items-center justify-center rounded-lg hover:bg-gray-100 cursor-pointer ${s.copyIcon} ${isCopied ? s.copied : ''}`} onClick={copyHandle}>
  49. </div>
  50. </div>
  51. </Tooltip>
  52. </div>
  53. </div>
  54. )
  55. }
  56. export default InvitationLink