index.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import type { FC, ReactNode } from 'react'
  2. import React, { memo } from 'react'
  3. import Card from '@/app/components/plugins/card'
  4. import Modal from '@/app/components/base/modal'
  5. import Button from '@/app/components/base/button'
  6. import type { Plugin } from '../types'
  7. import type { UseMutationResult } from '@tanstack/react-query'
  8. type Props = {
  9. plugin: Plugin
  10. onCancel: () => void
  11. mutation: Pick<UseMutationResult, 'isSuccess' | 'isPending'>
  12. mutate: () => void
  13. confirmButtonText: ReactNode
  14. cancelButtonText: ReactNode
  15. modelTitle: ReactNode
  16. description: ReactNode
  17. cardTitleLeft: ReactNode
  18. modalBottomLeft?: ReactNode
  19. }
  20. const PluginMutationModal: FC<Props> = ({
  21. plugin,
  22. onCancel,
  23. mutation,
  24. confirmButtonText,
  25. cancelButtonText,
  26. modelTitle,
  27. description,
  28. cardTitleLeft,
  29. mutate,
  30. modalBottomLeft,
  31. }: Props) => {
  32. return (
  33. <Modal
  34. isShow={true}
  35. onClose={onCancel}
  36. className='min-w-[560px]'
  37. closable
  38. title={modelTitle}
  39. >
  40. <div className='mt-3 mb-2 text-text-secondary system-md-regular'>
  41. {description}
  42. </div>
  43. <div className='flex p-2 items-start content-start gap-1 self-stretch flex-wrap rounded-2xl bg-background-section-burn'>
  44. <Card
  45. installed={mutation.isSuccess}
  46. payload={plugin}
  47. className='w-full'
  48. titleLeft={cardTitleLeft}
  49. />
  50. </div>
  51. <div className='flex pt-5 items-center gap-2 self-stretch'>
  52. <div>
  53. {modalBottomLeft}
  54. </div>
  55. <div className='ml-auto flex gap-2'>
  56. {!mutation.isPending && (
  57. <Button onClick={onCancel}>
  58. {cancelButtonText}
  59. </Button>
  60. )}
  61. <Button
  62. variant='primary'
  63. loading={mutation.isPending}
  64. onClick={mutate}
  65. disabled={mutation.isPending}
  66. >
  67. {confirmButtonText}
  68. </Button>
  69. </div>
  70. </div>
  71. </Modal>
  72. )
  73. }
  74. PluginMutationModal.displayName = 'PluginMutationModal'
  75. export default memo(PluginMutationModal)