item.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import type { FC } from 'react'
  2. import { useState } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import { Edit02, Trash03 } from '@/app/components/base/icons/src/vender/line/general'
  5. import type { ApiBasedExtension } from '@/models/common'
  6. import { useModalContext } from '@/context/modal-context'
  7. import { deleteApiBasedExtension } from '@/service/common'
  8. import ConfirmCommon from '@/app/components/base/confirm/common'
  9. type ItemProps = {
  10. data: ApiBasedExtension
  11. onUpdate: () => void
  12. }
  13. const Item: FC<ItemProps> = ({
  14. data,
  15. onUpdate,
  16. }) => {
  17. const { t } = useTranslation()
  18. const { setShowApiBasedExtensionModal } = useModalContext()
  19. const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
  20. const handleOpenApiBasedExtensionModal = () => {
  21. setShowApiBasedExtensionModal({
  22. payload: data,
  23. onSaveCallback: () => onUpdate(),
  24. })
  25. }
  26. const handleDeleteApiBasedExtension = async () => {
  27. await deleteApiBasedExtension(`/api-based-extension/${data.id}`)
  28. setShowDeleteConfirm(false)
  29. onUpdate()
  30. }
  31. return (
  32. <div className='group flex items-center mb-2 px-4 py-2 border-[0.5px] border-transparent rounded-xl bg-gray-50 hover:border-gray-200 hover:shadow-xs'>
  33. <div className='grow'>
  34. <div className='mb-0.5 text-[13px] font-medium text-gray-700'>{data.name}</div>
  35. <div className='text-xs text-gray-500'>{data.api_endpoint}</div>
  36. </div>
  37. <div className='hidden group-hover:flex items-center'>
  38. <div
  39. className='flex items-center mr-1 px-3 h-7 bg-white text-xs font-medium text-gray-700 rounded-md border-[0.5px] border-gray-200 shadow-xs cursor-pointer'
  40. onClick={handleOpenApiBasedExtensionModal}
  41. >
  42. <Edit02 className='mr-[5px] w-3.5 h-3.5' />
  43. {t('common.operation.edit')}
  44. </div>
  45. <div
  46. className='flex items-center justify-center w-7 h-7 bg-white text-gray-700 rounded-md border-[0.5px] border-gray-200 shadow-xs cursor-pointer'
  47. onClick={() => setShowDeleteConfirm(true)}
  48. >
  49. <Trash03 className='w-4 h-4' />
  50. </div>
  51. </div>
  52. {
  53. showDeleteConfirm && (
  54. <ConfirmCommon
  55. type='danger'
  56. isShow={showDeleteConfirm}
  57. onCancel={() => setShowDeleteConfirm(false)}
  58. title={`${t('common.operation.delete')} “${data.name}”?`}
  59. onConfirm={handleDeleteApiBasedExtension}
  60. confirmWrapperClassName='!z-30'
  61. confirmText={t('common.operation.delete') || ''}
  62. confirmBtnClassName='!bg-[#D92D20]'
  63. />
  64. )
  65. }
  66. </div>
  67. )
  68. }
  69. export default Item