From bed56beff570d66094f8a1a6376650e8b984424a Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Sun, 16 Jun 2024 15:30:53 +0800 Subject: [PATCH] refactor(console): use dynamic step component for connector guide --- .../src/pages/Connectors/Guide/Steps.tsx | 46 ++++++++++++++ .../src/pages/Connectors/Guide/index.tsx | 63 ++++++++----------- 2 files changed, 73 insertions(+), 36 deletions(-) create mode 100644 packages/console/src/pages/Connectors/Guide/Steps.tsx diff --git a/packages/console/src/pages/Connectors/Guide/Steps.tsx b/packages/console/src/pages/Connectors/Guide/Steps.tsx new file mode 100644 index 00000000000..580493454e6 --- /dev/null +++ b/packages/console/src/pages/Connectors/Guide/Steps.tsx @@ -0,0 +1,46 @@ +import { type LocalePhrase } from '@logto/phrases'; +import React, { type ReactNode, type ReactElement } from 'react'; +import { useTranslation } from 'react-i18next'; + +import * as styles from './index.module.scss'; + +type CanBeArray = T | T[]; + +type StepProps = { + readonly children: ReactNode; + readonly index?: number; + readonly tKey: keyof LocalePhrase['translation']['admin_console']['connectors']['guide']; +}; + +export function Step({ children, index, tKey }: StepProps) { + const { t } = useTranslation(undefined, { keyPrefix: 'admin_console.connectors.guide' }); + + return ( +
+
+
{index}
+
{t(tKey)}
+
+ {children} +
+ ); +} + +type Props = { + readonly children: CanBeArray | boolean>; +}; + +function Steps({ children }: Props) { + return ( + <> + {React.Children.map(children, (child, index) => { + return ( + typeof child !== 'boolean' && + React.cloneElement(child, { key: child.key, index: index + 1 }) + ); + })} + + ); +} + +export default Steps; diff --git a/packages/console/src/pages/Connectors/Guide/index.tsx b/packages/console/src/pages/Connectors/Guide/index.tsx index 68ce4d20c41..0b03293b31b 100644 --- a/packages/console/src/pages/Connectors/Guide/index.tsx +++ b/packages/console/src/pages/Connectors/Guide/index.tsx @@ -33,6 +33,7 @@ import { trySubmitSafe } from '@/utils/form'; import { splitMarkdownByTitle } from '../utils'; +import Steps, { Step } from './Steps'; import * as styles from './index.module.scss'; const targetErrorCode = 'connector.multiple_target_with_same_platform'; @@ -187,44 +188,34 @@ function Guide({ connector, onClose }: Props) {
- {isSocialConnector && ( -
-
-
1
-
{t('connectors.guide.general_setting')}
-
- -
- )} -
-
-
{isSocialConnector ? 2 : 1}
-
{t('connectors.guide.parameter_configuration')}
-
- -
- {!isSocialConnector && ( -
-
-
2
-
{t('connectors.guide.test_connection')}
-
- + {isSocialConnector && ( + + + + )} + + configParser(watch(), formItems)} + formItems={formItems} /> -
- )} + + {!isSocialConnector && ( + + configParser(watch(), formItems)} + /> + + )} +