Skip to content

Commit 66152e4

Browse files
committed
fix: show paywall and correctly display auto create groups
1 parent e086d78 commit 66152e4

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

site/src/pages/ManagementSettingsPage/IdpSyncPage/IdpSyncPage.tsx

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import LaunchOutlined from "@mui/icons-material/LaunchOutlined";
22
import Button from "@mui/material/Button";
3+
import { getErrorMessage } from "api/errors";
34
import { groupsByOrganization } from "api/queries/groups";
45
import {
56
groupIdpSyncSettings,
67
roleIdpSyncSettings,
78
} from "api/queries/organizations";
8-
import { ErrorAlert } from "components/Alert/ErrorAlert";
99
import { EmptyState } from "components/EmptyState/EmptyState";
1010
import { FeatureStageBadge } from "components/FeatureStageBadge/FeatureStageBadge";
11+
import { displayError } from "components/GlobalSnackbar/utils";
1112
import { Loader } from "components/Loader/Loader";
1213
import { SettingsHeader } from "components/SettingsHeader/SettingsHeader";
1314
import { Stack } from "components/Stack/Stack";
14-
import type { FC } from "react";
15+
import { useFeatureVisibility } from "modules/dashboard/useFeatureVisibility";
16+
import { type FC, useEffect } from "react";
1517
import { Helmet } from "react-helmet-async";
1618
import { useQueries } from "react-query";
1719
import { useParams } from "react-router-dom";
@@ -25,6 +27,8 @@ export const IdpSyncPage: FC = () => {
2527
const { organization: organizationName } = useParams() as {
2628
organization: string;
2729
};
30+
// IdP sync does not have its own entitlement and is based on templace_rbac
31+
const { template_rbac: isIdpSyncEnabled } = useFeatureVisibility();
2832
const { organizations } = useOrganizationSettings();
2933
const organization = organizations?.find((o) => o.name === organizationName);
3034

@@ -37,6 +41,36 @@ export const IdpSyncPage: FC = () => {
3741
],
3842
});
3943

44+
useEffect(() => {
45+
if (groupIdpSyncSettingsQuery.error) {
46+
displayError(
47+
getErrorMessage(
48+
groupIdpSyncSettingsQuery.error,
49+
"Unable to load group IdP sync settings.",
50+
),
51+
);
52+
}
53+
}, [groupIdpSyncSettingsQuery.error]);
54+
55+
useEffect(() => {
56+
if (roleIdpSyncSettingsQuery.error) {
57+
displayError(
58+
getErrorMessage(
59+
roleIdpSyncSettingsQuery.error,
60+
"Unable to load role IdP sync settings.",
61+
),
62+
);
63+
}
64+
}, [roleIdpSyncSettingsQuery.error]);
65+
66+
useEffect(() => {
67+
if (groupsQuery.error) {
68+
displayError(
69+
getErrorMessage(groupsQuery.error, "Unable to load groups."),
70+
);
71+
}
72+
}, [groupsQuery.error]);
73+
4074
if (!organization) {
4175
return <EmptyState message="Organization not found" />;
4276
}
@@ -49,19 +83,6 @@ export const IdpSyncPage: FC = () => {
4983
return <Loader />;
5084
}
5185

52-
const error =
53-
groupIdpSyncSettingsQuery.error ||
54-
roleIdpSyncSettingsQuery.error ||
55-
groupsQuery.error;
56-
if (
57-
error ||
58-
!groupIdpSyncSettingsQuery.data ||
59-
!roleIdpSyncSettingsQuery.data ||
60-
!groupsQuery.data
61-
) {
62-
return <ErrorAlert error={error} />;
63-
}
64-
6586
const groupsMap = new Map<string, string>();
6687
if (groupsQuery.data) {
6788
for (const group of groupsQuery.data) {
@@ -104,6 +125,7 @@ export const IdpSyncPage: FC = () => {
104125
groups={groupsQuery.data}
105126
groupsMap={groupsMap}
106127
organization={organization}
128+
isIdpSyncEnabled={isIdpSyncEnabled}
107129
/>
108130
</>
109131
);

site/src/pages/ManagementSettingsPage/IdpSyncPage/IdpSyncPageView.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ interface IdpSyncPageViewProps {
3737
groups: Group[] | undefined;
3838
groupsMap: Map<string, string>;
3939
organization: Organization;
40+
isIdpSyncEnabled: boolean;
4041
}
4142

4243
export const IdpSyncPageView: FC<IdpSyncPageViewProps> = ({
4344
groupSyncSettings,
4445
roleSyncSettings,
4546
groupsMap,
4647
organization,
48+
isIdpSyncEnabled,
4749
}) => {
4850
const [searchParams] = useSearchParams();
4951

@@ -63,7 +65,7 @@ export const IdpSyncPageView: FC<IdpSyncPageViewProps> = ({
6365
return (
6466
<>
6567
<ChooseOne>
66-
<Cond condition={false}>
68+
<Cond condition={!isIdpSyncEnabled}>
6769
<Paywall
6870
message="IdP Sync"
6971
description="Configure group and role mappings to manage permissions outside of Coder. You need an Premium license to use this feature."
@@ -101,9 +103,13 @@ export const IdpSyncPageView: FC<IdpSyncPageViewProps> = ({
101103
/>
102104
<IdpField
103105
name={"Auto Create"}
104-
fieldText={String(
105-
groupSyncSettings?.auto_create_missing_groups || "n/a",
106-
)}
106+
fieldText={
107+
groupSyncSettings?.field
108+
? String(
109+
groupSyncSettings?.auto_create_missing_groups,
110+
)
111+
: "n/a"
112+
}
107113
/>
108114
</Stack>
109115
</div>

0 commit comments

Comments
 (0)