| 
									
										
										
										
											2024-06-14 22:02:41 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import React from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							| 
									
										
										
										
											2024-06-20 11:05:08 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   RiDeleteBinLine, | 
					
						
							|  |  |  | } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2024-06-14 22:02:41 +08:00
										 |  |  | import Indicator from '../../../indicator' | 
					
						
							|  |  |  | import Operate from '../data-source-notion/operate' | 
					
						
							|  |  |  | import { DataSourceType } from './types' | 
					
						
							|  |  |  | import s from './style.module.css' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2024-06-14 22:02:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export type ConfigItemType = { | 
					
						
							|  |  |  |   id: string | 
					
						
							|  |  |  |   logo: any | 
					
						
							|  |  |  |   name: string | 
					
						
							|  |  |  |   isActive: boolean | 
					
						
							|  |  |  |   notionConfig?: { | 
					
						
							|  |  |  |     total: number | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Props = { | 
					
						
							|  |  |  |   type: DataSourceType | 
					
						
							|  |  |  |   payload: ConfigItemType | 
					
						
							|  |  |  |   onRemove: () => void | 
					
						
							|  |  |  |   notionActions?: { | 
					
						
							|  |  |  |     onChangeAuthorizedPage: () => void | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-06-17 03:06:32 -05:00
										 |  |  |   readOnly: boolean | 
					
						
							| 
									
										
										
										
											2024-06-14 22:02:41 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ConfigItem: FC<Props> = ({ | 
					
						
							|  |  |  |   type, | 
					
						
							|  |  |  |   payload, | 
					
						
							|  |  |  |   onRemove, | 
					
						
							|  |  |  |   notionActions, | 
					
						
							| 
									
										
										
										
											2024-06-17 03:06:32 -05:00
										 |  |  |   readOnly, | 
					
						
							| 
									
										
										
										
											2024-06-14 22:02:41 +08:00
										 |  |  | }) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  |   const isNotion = type === DataSourceType.notion | 
					
						
							|  |  |  |   const isWebsite = type === DataSourceType.website | 
					
						
							|  |  |  |   const onChangeAuthorizedPage = notionActions?.onChangeAuthorizedPage || function () { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div className={cn(s['workspace-item'], 'flex items-center mb-1 py-1 pr-1 bg-white rounded-lg')} key={payload.id}> | 
					
						
							|  |  |  |       <payload.logo className='ml-3 mr-1.5' /> | 
					
						
							|  |  |  |       <div className='grow py-[7px] leading-[18px] text-[13px] font-medium text-gray-700 truncate' title={payload.name}>{payload.name}</div> | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         payload.isActive | 
					
						
							|  |  |  |           ? <Indicator className='shrink-0 mr-[6px]' /> | 
					
						
							|  |  |  |           : <Indicator className='shrink-0 mr-[6px]' color='yellow' /> | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       <div className='shrink-0 mr-3 text-xs font-medium uppercase'> | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           payload.isActive | 
					
						
							|  |  |  |             ? t(isNotion ? 'common.dataSource.notion.connected' : 'common.dataSource.website.active') | 
					
						
							|  |  |  |             : t(isNotion ? 'common.dataSource.notion.disconnected' : 'common.dataSource.website.inactive') | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       <div className='mr-2 w-[1px] h-3 bg-gray-100' /> | 
					
						
							|  |  |  |       {isNotion && ( | 
					
						
							|  |  |  |         <Operate payload={{ | 
					
						
							|  |  |  |           id: payload.id, | 
					
						
							|  |  |  |           total: payload.notionConfig?.total || 0, | 
					
						
							|  |  |  |         }} onAuthAgain={onChangeAuthorizedPage} | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       )} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2024-06-17 03:06:32 -05:00
										 |  |  |         isWebsite && !readOnly && ( | 
					
						
							| 
									
										
										
										
											2024-06-14 22:02:41 +08:00
										 |  |  |           <div className='p-2 text-gray-500 cursor-pointer rounded-md hover:bg-black/5' onClick={onRemove} > | 
					
						
							| 
									
										
										
										
											2024-06-20 11:05:08 +08:00
										 |  |  |             <RiDeleteBinLine className='w-4 h-4 ' /> | 
					
						
							| 
									
										
										
										
											2024-06-14 22:02:41 +08:00
										 |  |  |           </div> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | export default React.memo(ConfigItem) |