From eb3aa049ece2e022bb02180667b926d30769f4ca Mon Sep 17 00:00:00 2001 From: Parkreiner Date: Thu, 21 Sep 2023 22:03:45 +0000 Subject: [PATCH 1/4] fix: remove needless undefined checks --- .../SecurityPage/SingleSignOnSection.tsx | 122 ++++++++---------- 1 file changed, 57 insertions(+), 65 deletions(-) diff --git a/site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx b/site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx index 224ad1422c0d4..d28b8f7ab0f34 100644 --- a/site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx +++ b/site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx @@ -8,7 +8,6 @@ import Button from "@mui/material/Button"; import Typography from "@mui/material/Typography"; import { convertToOAUTH } from "api/api"; import { AuthMethods, LoginType, UserLoginType } from "api/typesGenerated"; -import Skeleton from "@mui/material/Skeleton"; import { Stack } from "components/Stack/Stack"; import { useMutation } from "@tanstack/react-query"; import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"; @@ -116,73 +115,66 @@ export const SingleSignOnSection = ({ description="Authenticate in Coder using one-click" > - {authMethods && userLoginType ? ( - userLoginType.login_type === "password" ? ( - <> - {authMethods.github.enabled && ( - - )} - {authMethods.oidc.enabled && ( - - )} - - ) : ( - + {authMethods.github.enabled && ( + + )} + {authMethods.oidc.enabled && ( + + )} + + ) : ( + theme.palette.background.paper, + borderRadius: 1, + border: (theme) => `1px solid ${theme.palette.divider}`, + padding: 2, + display: "flex", + gap: 2, + alignItems: "center", + fontSize: 14, + }} + > + theme.palette.background.paper, - borderRadius: 1, - border: (theme) => `1px solid ${theme.palette.divider}`, - padding: 2, - display: "flex", - gap: 2, - alignItems: "center", - fontSize: 14, + color: (theme) => theme.palette.success.light, + fontSize: 16, }} - > - theme.palette.success.light, - fontSize: 16, - }} - /> - - Authenticated with{" "} - - {userLoginType.login_type === "github" - ? "GitHub" - : getOIDCLabel(authMethods)} - - - - {userLoginType.login_type === "github" ? ( - - ) : ( - - )} - + /> + + Authenticated with{" "} + + {userLoginType.login_type === "github" + ? "GitHub" + : getOIDCLabel(authMethods)} + + + + {userLoginType.login_type === "github" ? ( + + ) : ( + + )} - ) - ) : ( - + )} From 1dc79523c9c89bb3b3be689c7778c15500d531ab Mon Sep 17 00:00:00 2001 From: Parkreiner Date: Thu, 21 Sep 2023 22:05:40 +0000 Subject: [PATCH 2/4] refactor: clean up button markup --- .../UserSettingsPage/SecurityPage/SingleSignOnSection.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx b/site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx index d28b8f7ab0f34..56b57166cb1d7 100644 --- a/site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx +++ b/site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx @@ -119,11 +119,11 @@ export const SingleSignOnSection = ({ <> {authMethods.github.enabled && ( @@ -131,9 +131,9 @@ export const SingleSignOnSection = ({ {authMethods.oidc.enabled && ( )} @@ -164,14 +169,14 @@ export const SingleSignOnSection = ({ {userLoginType.login_type === "github" ? "GitHub" - : getOIDCLabel(authMethods)} + : getOIDCLabel(authMethods.oidc)} {userLoginType.login_type === "github" ? ( ) : ( - + )} @@ -190,21 +195,23 @@ export const SingleSignOnSection = ({ ); }; -const OIDCIcon = ({ authMethods }: { authMethods: AuthMethods }) => { - return authMethods.oidc.iconUrl ? ( +const OIDCIcon = ({ oidcAuth }: { oidcAuth: OIDCAuthMethod }) => { + if (!oidcAuth.iconUrl) { + return ; + } + + return ( - ) : ( - ); }; -const getOIDCLabel = (authMethods: AuthMethods) => { - return authMethods.oidc.signInText || "OpenID Connect"; +const getOIDCLabel = (oidcAuth: OIDCAuthMethod) => { + return oidcAuth.signInText || "OpenID Connect"; }; const ConfirmLoginTypeChangeModal = ({ From 64c865ca1eafac921f8d6135bfcfc8d6e35abec5 Mon Sep 17 00:00:00 2001 From: Parkreiner Date: Thu, 21 Sep 2023 22:11:26 +0000 Subject: [PATCH 4/4] feat: add empty SSO state --- .../SecurityPage/SingleSignOnSection.tsx | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx b/site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx index 957a422c6dbcd..4b0cecc6ffdc6 100644 --- a/site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx +++ b/site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx @@ -18,6 +18,10 @@ import { useMutation } from "@tanstack/react-query"; import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"; import { getErrorMessage } from "api/errors"; import CheckCircleOutlined from "@mui/icons-material/CheckCircleOutlined"; +import { EmptyState } from "components/EmptyState/EmptyState"; +import { makeStyles } from "@mui/styles"; +import Link from "@mui/material/Link"; +import { docs } from "utils/docs"; type LoginTypeConfirmation = | { @@ -97,6 +101,32 @@ export const useSingleSignOnSection = () => { }; }; +const useEmptyStateStyles = makeStyles((theme) => ({ + root: { + minHeight: 0, + padding: theme.spacing(6, 4), + backgroundColor: theme.palette.background.paper, + borderRadius: theme.shape.borderRadius, + }, +})); + +function SSOEmptyState() { + const styles = useEmptyStateStyles(); + + return ( + + Learn how to add a provider + + } + /> + ); +} + type SingleSignOnSectionProps = ReturnType & { authMethods: AuthMethods; userLoginType: UserLoginType; @@ -112,6 +142,12 @@ export const SingleSignOnSection = ({ isConfirming, error, }: SingleSignOnSectionProps) => { + const authList = Object.values( + authMethods, + ) as (typeof authMethods)[keyof typeof authMethods][]; + + const noSsoEnabled = !authList.some((method) => method.enabled); + return ( <>
)} + {authMethods.oidc.enabled && (