index.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import {
  5. PlayIcon,
  6. } from '@heroicons/react/24/solid'
  7. import { useTranslation } from 'react-i18next'
  8. import {
  9. RiLoader2Line,
  10. } from '@remixicon/react'
  11. import CSVReader from './csv-reader'
  12. import CSVDownload from './csv-download'
  13. import cn from '@/utils/classnames'
  14. import Button from '@/app/components/base/button'
  15. export type IRunBatchProps = {
  16. vars: { name: string }[]
  17. onSend: (data: string[][]) => void
  18. isAllFinished: boolean
  19. }
  20. const RunBatch: FC<IRunBatchProps> = ({
  21. vars,
  22. onSend,
  23. isAllFinished,
  24. }) => {
  25. const { t } = useTranslation()
  26. const [csvData, setCsvData] = React.useState<string[][]>([])
  27. const [isParsed, setIsParsed] = React.useState(false)
  28. const handleParsed = (data: string[][]) => {
  29. setCsvData(data)
  30. // console.log(data)
  31. setIsParsed(true)
  32. }
  33. const handleSend = () => {
  34. onSend(csvData)
  35. }
  36. const Icon = isAllFinished ? PlayIcon : RiLoader2Line
  37. return (
  38. <div className='pt-4'>
  39. <CSVReader onParsed={handleParsed} />
  40. <CSVDownload vars={vars} />
  41. <div className='mt-4 h-[1px] bg-gray-100'></div>
  42. <div className='flex justify-end'>
  43. <Button
  44. variant="primary"
  45. className='mt-4 pl-3 pr-4'
  46. onClick={handleSend}
  47. disabled={!isParsed || !isAllFinished}
  48. >
  49. <Icon className={cn(!isAllFinished && 'animate-spin', 'shrink-0 w-4 h-4 mr-1')} aria-hidden="true" />
  50. <span className='uppercase text-[13px]'>{t('share.generation.run')}</span>
  51. </Button>
  52. </div>
  53. </div>
  54. )
  55. }
  56. export default React.memo(RunBatch)