common.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import type { FC, ReactElement } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import cn from 'classnames'
  4. import s from './common.module.css'
  5. import Modal from '@/app/components/base/modal'
  6. import { XClose } from '@/app/components/base/icons/src/vender/line/general'
  7. import { AlertCircle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback'
  8. import Button from '@/app/components/base/button'
  9. type ConfirmCommonProps = {
  10. type?: string
  11. isShow: boolean
  12. onCancel: () => void
  13. title: string
  14. desc?: string
  15. onConfirm: () => void
  16. }
  17. const ConfirmCommon: FC<ConfirmCommonProps> = ({
  18. type = 'danger',
  19. isShow,
  20. onCancel,
  21. title,
  22. desc,
  23. onConfirm,
  24. }) => {
  25. const { t } = useTranslation()
  26. const CONFIRM_MAP: Record<string, { icon: ReactElement; confirmText: string }> = {
  27. danger: {
  28. icon: <AlertCircle className='w-6 h-6 text-[#D92D20]' />,
  29. confirmText: t('common.operation.remove'),
  30. },
  31. }
  32. return (
  33. <Modal isShow={isShow} onClose={() => {}} className='!w-[480px] !max-w-[480px] !p-0 !rounded-2xl'>
  34. <div className={cn(s.wrapper, 'relative p-8')}>
  35. <div className='flex items-center justify-center absolute top-4 right-4 w-8 h-8 cursor-pointer' onClick={onCancel}>
  36. <XClose className='w-4 h-4 text-gray-500' />
  37. </div>
  38. <div className='flex items-center justify-center mb-3 w-12 h-12 bg-white shadow-xl rounded-xl'>
  39. {CONFIRM_MAP[type].icon}
  40. </div>
  41. <div className='text-xl font-semibold text-gray-900'>{title}</div>
  42. {
  43. desc && <div className='mt-1 text-sm text-gray-500'>{desc}</div>
  44. }
  45. <div className='flex items-center justify-end mt-10'>
  46. <Button
  47. className='mr-2 min-w-24 text-sm font-medium !text-gray-700'
  48. onClick={onCancel}
  49. >
  50. {t('common.operation.cancel')}
  51. </Button>
  52. <Button
  53. type='primary'
  54. className=''
  55. onClick={onConfirm}
  56. >
  57. {CONFIRM_MAP[type].confirmText}
  58. </Button>
  59. </div>
  60. </div>
  61. </Modal>
  62. )
  63. }
  64. export default ConfirmCommon