index.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { useTranslation } from 'react-i18next'
  2. import useSWR from 'swr'
  3. import {
  4. RiAddLine,
  5. } from '@remixicon/react'
  6. import Item from './item'
  7. import Empty from './empty'
  8. import { useModalContext } from '@/context/modal-context'
  9. import { fetchApiBasedExtensionList } from '@/service/common'
  10. const ApiBasedExtensionPage = () => {
  11. const { t } = useTranslation()
  12. const { setShowApiBasedExtensionModal } = useModalContext()
  13. const { data, mutate, isLoading } = useSWR(
  14. '/api-based-extension',
  15. fetchApiBasedExtensionList,
  16. )
  17. const handleOpenApiBasedExtensionModal = () => {
  18. setShowApiBasedExtensionModal({
  19. payload: {},
  20. onSaveCallback: () => mutate(),
  21. })
  22. }
  23. return (
  24. <div>
  25. {
  26. !isLoading && !data?.length && (
  27. <Empty />
  28. )
  29. }
  30. {
  31. !isLoading && !!data?.length && (
  32. data.map(item => (
  33. <Item
  34. key={item.id}
  35. data={item}
  36. onUpdate={() => mutate()}
  37. />
  38. ))
  39. )
  40. }
  41. <div
  42. className='flex items-center justify-center px-3 h-8 text-[13px] font-medium text-gray-700 rounded-lg bg-gray-50 cursor-pointer'
  43. onClick={handleOpenApiBasedExtensionModal}
  44. >
  45. <RiAddLine className='mr-2 w-4 h-4' />
  46. {t('common.apiBasedExtension.add')}
  47. </div>
  48. </div>
  49. )
  50. }
  51. export default ApiBasedExtensionPage