0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-23 20:33:16 -05:00

feat(console): add component UnnamedTrans (#401)

This commit is contained in:
Wang Sijie 2022-03-18 11:20:23 +08:00 committed by GitHub
parent 32b058467c
commit 4a73e22d2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 12 deletions

View file

@ -4,7 +4,7 @@ import { Link, To } from 'react-router-dom';
import * as styles from './index.module.scss'; import * as styles from './index.module.scss';
type Props = { type Props = {
title: string; title: ReactNode;
subtitle?: string; subtitle?: string;
icon?: ReactNode; icon?: ReactNode;
to?: To; to?: To;

View file

@ -0,0 +1,22 @@
import { Languages } from '@logto/phrases';
import React from 'react';
import { useTranslation } from 'react-i18next';
type Props = {
resource: Record<Languages, string>;
};
const UnnamedTrans = ({ resource }: Props) => {
const {
i18n: { languages },
} = useTranslation();
const matchedLanguage = languages.find((language) => resource[language]);
if (!matchedLanguage) {
return null;
}
return <span>{resource[matchedLanguage]}</span>;
};
export default UnnamedTrans;

View file

@ -15,6 +15,7 @@ import ImagePlaceholder from '@/components/ImagePlaceholder';
import Markdown from '@/components/Markdown'; import Markdown from '@/components/Markdown';
import Status from '@/components/Status'; import Status from '@/components/Status';
import TabNav, { TabNavLink } from '@/components/TabNav'; import TabNav, { TabNavLink } from '@/components/TabNav';
import UnnamedTrans from '@/components/UnnamedTrans';
import useApi, { RequestError } from '@/hooks/use-api'; import useApi, { RequestError } from '@/hooks/use-api';
import SenderTester from './components/SenderTester'; import SenderTester from './components/SenderTester';
@ -26,10 +27,7 @@ const ConnectorDetails = () => {
const [config, setConfig] = useState<string>(); const [config, setConfig] = useState<string>();
const [saveError, setSaveError] = useState<string>(); const [saveError, setSaveError] = useState<string>();
const [isSubmitLoading, setIsSubmitLoading] = useState(false); const [isSubmitLoading, setIsSubmitLoading] = useState(false);
const { const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
t,
i18n: { language },
} = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { data, error } = useSWR<ConnectorDTO, RequestError>( const { data, error } = useSWR<ConnectorDTO, RequestError>(
connectorId && `/api/connectors/${connectorId}` connectorId && `/api/connectors/${connectorId}`
); );
@ -85,7 +83,9 @@ const ConnectorDetails = () => {
)} )}
<div className={styles.metadata}> <div className={styles.metadata}>
<div> <div>
<div className={styles.name}>{data.metadata.name[language]}</div> <div className={styles.name}>
<UnnamedTrans resource={data.metadata.name} />
</div>
<div className={styles.id}>{data.id}</div> <div className={styles.id}>{data.id}</div>
</div> </div>
<div> <div>

View file

@ -1,10 +1,10 @@
import { ConnectorDTO } from '@logto/schemas'; import { ConnectorDTO } from '@logto/schemas';
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import ImagePlaceholder from '@/components/ImagePlaceholder'; import ImagePlaceholder from '@/components/ImagePlaceholder';
import ItemPreview from '@/components/ItemPreview'; import ItemPreview from '@/components/ItemPreview';
import UnnamedTrans from '@/components/UnnamedTrans';
import * as styles from './ConnectorName.module.scss'; import * as styles from './ConnectorName.module.scss';
@ -14,10 +14,6 @@ type Props = {
}; };
const ConnectorName = ({ connector, titlePlaceholder = '' }: Props) => { const ConnectorName = ({ connector, titlePlaceholder = '' }: Props) => {
const {
i18n: { language },
} = useTranslation();
if (!connector) { if (!connector) {
return <ItemPreview title={titlePlaceholder} icon={<ImagePlaceholder />} />; return <ItemPreview title={titlePlaceholder} icon={<ImagePlaceholder />} />;
} }
@ -25,7 +21,7 @@ const ConnectorName = ({ connector, titlePlaceholder = '' }: Props) => {
return ( return (
<Link to={`/connectors/${connector.id}`} className={styles.link}> <Link to={`/connectors/${connector.id}`} className={styles.link}>
<ItemPreview <ItemPreview
title={connector.metadata.name[language] ?? connector.metadata.name.en ?? '-'} title={<UnnamedTrans resource={connector.metadata.name} />}
subtitle={connector.id} subtitle={connector.id}
icon={ icon={
connector.metadata.logo.startsWith('http') ? ( connector.metadata.logo.startsWith('http') ? (