| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | import { useState } from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							|  |  |  | import { XMarkIcon } from '@heroicons/react/24/outline' | 
					
						
							|  |  |  | import NotionPageSelector from '../base' | 
					
						
							|  |  |  | import s from './index.module.css' | 
					
						
							| 
									
										
										
										
											2024-07-25 11:21:51 +08:00
										 |  |  | import type { NotionPage } from '@/models/common' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | import Modal from '@/app/components/base/modal' | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  | import { noop } from 'lodash-es' | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type NotionPageSelectorModalProps = { | 
					
						
							|  |  |  |   isShow: boolean | 
					
						
							|  |  |  |   onClose: () => void | 
					
						
							| 
									
										
										
										
											2024-07-25 11:21:51 +08:00
										 |  |  |   onSave: (selectedPages: NotionPage[]) => void | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  |   datasetId: string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | const NotionPageSelectorModal = ({ | 
					
						
							|  |  |  |   isShow, | 
					
						
							|  |  |  |   onClose, | 
					
						
							|  |  |  |   onSave, | 
					
						
							|  |  |  |   datasetId, | 
					
						
							|  |  |  | }: NotionPageSelectorModalProps) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							| 
									
										
										
										
											2024-07-25 11:21:51 +08:00
										 |  |  |   const [selectedPages, setSelectedPages] = useState<NotionPage[]>([]) | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const handleClose = () => { | 
					
						
							|  |  |  |     onClose() | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-07-25 11:21:51 +08:00
										 |  |  |   const handleSelectPage = (newSelectedPages: NotionPage[]) => { | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  |     setSelectedPages(newSelectedPages) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const handleSave = () => { | 
					
						
							|  |  |  |     onSave(selectedPages) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <Modal | 
					
						
							|  |  |  |       className={s.modal} | 
					
						
							|  |  |  |       isShow={isShow} | 
					
						
							| 
									
										
										
										
											2025-04-06 17:56:08 +08:00
										 |  |  |       onClose={noop} | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  |     > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       <div className='mb-6 flex h-8 items-center justify-between'> | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  |         <div className='text-xl font-semibold text-gray-900'>{t('common.dataSource.notion.selector.addPages')}</div> | 
					
						
							|  |  |  |         <div | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           className='-mr-2 flex h-8 w-8 cursor-pointer items-center justify-center' | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  |           onClick={handleClose}> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <XMarkIcon className='h-4 w-4' /> | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  |         </div> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       <NotionPageSelector | 
					
						
							|  |  |  |         onSelect={handleSelectPage} | 
					
						
							|  |  |  |         canPreview={false} | 
					
						
							|  |  |  |         datasetId={datasetId} | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |       <div className='mt-8 flex justify-end'> | 
					
						
							|  |  |  |         <div className={s.operate} onClick={handleClose}>{t('common.operation.cancel')}</div> | 
					
						
							|  |  |  |         <div className={cn(s.operate, s['operate-save'])} onClick={handleSave}>{t('common.operation.save')}</div> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     </Modal> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default NotionPageSelectorModal |