mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
fix(console): socialConnectors in preview data (#862)
* fix(console): socialConnectors in preview data * fix: cr
This commit is contained in:
parent
65fb36ce3f
commit
a2cd983d97
2 changed files with 34 additions and 13 deletions
|
@ -1,12 +1,14 @@
|
||||||
import { Language } from '@logto/phrases';
|
import { Language } from '@logto/phrases';
|
||||||
import { AppearanceMode, SignInExperience } from '@logto/schemas';
|
import { AppearanceMode, ConnectorDTO, ConnectorMetadata, SignInExperience } from '@logto/schemas';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import React, { useState } from 'react';
|
import React, { useMemo, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
|
||||||
import Card from '@/components/Card';
|
import Card from '@/components/Card';
|
||||||
import Select from '@/components/Select';
|
import Select from '@/components/Select';
|
||||||
import TabNav, { TabNavItem } from '@/components/TabNav';
|
import TabNav, { TabNavItem } from '@/components/TabNav';
|
||||||
|
import { RequestError } from '@/hooks/use-api';
|
||||||
|
|
||||||
import * as styles from './Preview.module.scss';
|
import * as styles from './Preview.module.scss';
|
||||||
|
|
||||||
|
@ -20,16 +22,37 @@ const Preview = ({ signInExperience, className }: Props) => {
|
||||||
const [language, setLanguage] = useState<Language>(Language.English);
|
const [language, setLanguage] = useState<Language>(Language.English);
|
||||||
const [mode, setMode] = useState<AppearanceMode>(AppearanceMode.LightMode);
|
const [mode, setMode] = useState<AppearanceMode>(AppearanceMode.LightMode);
|
||||||
const [platform, setPlatform] = useState<'web' | 'mobile'>('web');
|
const [platform, setPlatform] = useState<'web' | 'mobile'>('web');
|
||||||
|
const { data: allConnectors } = useSWR<ConnectorDTO[], RequestError>('/api/connectors');
|
||||||
|
|
||||||
// TODO: is a placeholder
|
const config = useMemo(() => {
|
||||||
const config = encodeURIComponent(
|
if (!allConnectors) {
|
||||||
JSON.stringify({
|
return '';
|
||||||
signInExperience,
|
}
|
||||||
language,
|
|
||||||
mode,
|
const socialConnectors = signInExperience.socialSignInConnectorTargets.reduce<
|
||||||
platform,
|
Array<ConnectorMetadata & { id: string }>
|
||||||
})
|
>(
|
||||||
);
|
(previous, connectorTarget) => [
|
||||||
|
...previous,
|
||||||
|
...allConnectors
|
||||||
|
.filter(({ metadata: { target } }) => target === connectorTarget)
|
||||||
|
.map(({ metadata, id }) => ({ ...metadata, id })),
|
||||||
|
],
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
return encodeURIComponent(
|
||||||
|
JSON.stringify({
|
||||||
|
signInExperience: {
|
||||||
|
...signInExperience,
|
||||||
|
socialConnectors,
|
||||||
|
},
|
||||||
|
language,
|
||||||
|
mode,
|
||||||
|
platform,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}, [allConnectors, language, mode, platform, signInExperience]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className={classNames(styles.preview, className)}>
|
<Card className={classNames(styles.preview, className)}>
|
||||||
|
|
|
@ -36,8 +36,6 @@ const usePreview = (): [boolean, PreviewConfig?] => {
|
||||||
fixedLanguage: language,
|
fixedLanguage: language,
|
||||||
autoDetect: false,
|
autoDetect: false,
|
||||||
},
|
},
|
||||||
// TODO: Remove this once preview returns connectors data
|
|
||||||
socialConnectors: [],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return { signInExperience: settings, language, mode, platform };
|
return { signInExperience: settings, language, mode, platform };
|
||||||
|
|
Loading…
Reference in a new issue