index.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { ArrowTopRightOnSquareIcon } from '@heroicons/react/24/outline'
  5. import { useTranslation } from 'react-i18next'
  6. import { useContext } from 'use-context-selector'
  7. import type { AppMode } from '@/types/app'
  8. import I18n from '@/context/i18n'
  9. import Button from '@/app/components/base/button'
  10. import Modal from '@/app/components/base/modal'
  11. import Tag from '@/app/components/base/tag'
  12. import { LanguagesSupported } from '@/i18n/language'
  13. type IShareLinkProps = {
  14. isShow: boolean
  15. onClose: () => void
  16. linkUrl: string
  17. api_base_url: string
  18. appId: string
  19. mode: AppMode
  20. }
  21. const StepNum: FC<{ children: React.ReactNode }> = ({ children }) =>
  22. <div className='h-7 w-7 flex justify-center items-center flex-shrink-0 mr-3 text-primary-600 bg-primary-50 rounded-2xl'>
  23. {children}
  24. </div>
  25. const GithubIcon = ({ className }: { className: string }) => {
  26. return (
  27. <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg" className={className}>
  28. <path d="M5.80078 13.7109C5.80078 13.6406 5.73047 13.5703 5.625 13.5703C5.51953 13.5703 5.44922 13.6406 5.44922 13.7109C5.44922 13.7812 5.51953 13.8516 5.625 13.8164C5.73047 13.8164 5.80078 13.7812 5.80078 13.7109ZM4.71094 13.5352C4.71094 13.6055 4.78125 13.7109 4.88672 13.7109C4.95703 13.7461 5.0625 13.7109 5.09766 13.6406C5.09766 13.5703 5.0625 13.5 4.95703 13.4648C4.85156 13.4297 4.74609 13.4648 4.71094 13.5352ZM6.29297 13.5C6.1875 13.5 6.11719 13.5703 6.11719 13.6758C6.11719 13.7461 6.22266 13.7812 6.32812 13.7461C6.43359 13.7109 6.50391 13.6758 6.46875 13.6055C6.46875 13.5352 6.36328 13.4648 6.29297 13.5ZM8.57812 0C3.72656 0 0 3.72656 0 8.57812C0 12.4805 2.42578 15.8203 5.94141 17.0156C6.39844 17.0859 6.53906 16.8047 6.53906 16.5938C6.53906 16.3477 6.53906 15.1523 6.53906 14.4141C6.53906 14.4141 4.07812 14.9414 3.55078 13.3594C3.55078 13.3594 3.16406 12.3398 2.60156 12.0938C2.60156 12.0938 1.79297 11.5312 2.63672 11.5312C2.63672 11.5312 3.51562 11.6016 4.00781 12.4453C4.78125 13.8164 6.04688 13.4297 6.57422 13.1836C6.64453 12.6211 6.85547 12.2344 7.13672 11.9883C5.16797 11.7773 3.16406 11.4961 3.16406 8.12109C3.16406 7.13672 3.44531 6.67969 4.00781 6.04688C3.90234 5.80078 3.62109 4.88672 4.11328 3.65625C4.81641 3.44531 6.53906 4.60547 6.53906 4.60547C7.24219 4.39453 7.98047 4.32422 8.71875 4.32422C9.49219 4.32422 10.2305 4.39453 10.9336 4.60547C10.9336 4.60547 12.6211 3.41016 13.3594 3.65625C13.8516 4.88672 13.5352 5.80078 13.4648 6.04688C14.0273 6.67969 14.3789 7.13672 14.3789 8.12109C14.3789 11.4961 12.3047 11.7773 10.3359 11.9883C10.6523 12.2695 10.9336 12.7969 10.9336 13.6406C10.9336 14.8008 10.8984 16.2773 10.8984 16.5586C10.8984 16.8047 11.0742 17.0859 11.5312 16.9805C15.0469 15.8203 17.4375 12.4805 17.4375 8.57812C17.4375 3.72656 13.4648 0 8.57812 0ZM3.41016 12.1289C3.33984 12.1641 3.375 12.2695 3.41016 12.3398C3.48047 12.375 3.55078 12.4102 3.62109 12.375C3.65625 12.3398 3.65625 12.2344 3.58594 12.1641C3.51562 12.1289 3.44531 12.0938 3.41016 12.1289ZM3.02344 11.8477C2.98828 11.918 3.02344 11.9531 3.09375 11.9883C3.16406 12.0234 3.23438 12.0234 3.26953 11.9531C3.26953 11.918 3.23438 11.8828 3.16406 11.8477C3.09375 11.8125 3.05859 11.8125 3.02344 11.8477ZM4.14844 13.1133C4.11328 13.1484 4.11328 13.2539 4.21875 13.3242C4.28906 13.3945 4.39453 13.4297 4.42969 13.3594C4.46484 13.3242 4.46484 13.2188 4.39453 13.1484C4.32422 13.0781 4.21875 13.043 4.14844 13.1133ZM3.76172 12.5859C3.69141 12.6211 3.69141 12.7266 3.76172 12.7969C3.83203 12.8672 3.90234 12.9023 3.97266 12.8672C4.00781 12.832 4.00781 12.7266 3.97266 12.6562C3.90234 12.5859 3.83203 12.5508 3.76172 12.5859Z" fill="#1F2A37" />
  29. </svg>
  30. )
  31. }
  32. const prefixCustomize = 'appOverview.overview.appInfo.customize'
  33. const CustomizeModal: FC<IShareLinkProps> = ({
  34. isShow,
  35. onClose,
  36. appId,
  37. api_base_url,
  38. mode,
  39. }) => {
  40. const { t } = useTranslation()
  41. const { locale } = useContext(I18n)
  42. const isChatApp = mode === 'chat' || mode === 'advanced-chat'
  43. return <Modal
  44. title={t(`${prefixCustomize}.title`)}
  45. description={t(`${prefixCustomize}.explanation`)}
  46. isShow={isShow}
  47. onClose={onClose}
  48. className='!max-w-2xl w-[640px]'
  49. closable={true}
  50. >
  51. <div className='w-full mt-4 px-6 py-5 border-gray-200 rounded-lg border-[0.5px]'>
  52. <Tag bordered={true} hideBg={true} className='text-primary-600 border-primary-600 uppercase'>{t(`${prefixCustomize}.way`)} 1</Tag>
  53. <p className='my-2 text-base font-medium text-gray-800'>{t(`${prefixCustomize}.way1.name`)}</p>
  54. <div className='flex py-4'>
  55. <StepNum>1</StepNum>
  56. <div className='flex flex-col'>
  57. <div className='text-gray-900'>{t(`${prefixCustomize}.way1.step1`)}</div>
  58. <div className='text-gray-500 text-xs mt-1 mb-2'>{t(`${prefixCustomize}.way1.step1Tip`)}</div>
  59. <a href={`https://github.com/langgenius/${isChatApp ? 'webapp-conversation' : 'webapp-text-generator'}`} target='_blank' rel='noopener noreferrer'>
  60. <Button className='text-gray-800 text-sm w-fit'><GithubIcon className='text-gray-800 mr-2' />{t(`${prefixCustomize}.way1.step1Operation`)}</Button>
  61. </a>
  62. </div>
  63. </div>
  64. <div className='flex pt-4'>
  65. <StepNum>2</StepNum>
  66. <div className='flex flex-col'>
  67. <div className='text-gray-900'>{t(`${prefixCustomize}.way1.step3`)}</div>
  68. <div className='text-gray-500 text-xs mt-1 mb-2'>{t(`${prefixCustomize}.way1.step2Tip`)}</div>
  69. <a href="https://vercel.com/docs/concepts/deployments/git/vercel-for-github" target='_blank' rel='noopener noreferrer'>
  70. <Button className='text-gray-800 text-sm w-fit'>
  71. <div className='mr-1.5 border-solid border-t-0 border-r-[7px] border-l-[7px] border-b-[12px] border-r-transparent border-b-black border-l-transparent border-t-transparent'></div>
  72. <span>{t(`${prefixCustomize}.way1.step2Operation`)}</span>
  73. </Button>
  74. </a>
  75. </div>
  76. </div>
  77. <div className='flex py-4'>
  78. <StepNum>3</StepNum>
  79. <div className='flex flex-col w-full overflow-hidden'>
  80. <div className='text-gray-900'>{t(`${prefixCustomize}.way1.step3`)}</div>
  81. <div className='text-gray-500 text-xs mt-1 mb-2'>{t(`${prefixCustomize}.way1.step3Tip`)}</div>
  82. <pre className='overflow-x-scroll box-border py-3 px-4 bg-gray-100 text-xs font-medium rounded-lg select-text'>
  83. NEXT_PUBLIC_APP_ID={`'${appId}'`} <br />
  84. NEXT_PUBLIC_APP_KEY={'\'<Web API Key From Dify>\''} <br />
  85. NEXT_PUBLIC_API_URL={`'${api_base_url}'`}
  86. </pre>
  87. </div>
  88. </div>
  89. </div>
  90. <div className='w-full mt-4 px-6 py-5 border-gray-200 rounded-lg border-[0.5px]'>
  91. <Tag bordered={true} hideBg={true} className='text-primary-600 border-primary-600 uppercase'>{t(`${prefixCustomize}.way`)} 2</Tag>
  92. <p className='mt-2 text-base font-medium text-gray-800'>{t(`${prefixCustomize}.way2.name`)}</p>
  93. <Button
  94. className='w-36 mt-2'
  95. onClick={() =>
  96. window.open(
  97. `https://docs.dify.ai/${locale !== LanguagesSupported[1]
  98. ? 'user-guide/launching-dify-apps/developing-with-apis'
  99. : `v/${locale.toLowerCase()}/guides/application-publishing/developing-with-apis`
  100. }`,
  101. '_blank',
  102. )
  103. }
  104. >
  105. <span className='text-sm text-gray-800'>{t(`${prefixCustomize}.way2.operation`)}</span>
  106. <ArrowTopRightOnSquareIcon className='w-4 h-4 ml-1 text-gray-800 shrink-0' />
  107. </Button>
  108. </div>
  109. </Modal>
  110. }
  111. export default CustomizeModal