🐛 fix(oauth): Refactor OAuth configuration types and update related API methods
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { getOAuthConfig, oAuthCreateConfig, updateOAuthConfig } from '@/services/admin/system';
|
||||
import { getOAuthByPlatform, updateOAuthConfig } from '@/services/admin/system';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { Label } from '@workspace/ui/components/label';
|
||||
import { Switch } from '@workspace/ui/components/switch';
|
||||
@@ -13,35 +13,28 @@ export default function Page() {
|
||||
const t = useTranslations('github');
|
||||
|
||||
const { data, refetch } = useQuery({
|
||||
queryKey: ['getOAuthConfig', 'github'],
|
||||
queryKey: ['getOAuthByPlatform', 'github'],
|
||||
queryFn: async () => {
|
||||
const { data } = await getOAuthConfig();
|
||||
return data.data?.list.find((item) => item.platform === 'github') as API.OAuthConfig;
|
||||
const { data } = await getOAuthByPlatform({
|
||||
platform: 'github',
|
||||
});
|
||||
return data.data;
|
||||
},
|
||||
});
|
||||
|
||||
async function updateConfig(key: keyof API.OAuthConfig, value: unknown) {
|
||||
async function updateConfig(key: keyof API.UpdateOAuthConfig, value: unknown) {
|
||||
if (data?.[key] === value) return;
|
||||
try {
|
||||
if (data?.id) {
|
||||
await oAuthCreateConfig({
|
||||
...data,
|
||||
platform: 'github',
|
||||
[key]: value,
|
||||
} as API.OAuthConfig);
|
||||
} else {
|
||||
await updateOAuthConfig({
|
||||
...data,
|
||||
[key]: value,
|
||||
} as API.OAuthConfig);
|
||||
}
|
||||
await updateOAuthConfig({
|
||||
...data,
|
||||
[key]: value,
|
||||
} as API.UpdateOAuthConfig);
|
||||
toast.success(t('saveSuccess'));
|
||||
refetch();
|
||||
} catch (error) {
|
||||
toast.error(t('saveFailed'));
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Table>
|
||||
<TableBody>
|
||||
@@ -65,8 +58,13 @@ export default function Page() {
|
||||
<TableCell className='text-right'>
|
||||
<EnhancedInput
|
||||
placeholder='e.g., Iv1.1234567890abcdef'
|
||||
value={data?.client_id}
|
||||
onValueBlur={(value) => updateConfig('client_id', value)}
|
||||
value={data?.config?.client_id}
|
||||
onValueBlur={(value) =>
|
||||
updateConfig('config', {
|
||||
...data?.config,
|
||||
client_id: value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
@@ -78,8 +76,13 @@ export default function Page() {
|
||||
<TableCell className='text-right'>
|
||||
<EnhancedInput
|
||||
placeholder='e.g., 1234567890abcdef1234567890abcdef12345678'
|
||||
value={data?.client_secret}
|
||||
onValueBlur={(value) => updateConfig('client_secret', value)}
|
||||
value={data?.config?.client_secret}
|
||||
onValueBlur={(value) => {
|
||||
updateConfig('config', {
|
||||
...data?.config,
|
||||
client_secret: value,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
Reference in New Issue
Block a user