-
-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
302 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { type RouteObject } from 'react-router-dom'; | ||
|
||
import Mfa from '@/pages/Mfa'; | ||
|
||
export const mfa: RouteObject = { path: 'mfa', element: <Mfa /> }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
239 changes: 239 additions & 0 deletions
239
packages/console/src/pages/OrganizationDetails/Settings/JitSettings.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
import { RoleType, type SsoConnectorWithProviderConfig } from '@logto/schemas'; | ||
import { useCallback, useMemo, useState } from 'react'; | ||
import { Controller, type UseFormReturn } from 'react-hook-form'; | ||
import { Trans, useTranslation } from 'react-i18next'; | ||
import useSWRInfinite from 'swr/infinite'; | ||
|
||
import Minus from '@/assets/icons/minus.svg'; | ||
import Plus from '@/assets/icons/plus.svg'; | ||
import SsoIcon from '@/assets/icons/single-sign-on.svg'; | ||
import FormCard from '@/components/FormCard'; | ||
import MultiOptionInput from '@/components/MultiOptionInput'; | ||
import OrganizationRolesSelect from '@/components/OrganizationRolesSelect'; | ||
import { organizationJit } from '@/consts'; | ||
import ActionMenu from '@/ds-components/ActionMenu'; | ||
import { DropdownItem } from '@/ds-components/Dropdown'; | ||
import FormField from '@/ds-components/FormField'; | ||
import IconButton from '@/ds-components/IconButton'; | ||
import InlineNotification from '@/ds-components/InlineNotification'; | ||
import TextLink from '@/ds-components/TextLink'; | ||
import { enterpriseSso } from '@/hooks/use-console-routes/routes/enterprise-sso'; | ||
import useDocumentationUrl from '@/hooks/use-documentation-url'; | ||
import SsoConnectorLogo from '@/pages/EnterpriseSso/SsoConnectorLogo'; | ||
import { domainRegExp } from '@/pages/EnterpriseSsoDetails/Experience/DomainsInput/consts'; | ||
|
||
import * as styles from './index.module.scss'; | ||
import { type FormData } from './utils'; | ||
|
||
type Props = { | ||
readonly form: UseFormReturn<FormData>; | ||
}; | ||
|
||
function JitSettings({ form }: Props) { | ||
const { | ||
control, | ||
formState: { errors }, | ||
setError, | ||
clearErrors, | ||
watch, | ||
} = form; | ||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); | ||
const [emailDomains, ssoConnectorIds] = watch(['jitEmailDomains', 'jitSsoConnectorIds']); | ||
const [keyword, setKeyword] = useState(''); | ||
// Fetch all SSO connector to show if a domain is configured SSO | ||
const { data: ssoConnectorMatrix } = useSWRInfinite<SsoConnectorWithProviderConfig[]>( | ||
(index, previous) => { | ||
return previous && previous.length === 0 ? null : `api/sso-connectors?page=${index + 1}`; | ||
}, | ||
{ initialSize: Number.POSITIVE_INFINITY } | ||
); | ||
const allSsoConnectors = useMemo(() => ssoConnectorMatrix?.flat(), [ssoConnectorMatrix]); | ||
const hasSsoEnabled = useCallback( | ||
(domain: string) => allSsoConnectors?.some(({ domains }) => domains.includes(domain)), | ||
[allSsoConnectors] | ||
); | ||
/** If any of the email domains has SSO enabled. */ | ||
const hasSsoEnabledEmailDomain = useMemo( | ||
() => emailDomains.some((domain) => hasSsoEnabled(domain)), | ||
[emailDomains, hasSsoEnabled] | ||
); | ||
const { getDocumentationUrl } = useDocumentationUrl(); | ||
|
||
return ( | ||
<FormCard | ||
title="organization_details.jit.title" | ||
description="organization_details.jit.description" | ||
> | ||
<FormField | ||
title="organization_details.jit.enterprise_sso" | ||
description={ | ||
<Trans | ||
i18nKey="admin_console.organization_details.jit.enterprise_sso_description" | ||
components={{ | ||
a: ( | ||
<TextLink | ||
to={getDocumentationUrl(organizationJit.enterpriseSso)} | ||
targetBlank="noopener" | ||
/> | ||
), | ||
}} | ||
/> | ||
} | ||
descriptionPosition="top" | ||
> | ||
{ssoConnectorIds.length === 0 && ( | ||
<InlineNotification> | ||
<Trans | ||
i18nKey="admin_console.organization_details.jit.no_enterprise_connector_set" | ||
components={{ a: <TextLink to={'/' + enterpriseSso.path} /> }} | ||
/> | ||
</InlineNotification> | ||
)} | ||
{ssoConnectorIds.length > 0 && ( | ||
<Controller | ||
name="jitSsoConnectorIds" | ||
control={control} | ||
render={({ field: { onChange, value } }) => ( | ||
<div className={styles.ssoConnectorList}> | ||
{value.map((id) => { | ||
const connector = allSsoConnectors?.find( | ||
({ id: connectorId }) => id === connectorId | ||
); | ||
return ( | ||
connector && ( | ||
<div key={connector.id} className={styles.ssoConnector}> | ||
<div className={styles.info}> | ||
<SsoConnectorLogo className={styles.icon} data={connector} /> | ||
<span> | ||
{connector.connectorName} - {connector.providerName} | ||
</span> | ||
</div> | ||
<IconButton | ||
onClick={() => { | ||
onChange(value.filter((value) => value !== id)); | ||
}} | ||
> | ||
<Minus /> | ||
</IconButton> | ||
</div> | ||
) | ||
); | ||
})} | ||
<ActionMenu | ||
buttonProps={{ | ||
type: 'default', | ||
size: 'medium', | ||
title: 'organization_details.jit.add_enterprise_connector', | ||
icon: <Plus />, | ||
className: styles.addSsoConnectorButton, | ||
}} | ||
dropdownHorizontalAlign="start" | ||
> | ||
{allSsoConnectors | ||
?.filter(({ id }) => !value.includes(id)) | ||
.map((connector) => ( | ||
<DropdownItem | ||
key={connector.id} | ||
className={styles.dropdownItem} | ||
onClick={() => { | ||
onChange([...value, connector.id]); | ||
}} | ||
> | ||
<SsoConnectorLogo className={styles.icon} data={connector} /> | ||
<span>{connector.connectorName}</span> | ||
</DropdownItem> | ||
))} | ||
</ActionMenu> | ||
</div> | ||
)} | ||
/> | ||
)} | ||
</FormField> | ||
<FormField | ||
title="organization_details.jit.email_domain" | ||
description={ | ||
<Trans | ||
i18nKey="admin_console.organization_details.jit.email_domain_description" | ||
components={{ | ||
a: ( | ||
<TextLink | ||
to={getDocumentationUrl(organizationJit.emailDomain)} | ||
targetBlank="noopener" | ||
/> | ||
), | ||
}} | ||
/> | ||
} | ||
descriptionPosition="top" | ||
className={styles.jitEmailDomains} | ||
> | ||
<Controller | ||
name="jitEmailDomains" | ||
control={control} | ||
render={({ field: { onChange, value } }) => ( | ||
<MultiOptionInput | ||
values={value} | ||
valueClassName={(domain) => (hasSsoEnabled(domain) ? styles.ssoEnabled : undefined)} | ||
renderValue={(value) => | ||
hasSsoEnabled(value) ? ( | ||
<> | ||
<SsoIcon /> | ||
{value} | ||
</> | ||
) : ( | ||
value | ||
) | ||
} | ||
validateInput={(input) => { | ||
if (!domainRegExp.test(input)) { | ||
return t('organization_details.jit.invalid_domain'); | ||
} | ||
|
||
if (value.includes(input)) { | ||
return t('organization_details.jit.domain_already_added'); | ||
} | ||
|
||
return { value: input }; | ||
}} | ||
placeholder={t('organization_details.jit.email_domain_placeholder')} | ||
error={errors.jitEmailDomains?.message} | ||
onChange={onChange} | ||
onError={(error) => { | ||
setError('jitEmailDomains', { type: 'custom', message: error }); | ||
}} | ||
onClearError={() => { | ||
clearErrors('jitEmailDomains'); | ||
}} | ||
/> | ||
)} | ||
/> | ||
{hasSsoEnabledEmailDomain && ( | ||
<InlineNotification severity="alert" className={styles.warning}> | ||
{t('organization_details.jit.sso_enabled_domain_warning')} | ||
</InlineNotification> | ||
)} | ||
</FormField> | ||
<FormField | ||
title="organization_details.jit.organization_roles" | ||
description="organization_details.jit.organization_roles_description" | ||
descriptionPosition="top" | ||
> | ||
<Controller | ||
name="jitRoles" | ||
control={control} | ||
render={({ field: { onChange, value } }) => ( | ||
<OrganizationRolesSelect | ||
roleType={RoleType.User} | ||
keyword={keyword} | ||
setKeyword={setKeyword} | ||
value={value} | ||
onChange={onChange} | ||
/> | ||
)} | ||
/> | ||
</FormField> | ||
</FormCard> | ||
); | ||
} | ||
|
||
export default JitSettings; |
Oops, something went wrong.