mirror of
https://github.com/logto-io/logto.git
synced 2025-03-31 22:51:25 -05:00
fix(console): sms and email connector in use status (#1161)
This commit is contained in:
parent
4dbeb22fb6
commit
a868c1ff63
3 changed files with 22 additions and 22 deletions
|
@ -1,16 +1,28 @@
|
|||
import { SignInExperience } from '@logto/schemas';
|
||||
import { ConnectorType, SignInExperience, SignInMethodState } from '@logto/schemas';
|
||||
import useSWR from 'swr';
|
||||
|
||||
import { RequestError } from './use-api';
|
||||
|
||||
const useConnectorInUse = (connectorTarget?: string): boolean | undefined => {
|
||||
const { data } = useSWR<SignInExperience, RequestError>(connectorTarget && '/api/sign-in-exp');
|
||||
const useConnectorInUse = (type?: ConnectorType, target?: string): boolean | undefined => {
|
||||
const { data } = useSWR<SignInExperience, RequestError>(target && type && '/api/sign-in-exp');
|
||||
|
||||
if (!data || !connectorTarget) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
return data.socialSignInConnectorTargets.includes(connectorTarget);
|
||||
if (type === ConnectorType.Email) {
|
||||
return data.signInMethods.email !== SignInMethodState.Disabled;
|
||||
}
|
||||
|
||||
if (type === ConnectorType.SMS) {
|
||||
return data.signInMethods.sms !== SignInMethodState.Disabled;
|
||||
}
|
||||
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
|
||||
return data.socialSignInConnectorTargets.includes(target);
|
||||
};
|
||||
|
||||
export default useConnectorInUse;
|
||||
|
|
|
@ -43,7 +43,7 @@ const ConnectorDetails = () => {
|
|||
const { data, error } = useSWR<ConnectorDTO, RequestError>(
|
||||
connectorId && `/api/connectors/${connectorId}`
|
||||
);
|
||||
const inUse = useConnectorInUse(data?.type === ConnectorType.Social ? data.target : undefined);
|
||||
const inUse = useConnectorInUse(data?.type, data?.target);
|
||||
const isLoading = !data && !error;
|
||||
const api = useApi();
|
||||
const navigate = useNavigate();
|
||||
|
@ -130,20 +130,13 @@ const ConnectorDetails = () => {
|
|||
<div>
|
||||
<ConnectorTypeName type={data.type} />
|
||||
<div className={styles.verticalBar} />
|
||||
{data.type === ConnectorType.Social && inUse !== undefined && (
|
||||
{inUse !== undefined && (
|
||||
<Status status={inUse ? 'enabled' : 'disabled'} varient="outlined">
|
||||
{t('connectors.connector_status', {
|
||||
context: inUse ? 'in_use' : 'not_in_use',
|
||||
})}
|
||||
</Status>
|
||||
)}
|
||||
{data.type !== ConnectorType.Social && (
|
||||
<Status status={data.enabled ? 'enabled' : 'disabled'} varient="outlined">
|
||||
{t('connectors.connector_status', {
|
||||
context: data.enabled ? 'in_use' : 'not_in_use',
|
||||
})}
|
||||
</Status>
|
||||
)}
|
||||
<div className={styles.verticalBar} />
|
||||
<div className={styles.text}>ID</div>
|
||||
<CopyToClipboard value={data.id} />
|
||||
|
|
|
@ -19,9 +19,7 @@ type Props = {
|
|||
|
||||
const ConnectorRow = ({ type, connectors, onClickSetup }: Props) => {
|
||||
const { t } = useTranslation(undefined);
|
||||
const inUse = useConnectorInUse(
|
||||
conditional(type === ConnectorType.Social && connectors[0]?.target)
|
||||
);
|
||||
const inUse = useConnectorInUse(type, connectors[0]?.target);
|
||||
const navigate = useNavigate();
|
||||
const showSetupButton = type !== ConnectorType.Social && !connectors[0];
|
||||
|
||||
|
@ -40,17 +38,14 @@ const ConnectorRow = ({ type, connectors, onClickSetup }: Props) => {
|
|||
</td>
|
||||
<td>{t(connectorTitlePlaceHolder[type])}</td>
|
||||
<td>
|
||||
{type === ConnectorType.Social && inUse !== undefined && (
|
||||
{inUse !== undefined && (
|
||||
<Status status={inUse ? 'enabled' : 'disabled'}>
|
||||
{t('admin_console.connectors.connector_status', {
|
||||
context: inUse ? 'in_use' : 'not_in_use',
|
||||
})}
|
||||
</Status>
|
||||
)}
|
||||
{type !== ConnectorType.Social && connectors[0] && (
|
||||
<Status status="enabled">{t('admin_console.connectors.connector_status_in_use')}</Status>
|
||||
)}
|
||||
{type !== ConnectorType.Social && !connectors[0] && '-'}
|
||||
{inUse === undefined && !connectors[0] && '-'}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue