index.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { useState } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { XMarkIcon } from '@heroicons/react/24/outline'
  4. import NotionPageSelector from '../base'
  5. import s from './index.module.css'
  6. import type { NotionPage } from '@/models/common'
  7. import cn from '@/utils/classnames'
  8. import Modal from '@/app/components/base/modal'
  9. type NotionPageSelectorModalProps = {
  10. isShow: boolean
  11. onClose: () => void
  12. onSave: (selectedPages: NotionPage[]) => void
  13. datasetId: string
  14. }
  15. const NotionPageSelectorModal = ({
  16. isShow,
  17. onClose,
  18. onSave,
  19. datasetId,
  20. }: NotionPageSelectorModalProps) => {
  21. const { t } = useTranslation()
  22. const [selectedPages, setSelectedPages] = useState<NotionPage[]>([])
  23. const handleClose = () => {
  24. onClose()
  25. }
  26. const handleSelectPage = (newSelectedPages: NotionPage[]) => {
  27. setSelectedPages(newSelectedPages)
  28. }
  29. const handleSave = () => {
  30. onSave(selectedPages)
  31. }
  32. return (
  33. <Modal
  34. className={s.modal}
  35. isShow={isShow}
  36. onClose={() => { }}
  37. >
  38. <div className='flex items-center justify-between mb-6 h-8'>
  39. <div className='text-xl font-semibold text-gray-900'>{t('common.dataSource.notion.selector.addPages')}</div>
  40. <div
  41. className='flex items-center justify-center -mr-2 w-8 h-8 cursor-pointer'
  42. onClick={handleClose}>
  43. <XMarkIcon className='w-4 h-4' />
  44. </div>
  45. </div>
  46. <NotionPageSelector
  47. onSelect={handleSelectPage}
  48. canPreview={false}
  49. datasetId={datasetId}
  50. />
  51. <div className='mt-8 flex justify-end'>
  52. <div className={s.operate} onClick={handleClose}>{t('common.operation.cancel')}</div>
  53. <div className={cn(s.operate, s['operate-save'])} onClick={handleSave}>{t('common.operation.save')}</div>
  54. </div>
  55. </Modal>
  56. )
  57. }
  58. export default NotionPageSelectorModal