| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import { useState } from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							| 
									
										
										
										
											2024-06-20 11:05:08 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   RiDeleteBinLine, | 
					
						
							| 
									
										
										
										
											2025-03-07 11:56:20 +08:00
										 |  |  |   RiEditLine, | 
					
						
							| 
									
										
										
										
											2024-06-20 11:05:08 +08:00
										 |  |  | } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2025-03-07 11:56:20 +08:00
										 |  |  | import Button from '@/app/components/base/button' | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  | import type { ApiBasedExtension } from '@/models/common' | 
					
						
							|  |  |  | import { useModalContext } from '@/context/modal-context' | 
					
						
							|  |  |  | import { deleteApiBasedExtension } from '@/service/common' | 
					
						
							| 
									
										
										
										
											2024-08-06 14:31:13 +08:00
										 |  |  | import Confirm from '@/app/components/base/confirm' | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type ItemProps = { | 
					
						
							|  |  |  |   data: ApiBasedExtension | 
					
						
							|  |  |  |   onUpdate: () => void | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | const Item: FC<ItemProps> = ({ | 
					
						
							|  |  |  |   data, | 
					
						
							|  |  |  |   onUpdate, | 
					
						
							|  |  |  | }) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  |   const { setShowApiBasedExtensionModal } = useModalContext() | 
					
						
							|  |  |  |   const [showDeleteConfirm, setShowDeleteConfirm] = useState(false) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const handleOpenApiBasedExtensionModal = () => { | 
					
						
							|  |  |  |     setShowApiBasedExtensionModal({ | 
					
						
							|  |  |  |       payload: data, | 
					
						
							|  |  |  |       onSaveCallback: () => onUpdate(), | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const handleDeleteApiBasedExtension = async () => { | 
					
						
							|  |  |  |     await deleteApiBasedExtension(`/api-based-extension/${data.id}`) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     setShowDeleteConfirm(false) | 
					
						
							|  |  |  |     onUpdate() | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |     <div className='group mb-2 flex items-center rounded-xl border-[0.5px] border-transparent bg-components-input-bg-normal px-4 py-2 hover:border-components-input-border-active hover:shadow-xs'> | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |       <div className='grow'> | 
					
						
							| 
									
										
										
										
											2025-03-07 11:56:20 +08:00
										 |  |  |         <div className='mb-0.5 text-[13px] font-medium text-text-secondary'>{data.name}</div> | 
					
						
							|  |  |  |         <div className='text-xs text-text-tertiary'>{data.api_endpoint}</div> | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       <div className='hidden items-center group-hover:flex'> | 
					
						
							| 
									
										
										
										
											2025-03-07 11:56:20 +08:00
										 |  |  |         <Button | 
					
						
							|  |  |  |           className='mr-1' | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |           onClick={handleOpenApiBasedExtensionModal} | 
					
						
							|  |  |  |         > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <RiEditLine className='mr-1 h-4 w-4' /> | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |           {t('common.operation.edit')} | 
					
						
							| 
									
										
										
										
											2025-03-07 11:56:20 +08:00
										 |  |  |         </Button> | 
					
						
							|  |  |  |         <Button | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |           onClick={() => setShowDeleteConfirm(true)} | 
					
						
							|  |  |  |         > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <RiDeleteBinLine className='mr-1 h-4 w-4' /> | 
					
						
							| 
									
										
										
										
											2025-03-07 11:56:20 +08:00
										 |  |  |           {t('common.operation.delete')} | 
					
						
							|  |  |  |         </Button> | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |       </div> | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2024-08-06 14:31:13 +08:00
										 |  |  |         showDeleteConfirm | 
					
						
							|  |  |  |           && <Confirm | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |             isShow={showDeleteConfirm} | 
					
						
							|  |  |  |             onCancel={() => setShowDeleteConfirm(false)} | 
					
						
							|  |  |  |             title={`${t('common.operation.delete')} “${data.name}”?`} | 
					
						
							|  |  |  |             onConfirm={handleDeleteApiBasedExtension} | 
					
						
							|  |  |  |             confirmText={t('common.operation.delete') || ''} | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default Item |