From fa3bc20986fcc1c6fd9416fb1dd53ddba59411af Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Tue, 12 Sep 2023 22:04:32 +0800 Subject: [PATCH] feat(console): add api resource guide cards in get-started page (#4465) --- .../Guide/GuideCard/index.module.scss | 4 ++ .../console/src/pages/GetStarted/index.tsx | 57 +++++++++++++++---- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/packages/console/src/components/Guide/GuideCard/index.module.scss b/packages/console/src/components/Guide/GuideCard/index.module.scss index 7f829d685..9548f8438 100644 --- a/packages/console/src/components/Guide/GuideCard/index.module.scss +++ b/packages/console/src/components/Guide/GuideCard/index.module.scss @@ -17,6 +17,10 @@ cursor: default; } + &:not(.hasButton):hover { + box-shadow: var(--shadow-2); + } + &.hasBorder { border-color: var(--color-divider); } diff --git a/packages/console/src/pages/GetStarted/index.tsx b/packages/console/src/pages/GetStarted/index.tsx index 7a994d2d4..c2146010b 100644 --- a/packages/console/src/pages/GetStarted/index.tsx +++ b/packages/console/src/pages/GetStarted/index.tsx @@ -1,5 +1,5 @@ import { withAppInsights } from '@logto/app-insights/react'; -import { Theme, type Application } from '@logto/schemas'; +import { Theme, type Application, type Resource } from '@logto/schemas'; import classNames from 'classnames'; import { useCallback, useContext, useMemo, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; @@ -12,7 +12,7 @@ import SocialDark from '@/assets/icons/social-dark.svg'; import Social from '@/assets/icons/social.svg'; import { type SelectedGuide } from '@/components/Guide/GuideCard'; import GuideCardGroup from '@/components/Guide/GuideCardGroup'; -import { useAppGuideMetadata } from '@/components/Guide/hooks'; +import { useApiGuideMetadata, useAppGuideMetadata } from '@/components/Guide/hooks'; import PageMeta from '@/components/PageMeta'; import { ConnectorsTabs } from '@/consts'; import { AppDataContext } from '@/contexts/AppDataProvider'; @@ -24,7 +24,8 @@ import useTenantPathname from '@/hooks/use-tenant-pathname'; import useTheme from '@/hooks/use-theme'; import useWindowResize from '@/hooks/use-window-resize'; -import CreateForm from '../Applications/components/CreateForm'; +import CreateApiForm from '../ApiResources/components/CreateForm'; +import CreateAppForm from '../Applications/components/CreateForm'; import FreePlanNotification from './FreePlanNotification'; import * as styles from './index.module.scss'; @@ -40,7 +41,9 @@ function GetStarted() { const { tenantEndpoint } = useContext(AppDataContext); const [selectedGuide, setSelectedGuide] = useState(); const { getStructuredAppGuideMetadata } = useAppGuideMetadata(); - const [showCreateForm, setShowCreateForm] = useState(false); + const apiGuideMetadata = useApiGuideMetadata(); + const [showCreateAppForm, setShowCreateAppForm] = useState(false); + const [showCreateApiForm, setShowCreateApiForm] = useState(false); // The number of visible guide cards to show in one row per the current screen width const [visibleCardCount, setVisibleCardCount] = useState(4); const containerRef = useRef(null); @@ -63,18 +66,35 @@ function GetStarted() { [visibleCardCount, getStructuredAppGuideMetadata] ); - const onClickGuide = useCallback((data: SelectedGuide) => { - setShowCreateForm(true); + const onClickAppGuide = useCallback((data: SelectedGuide) => { + setShowCreateAppForm(true); setSelectedGuide(data); }, []); - const onCloseCreateForm = useCallback( + const onCloseCreateAppForm = useCallback( (newApp?: Application) => { if (newApp && selectedGuide) { navigate(`/applications/${newApp.id}/guide/${selectedGuide.id}`, { replace: true }); return; } - setShowCreateForm(false); + setShowCreateAppForm(false); + setSelectedGuide(undefined); + }, + [navigate, selectedGuide] + ); + + const onClickApiGuide = useCallback((data: SelectedGuide) => { + setShowCreateApiForm(true); + setSelectedGuide(data); + }, []); + + const onCloseCreateApiForm = useCallback( + (newResource?: Resource) => { + if (newResource && selectedGuide) { + navigate(`/api-resources/${newResource.id}/guide/${selectedGuide.id}`, { replace: true }); + return; + } + setShowCreateApiForm(false); setSelectedGuide(undefined); }, [navigate, selectedGuide] @@ -93,14 +113,15 @@ function GetStarted() { - {selectedGuide?.target !== 'API' && showCreateForm && ( - )} {t('get_started.view_all')} @@ -147,6 +168,18 @@ function GetStarted() { /> + +
{t('get_started.secure.title')}
+ + {showCreateApiForm && } + {t('get_started.view_all')} +
{t('get_started.manage.title')}