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

View File

@ -1,5 +1,5 @@
import { LockTwoTone } from '@ant-design/icons'; 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 { ColumnsType } from 'antd/lib/table';
import deleteDomain from 'api/SAML/deleteDomain'; import deleteDomain from 'api/SAML/deleteDomain';
import listAllDomain from 'api/SAML/listAllDomain'; import listAllDomain from 'api/SAML/listAllDomain';
@ -20,7 +20,6 @@ import AddDomain from './AddDomain';
import Create from './Create'; import Create from './Create';
import EditSaml from './Edit'; import EditSaml from './Edit';
import SwitchComponent from './Switch'; import SwitchComponent from './Switch';
import { getIsValidCertificate } from './utils';
function AuthDomains(): JSX.Element { function AuthDomains(): JSX.Element {
const { t } = useTranslation(['common', 'organizationsettings']); 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 ( return (
<Button type="link" onClick={onEditHandler(record)}> <Button type="link" onClick={onEditHandler(record)}>
Edit SSO Edit SSO

View File

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

View File

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