0
Fork 0
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:
Wang Sijie 2022-05-19 14:05:43 +08:00 committed by GitHub
parent 65fb36ce3f
commit a2cd983d97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 13 deletions

View file

@ -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)}>

View file

@ -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 };