From 8459cb55aded238254c1ebe1505f853807791648 Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Thu, 24 Aug 2023 15:58:36 +0800 Subject: [PATCH] chore(console): code cleanup (#4390) --- packages/console/src/ds-components/Search/index.tsx | 3 --- packages/console/src/hooks/use-api.ts | 7 ++++++- .../components/PlatformTabs/PlatformTab.tsx | 3 --- packages/console/src/pages/ApplicationDetails/index.tsx | 1 - packages/console/src/pages/Dashboard/components/Block.tsx | 3 --- .../pages/Profile/components/LinkAccountSection/index.tsx | 1 + .../WebhookSettings/components/CustomHeaderField/index.tsx | 2 +- 7 files changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/console/src/ds-components/Search/index.tsx b/packages/console/src/ds-components/Search/index.tsx index 965d27fb6..d2e846cf8 100644 --- a/packages/console/src/ds-components/Search/index.tsx +++ b/packages/console/src/ds-components/Search/index.tsx @@ -1,6 +1,5 @@ import type { FormEventHandler, KeyboardEventHandler } from 'react'; import { useState } from 'react'; -import { useTranslation } from 'react-i18next'; import SearchIcon from '@/assets/icons/search.svg'; @@ -27,8 +26,6 @@ function Search({ onClearSearch, }: Props) { const [inputValue, setInputValue] = useState(defaultValue); - const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - const handleSearchKeyPress: KeyboardEventHandler = (event) => { if (event.key === 'Enter' && inputValue) { onSearch?.(inputValue); diff --git a/packages/console/src/hooks/use-api.ts b/packages/console/src/hooks/use-api.ts index 2094f44c6..f41be5098 100644 --- a/packages/console/src/hooks/use-api.ts +++ b/packages/console/src/hooks/use-api.ts @@ -3,6 +3,7 @@ import { useLogto } from '@logto/react'; import { getManagementApiResourceIndicator, type RequestErrorBody } from '@logto/schemas'; import { conditionalArray } from '@silverhand/essentials'; import ky from 'ky'; +import { type KyInstance } from 'node_modules/ky/distribution/types/ky'; import { useCallback, useContext, useMemo } from 'react'; import { toast } from 'react-hot-toast'; import { useTranslation } from 'react-i18next'; @@ -29,7 +30,11 @@ export type StaticApiProps = { resourceIndicator: string; }; -export const useStaticApi = ({ prefixUrl, hideErrorToast, resourceIndicator }: StaticApiProps) => { +export const useStaticApi = ({ + prefixUrl, + hideErrorToast, + resourceIndicator, +}: StaticApiProps): KyInstance => { const { isAuthenticated, getAccessToken, signOut } = useLogto(); const { t, i18n } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { show } = useConfirmModal(); diff --git a/packages/console/src/onboarding/pages/SignInExperience/components/PlatformTabs/PlatformTab.tsx b/packages/console/src/onboarding/pages/SignInExperience/components/PlatformTabs/PlatformTab.tsx index df544357f..7ee756631 100644 --- a/packages/console/src/onboarding/pages/SignInExperience/components/PlatformTabs/PlatformTab.tsx +++ b/packages/console/src/onboarding/pages/SignInExperience/components/PlatformTabs/PlatformTab.tsx @@ -1,7 +1,6 @@ import type { AdminConsoleKey } from '@logto/phrases'; import classNames from 'classnames'; import type { ReactNode } from 'react'; -import { useTranslation } from 'react-i18next'; import type { PreviewPlatform } from '@/components/SignInExperiencePreview/types'; import DynamicT from '@/ds-components/DynamicT'; @@ -18,8 +17,6 @@ type Props = { }; function PlatformTab({ isSelected, icon, title, tab, onClick }: Props) { - const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - return (
function ApplicationDetails() { const { id, guideId, tab } = useParams(); - console.log(tab); const { navigate, match } = useTenantPathname(); const isGuideView = id && guideId && match(`/applications/${id}/guide/${guideId}`); diff --git a/packages/console/src/pages/Dashboard/components/Block.tsx b/packages/console/src/pages/Dashboard/components/Block.tsx index 42c13c682..42e97b1ec 100644 --- a/packages/console/src/pages/Dashboard/components/Block.tsx +++ b/packages/console/src/pages/Dashboard/components/Block.tsx @@ -1,7 +1,6 @@ import type { AdminConsoleKey } from '@logto/phrases'; import { conditionalString } from '@silverhand/essentials'; import classNames from 'classnames'; -import { useTranslation } from 'react-i18next'; import ArrowDown from '@/assets/icons/arrow-down.svg'; import ArrowUp from '@/assets/icons/arrow-up.svg'; @@ -24,8 +23,6 @@ type Props = { }; function Block({ variant = 'default', count, delta, title, tip }: Props) { - const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - const deltaLabel = delta !== undefined && `${conditionalString(delta >= 0 && '+')}${delta}`; return ( diff --git a/packages/console/src/pages/Profile/components/LinkAccountSection/index.tsx b/packages/console/src/pages/Profile/components/LinkAccountSection/index.tsx index 7f25fa7c0..3023268df 100644 --- a/packages/console/src/pages/Profile/components/LinkAccountSection/index.tsx +++ b/packages/console/src/pages/Profile/components/LinkAccountSection/index.tsx @@ -125,6 +125,7 @@ function LinkAccountSection({ user, connectors, onUpdate }: Props) { t, onUpdate, getSocialAuthorizationUri, + getUrl, ]); return ( diff --git a/packages/console/src/pages/WebhookDetails/WebhookSettings/components/CustomHeaderField/index.tsx b/packages/console/src/pages/WebhookDetails/WebhookSettings/components/CustomHeaderField/index.tsx index c892005e3..5fcf3f97c 100644 --- a/packages/console/src/pages/WebhookDetails/WebhookSettings/components/CustomHeaderField/index.tsx +++ b/packages/console/src/pages/WebhookDetails/WebhookSettings/components/CustomHeaderField/index.tsx @@ -48,7 +48,7 @@ function CustomHeaderField() { }; const revalidate = () => { - for (const [index, _] of fields.entries()) { + for (const [index] of fields.entries()) { void trigger(`headers.${index}.key`); if (submitCount > 0) { void trigger(`headers.${index}.value`);