From 6227ba91d07c346f1ddd5dc5d802253fc5e51f24 Mon Sep 17 00:00:00 2001 From: "web@ppanel" Date: Sun, 19 Jan 2025 22:34:12 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(oauth):=20Refactor=20OAuth?= =?UTF-8?q?=20configuration=20types=20and=20update=20related=20API=20metho?= =?UTF-8?q?ds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/dashboard/auth-control/apple/page.tsx | 86 +++++++++++-------- .../dashboard/auth-control/facebook/page.tsx | 46 +++++----- .../dashboard/auth-control/github/page.tsx | 47 +++++----- .../dashboard/auth-control/google/page.tsx | 46 +++++----- .../dashboard/auth-control/telegram/page.tsx | 46 +++++----- apps/admin/services/admin/system.ts | 25 +++--- apps/admin/services/admin/typings.d.ts | 46 +++++----- apps/admin/services/common/typings.d.ts | 22 ++--- 8 files changed, 201 insertions(+), 163 deletions(-) diff --git a/apps/admin/app/dashboard/auth-control/apple/page.tsx b/apps/admin/app/dashboard/auth-control/apple/page.tsx index 97cb5ff..54f16ae 100644 --- a/apps/admin/app/dashboard/auth-control/apple/page.tsx +++ b/apps/admin/app/dashboard/auth-control/apple/page.tsx @@ -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'; @@ -14,28 +14,22 @@ export default function Page() { const t = useTranslations('apple'); const { data, refetch } = useQuery({ - queryKey: ['getOAuthConfig', 'apple'], + queryKey: ['getOAuthByPlatform', 'apple'], queryFn: async () => { - const { data } = await getOAuthConfig(); - return data.data?.list.find((item) => item.platform === 'apple') as API.OAuthConfig; + const { data } = await getOAuthByPlatform({ + platform: 'apple', + }); + 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: 'apple', - [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) { @@ -66,21 +60,13 @@ export default function Page() { updateConfig('team_id', value)} - /> - - - - - -

{t('clientIdDescription')}

-
- - updateConfig('client_id', value)} + value={data?.config?.team_id} + onValueBlur={(value) => { + updateConfig('config', { + ...data?.config, + team_id: value, + }); + }} />
@@ -92,8 +78,31 @@ export default function Page() { updateConfig('key_id', value)} + value={data?.config?.key_id} + onValueBlur={(value) => { + updateConfig('config', { + ...data?.config, + key_id: value, + }); + }} + /> + + + + + +

{t('clientIdDescription')}

+
+ + { + updateConfig('config', { + ...data?.config, + client_id: value, + }); + }} />
@@ -106,8 +115,13 @@ export default function Page() {