refactor: migrate common service toward TanStack Query (#29009)

This commit is contained in:
yyh
2025-12-19 17:34:14 +08:00
committed by GitHub
parent 89e4261883
commit 079620714e
33 changed files with 885 additions and 633 deletions

View File

@@ -1,11 +1,10 @@
'use client'
import { useTranslation } from 'react-i18next'
import useSWR from 'swr'
import Link from 'next/link'
import s from './index.module.css'
import { cn } from '@/utils/classnames'
import { fetchAccountIntegrates } from '@/service/common'
import { useAccountIntegrates } from '@/service/use-common'
const titleClassName = `
mb-2 text-sm font-medium text-gray-900
@@ -25,33 +24,38 @@ export default function IntegrationsPage() {
},
}
const { data } = useSWR({ url: '/account/integrates' }, fetchAccountIntegrates)
const integrates = data?.data?.length ? data.data : []
const { data } = useAccountIntegrates()
const integrates = data?.data ?? []
return (
<>
<div className='mb-8'>
<div className={titleClassName}>{t('common.integrations.connected')}</div>
{
integrates.map(integrate => (
<div key={integrate.provider} className='mb-2 flex items-center rounded-lg border-[0.5px] border-gray-200 bg-gray-50 px-3 py-2'>
<div className={cn('mr-3 h-8 w-8 rounded-lg border border-gray-100 bg-white', s[`${integrate.provider}-icon`])} />
<div className='grow'>
<div className='text-sm font-medium leading-[21px] text-gray-800'>{integrateMap[integrate.provider].name}</div>
<div className='text-xs font-normal leading-[18px] text-gray-500'>{integrateMap[integrate.provider].description}</div>
integrates.map((integrate) => {
const info = integrateMap[integrate.provider]
if (!info)
return null
return (
<div key={integrate.provider} className='mb-2 flex items-center rounded-lg border-[0.5px] border-gray-200 bg-gray-50 px-3 py-2'>
<div className={cn('mr-3 h-8 w-8 rounded-lg border border-gray-100 bg-white', s[`${integrate.provider}-icon`])} />
<div className='grow'>
<div className='text-sm font-medium leading-[21px] text-gray-800'>{info.name}</div>
<div className='text-xs font-normal leading-[18px] text-gray-500'>{info.description}</div>
</div>
{
!integrate.is_bound && (
<Link
className='flex h-8 cursor-pointer items-center rounded-lg border border-gray-200 bg-white px-[7px] text-xs font-medium text-gray-700'
href={integrate.link}
target='_blank' rel='noopener noreferrer'>
{t('common.integrations.connect')}
</Link>
)
}
</div>
{
!integrate.is_bound && (
<Link
className='flex h-8 cursor-pointer items-center rounded-lg border border-gray-200 bg-white px-[7px] text-xs font-medium text-gray-700'
href={integrate.link}
target='_blank' rel='noopener noreferrer'>
{t('common.integrations.connect')}
</Link>
)
}
</div>
))
)
})
}
</div>
{/* <div className='mb-8'>