fix: if invalid switch is disabled (#1656)

Co-authored-by: Ankit Nayan <ankit@signoz.io>
This commit is contained in:
Palash Gupta 2022-11-24 00:08:56 +05:30 committed by GitHub
parent 00863e54de
commit 4727dbc9f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 21 deletions

View File

@ -25,7 +25,7 @@ function SwitchComponent({
setIsLoading(false);
};
const isInValidCertificate = useMemo(
const isInValidVerificate = useMemo(
() => !getIsValidCertificate(record?.samlConfig),
[record],
);
@ -33,7 +33,7 @@ function SwitchComponent({
return (
<Switch
loading={isLoading}
disabled={isInValidCertificate}
disabled={isInValidVerificate}
checked={isChecked}
onChange={onChangeHandler}
/>

View File

@ -1,5 +1,5 @@
import { LockTwoTone } from '@ant-design/icons';
import { Button, Modal, notification, Space, Table, Typography } from 'antd';
import { Button, Modal, notification, Space, Table } from 'antd';
import { ColumnsType } from 'antd/lib/table';
import deleteDomain from 'api/SAML/deleteDomain';
import listAllDomain from 'api/SAML/listAllDomain';
@ -20,7 +20,6 @@ import AddDomain from './AddDomain';
import Create from './Create';
import EditSaml from './Edit';
import SwitchComponent from './Switch';
import { getIsValidCertificate } from './utils';
function AuthDomains(): JSX.Element {
const { t } = useTranslation(['common', 'organizationsettings']);
@ -196,12 +195,6 @@ function AuthDomains(): JSX.Element {
);
}
const isValidCertificate = getIsValidCertificate(record.samlConfig);
if (!isValidCertificate) {
return <Typography>Configure SSO &nbsp;</Typography>;
}
return (
<Button type="link" onClick={onEditHandler(record)}>
Edit SSO

View File

@ -1,6 +1,13 @@
export const getIsValidCertificate = (
config: Record<string, string>,
): boolean =>
config?.samlCert.length !== 0 &&
config?.samlEntity.length !== 0 &&
config?.samlIdp.length !== 0;
import { SAMLConfig } from 'types/api/SAML/listDomain';
export const getIsValidCertificate = (config: SAMLConfig): boolean => {
if (config === null) {
return false;
}
return (
config?.samlCert?.length !== 0 &&
config?.samlEntity?.length !== 0 &&
config?.samlIdp?.length !== 0
);
};

View File

@ -1,16 +1,18 @@
import { Organization } from '../user/getOrganization';
export interface SAMLConfig {
samlEntity: string;
samlIdp: string;
samlCert: string;
}
export interface SAMLDomain {
id: string;
name: string;
orgId: Organization['id'];
ssoEnabled: boolean;
ssoType: 'SAML';
samlConfig: {
samlEntity: string;
samlIdp: string;
samlCert: string;
};
samlConfig: SAMLConfig;
}
export interface Props {