index.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useEffect, useState } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { RiCloseLine } from '@remixicon/react'
  6. import CSVUploader from './csv-uploader'
  7. import CSVDownloader from './csv-downloader'
  8. import Button from '@/app/components/base/button'
  9. import Modal from '@/app/components/base/modal'
  10. import type { DocForm } from '@/models/datasets'
  11. export type IBatchModalProps = {
  12. isShow: boolean
  13. docForm: DocForm
  14. onCancel: () => void
  15. onConfirm: (file: File) => void
  16. }
  17. const BatchModal: FC<IBatchModalProps> = ({
  18. isShow,
  19. docForm,
  20. onCancel,
  21. onConfirm,
  22. }) => {
  23. const { t } = useTranslation()
  24. const [currentCSV, setCurrentCSV] = useState<File>()
  25. const handleFile = (file?: File) => setCurrentCSV(file)
  26. const handleSend = () => {
  27. if (!currentCSV)
  28. return
  29. onCancel()
  30. onConfirm(currentCSV)
  31. }
  32. useEffect(() => {
  33. if (!isShow)
  34. setCurrentCSV(undefined)
  35. }, [isShow])
  36. return (
  37. <Modal isShow={isShow} onClose={() => { }} className='px-8 py-6 !max-w-[520px] !rounded-xl'>
  38. <div className='relative pb-1 text-xl font-medium leading-[30px] text-gray-900'>{t('datasetDocuments.list.batchModal.title')}</div>
  39. <div className='absolute right-4 top-4 p-2 cursor-pointer' onClick={onCancel}>
  40. <RiCloseLine className='w-4 h-4 text-gray-500' />
  41. </div>
  42. <CSVUploader
  43. file={currentCSV}
  44. updateFile={handleFile}
  45. />
  46. <CSVDownloader
  47. docForm={docForm}
  48. />
  49. <div className='mt-[28px] pt-6 flex justify-end'>
  50. <Button className='mr-2' onClick={onCancel}>
  51. {t('datasetDocuments.list.batchModal.cancel')}
  52. </Button>
  53. <Button variant="primary" onClick={handleSend} disabled={!currentCSV}>
  54. {t('datasetDocuments.list.batchModal.run')}
  55. </Button>
  56. </div>
  57. </Modal>
  58. )
  59. }
  60. export default React.memo(BatchModal)