share-link.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useState } from 'react'
  4. import {
  5. ArrowPathIcon,
  6. LinkIcon,
  7. } from '@heroicons/react/24/outline'
  8. import { useTranslation } from 'react-i18next'
  9. import copy from 'copy-to-clipboard'
  10. import Modal from '@/app/components/base/modal'
  11. import Button from '@/app/components/base/button'
  12. import './style.css'
  13. type IShareLinkProps = {
  14. isShow: boolean
  15. onClose: () => void
  16. onGenerateCode: () => Promise<void>
  17. linkUrl: string
  18. }
  19. const prefixShare = 'appOverview.overview.appInfo.share'
  20. const ShareLinkModal: FC<IShareLinkProps> = ({
  21. linkUrl,
  22. isShow,
  23. onClose,
  24. onGenerateCode,
  25. }) => {
  26. const [genLoading, setGenLoading] = useState(false)
  27. const [isCopied, setIsCopied] = useState(false)
  28. const { t } = useTranslation()
  29. return <Modal
  30. title={t(`${prefixShare}.explanation`)}
  31. isShow={isShow}
  32. onClose={onClose}
  33. >
  34. {/* share url */}
  35. <p className='mt-5 text-xs font-medium text-gray-500'>{t(`${prefixShare}.shareUrl`)}</p>
  36. {/* input share url */}
  37. <input disabled type='text' value={linkUrl} className='mt-1 w-full bg-gray-50 p-2 text-primary-600 text-xs font-normal outline-gray-50 hover:outline-gray-50 cursor-pointer' />
  38. {/* button copy link/ button regenerate */}
  39. <div className='mt-4 flex gap-3'>
  40. <Button
  41. type="primary"
  42. className='w-32 !px-0'
  43. onClick={() => {
  44. copy(linkUrl) && setIsCopied(true)
  45. }}
  46. >
  47. <LinkIcon className='w-4 h-4 mr-2' />
  48. { t(`${prefixShare}.${isCopied ? 'linkCopied' : 'copyLink'}`) }
  49. </Button>
  50. <Button className='w-32 !px-0' onClick={async () => {
  51. setGenLoading(true)
  52. await onGenerateCode()
  53. setGenLoading(false)
  54. setIsCopied(false)
  55. }}>
  56. <ArrowPathIcon className={`w-4 h-4 mr-2 ${genLoading ? 'generateLogo' : ''}`} />
  57. {t(`${prefixShare}.regenerate`)}
  58. </Button>
  59. </div>
  60. </Modal>
  61. }
  62. export default ShareLinkModal