| 
									
										
										
										
											2023-08-12 00:57:13 +08:00
										 |  |  | import type { FC, ReactElement } from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							|  |  |  | import cn from 'classnames' | 
					
						
							|  |  |  | import s from './common.module.css' | 
					
						
							|  |  |  | import Modal from '@/app/components/base/modal' | 
					
						
							|  |  |  | import { XClose } from '@/app/components/base/icons/src/vender/line/general' | 
					
						
							|  |  |  | import { AlertCircle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback' | 
					
						
							| 
									
										
										
										
											2023-08-17 15:49:22 +08:00
										 |  |  | import { CheckCircle } from '@/app/components/base/icons/src/vender/solid/general' | 
					
						
							| 
									
										
										
										
											2023-08-12 00:57:13 +08:00
										 |  |  | import Button from '@/app/components/base/button' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-11 17:30:54 +08:00
										 |  |  | export type ConfirmCommonProps = { | 
					
						
							| 
									
										
										
										
											2023-08-12 00:57:13 +08:00
										 |  |  |   type?: string | 
					
						
							|  |  |  |   isShow: boolean | 
					
						
							|  |  |  |   onCancel: () => void | 
					
						
							|  |  |  |   title: string | 
					
						
							|  |  |  |   desc?: string | 
					
						
							| 
									
										
										
										
											2023-08-17 15:49:22 +08:00
										 |  |  |   onConfirm?: () => void | 
					
						
							|  |  |  |   showOperate?: boolean | 
					
						
							|  |  |  |   showOperateCancel?: boolean | 
					
						
							| 
									
										
										
										
											2023-09-27 14:53:22 +08:00
										 |  |  |   confirmBtnClassName?: string | 
					
						
							| 
									
										
										
										
											2023-08-17 15:49:22 +08:00
										 |  |  |   confirmText?: string | 
					
						
							| 
									
										
										
										
											2023-10-26 10:35:03 +08:00
										 |  |  |   confirmWrapperClassName?: string | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |   confirmDisabled?: boolean | 
					
						
							| 
									
										
										
										
											2023-08-12 00:57:13 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ConfirmCommon: FC<ConfirmCommonProps> = ({ | 
					
						
							|  |  |  |   type = 'danger', | 
					
						
							|  |  |  |   isShow, | 
					
						
							|  |  |  |   onCancel, | 
					
						
							|  |  |  |   title, | 
					
						
							|  |  |  |   desc, | 
					
						
							|  |  |  |   onConfirm, | 
					
						
							| 
									
										
										
										
											2023-08-17 15:49:22 +08:00
										 |  |  |   showOperate = true, | 
					
						
							|  |  |  |   showOperateCancel = true, | 
					
						
							| 
									
										
										
										
											2023-09-27 14:53:22 +08:00
										 |  |  |   confirmBtnClassName, | 
					
						
							| 
									
										
										
										
											2023-08-17 15:49:22 +08:00
										 |  |  |   confirmText, | 
					
						
							| 
									
										
										
										
											2023-10-26 10:35:03 +08:00
										 |  |  |   confirmWrapperClassName, | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |   confirmDisabled, | 
					
						
							| 
									
										
										
										
											2023-08-12 00:57:13 +08:00
										 |  |  | }) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const CONFIRM_MAP: Record<string, { icon: ReactElement; confirmText: string }> = { | 
					
						
							|  |  |  |     danger: { | 
					
						
							|  |  |  |       icon: <AlertCircle className='w-6 h-6 text-[#D92D20]' />, | 
					
						
							|  |  |  |       confirmText: t('common.operation.remove'), | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2023-08-17 15:49:22 +08:00
										 |  |  |     success: { | 
					
						
							|  |  |  |       icon: <CheckCircle className='w-6 h-6 text-[#039855]' />, | 
					
						
							|  |  |  |       confirmText: t('common.operation.ok'), | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2023-08-12 00:57:13 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2023-10-26 10:35:03 +08:00
										 |  |  |     <Modal isShow={isShow} onClose={() => {}} className='!w-[480px] !max-w-[480px] !p-0 !rounded-2xl' wrapperClassName={confirmWrapperClassName}> | 
					
						
							| 
									
										
										
										
											2023-08-17 15:49:22 +08:00
										 |  |  |       <div className={cn(s[`wrapper-${type}`], 'relative p-8')}> | 
					
						
							| 
									
										
										
										
											2023-08-12 00:57:13 +08:00
										 |  |  |         <div className='flex items-center justify-center absolute top-4 right-4 w-8 h-8 cursor-pointer' onClick={onCancel}> | 
					
						
							|  |  |  |           <XClose className='w-4 h-4 text-gray-500' /> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |         <div className='flex items-center justify-center mb-3 w-12 h-12 bg-white shadow-xl rounded-xl'> | 
					
						
							|  |  |  |           {CONFIRM_MAP[type].icon} | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |         <div className='text-xl font-semibold text-gray-900'>{title}</div> | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           desc && <div className='mt-1 text-sm text-gray-500'>{desc}</div> | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-08-17 15:49:22 +08:00
										 |  |  |         { | 
					
						
							|  |  |  |           showOperate && ( | 
					
						
							|  |  |  |             <div className='flex items-center justify-end mt-10'> | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                 showOperateCancel && ( | 
					
						
							|  |  |  |                   <Button | 
					
						
							|  |  |  |                     className='mr-2 min-w-24 text-sm font-medium !text-gray-700' | 
					
						
							|  |  |  |                     onClick={onCancel} | 
					
						
							|  |  |  |                   > | 
					
						
							|  |  |  |                     {t('common.operation.cancel')} | 
					
						
							|  |  |  |                   </Button> | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               <Button | 
					
						
							|  |  |  |                 type='primary' | 
					
						
							| 
									
										
										
										
											2023-09-27 14:53:22 +08:00
										 |  |  |                 className={confirmBtnClassName || ''} | 
					
						
							| 
									
										
										
										
											2023-08-17 15:49:22 +08:00
										 |  |  |                 onClick={onConfirm} | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |                 disabled={confirmDisabled} | 
					
						
							| 
									
										
										
										
											2023-08-17 15:49:22 +08:00
										 |  |  |               > | 
					
						
							|  |  |  |                 {confirmText || CONFIRM_MAP[type].confirmText} | 
					
						
							|  |  |  |               </Button> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-08-12 00:57:13 +08:00
										 |  |  |       </div> | 
					
						
							|  |  |  |     </Modal> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default ConfirmCommon |