index.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import {
  5. useCSVDownloader,
  6. } from 'react-papaparse'
  7. import { useTranslation } from 'react-i18next'
  8. import { Download02 as DownloadIcon } from '@/app/components/base/icons/src/vender/solid/general'
  9. export type ICSVDownloadProps = {
  10. vars: { name: string }[]
  11. }
  12. const CSVDownload: FC<ICSVDownloadProps> = ({
  13. vars,
  14. }) => {
  15. const { t } = useTranslation()
  16. const { CSVDownloader, Type } = useCSVDownloader()
  17. const addQueryContentVars = [...vars]
  18. const template = (() => {
  19. const res: Record<string, string> = {}
  20. addQueryContentVars.forEach((item) => {
  21. res[item.name] = ''
  22. })
  23. return res
  24. })()
  25. return (
  26. <div className='mt-6'>
  27. <div className='text-sm text-gray-900 font-medium'>{t('share.generation.csvStructureTitle')}</div>
  28. <div className='mt-2 max-h-[500px] overflow-auto'>
  29. <table className='w-full border-separate border-spacing-0 border border-gray-200 rounded-lg text-xs'>
  30. <thead className='text-gray-500'>
  31. <tr>
  32. {addQueryContentVars.map((item, i) => (
  33. <td key={i} className='h-9 pl-4 border-b border-gray-200'>{item.name}</td>
  34. ))}
  35. </tr>
  36. </thead>
  37. <tbody className='text-gray-300'>
  38. <tr>
  39. {addQueryContentVars.map((item, i) => (
  40. <td key={i} className='h-9 pl-4'>{item.name} {t('share.generation.field')}</td>
  41. ))}
  42. </tr>
  43. </tbody>
  44. </table>
  45. </div>
  46. <CSVDownloader
  47. className="block mt-2 cursor-pointer"
  48. type={Type.Link}
  49. filename={'template'}
  50. bom={true}
  51. config={{
  52. // delimiter: ';',
  53. }}
  54. data={[
  55. template,
  56. ]}
  57. >
  58. <div className='flex items-center h-[18px] space-x-1 text-[#155EEF] text-xs font-medium'>
  59. <DownloadIcon className='w-3 h-3' />
  60. <span>{t('share.generation.downloadTemplate')}</span>
  61. </div>
  62. </CSVDownloader>
  63. </div>
  64. )
  65. }
  66. export default React.memo(CSVDownload)