From 7a59e3acf7fdb35d195e9ce414faddb2e5149076 Mon Sep 17 00:00:00 2001 From: miloschwartz Date: Fri, 18 Jul 2025 14:45:16 -0700 Subject: [PATCH] fix external user select box --- .../settings/access/users/create/page.tsx | 57 +++++++++++-------- src/components/StrategySelect.tsx | 2 +- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/app/[orgId]/settings/access/users/create/page.tsx b/src/app/[orgId]/settings/access/users/create/page.tsx index a91fd7b9..2158701d 100644 --- a/src/app/[orgId]/settings/access/users/create/page.tsx +++ b/src/app/[orgId]/settings/access/users/create/page.tsx @@ -9,7 +9,7 @@ import { SettingsSectionHeader, SettingsSectionTitle } from "@app/components/Settings"; -import { StrategySelect } from "@app/components/StrategySelect"; +import { StrategyOption, StrategySelect } from "@app/components/StrategySelect"; import HeaderTitle from "@app/components/SettingsSectionTitle"; import { Button } from "@app/components/ui/button"; import { useParams, useRouter } from "next/navigation"; @@ -45,15 +45,10 @@ import { createApiClient } from "@app/lib/api"; import { Checkbox } from "@app/components/ui/checkbox"; import { ListIdpsResponse } from "@server/routers/idp"; import { useTranslations } from "next-intl"; +import { build } from "@server/build"; type UserType = "internal" | "oidc"; -interface UserTypeOption { - id: UserType; - title: string; - description: string; -} - interface IdpOption { idpId: number; name: string; @@ -147,13 +142,20 @@ export default function Page() { } }, [userType, env.email.emailEnabled, internalForm, externalForm]); - const userTypes: UserTypeOption[] = [ + const [userTypes, setUserTypes] = useState[]>([ { id: "internal", title: t("userTypeInternal"), - description: t("userTypeInternalDescription") + description: t("userTypeInternalDescription"), + disabled: false + }, + { + id: "oidc", + title: t("userTypeExternal"), + description: t("userTypeExternalDescription"), + disabled: true } - ]; + ]); useEffect(() => { if (!userType) { @@ -177,9 +179,6 @@ export default function Page() { if (res?.status === 200) { setRoles(res.data.data.roles); - if (userType === "internal") { - setDataLoaded(true); - } } } @@ -200,24 +199,32 @@ export default function Page() { if (res?.status === 200) { setIdps(res.data.data.idps); - setDataLoaded(true); if (res.data.data.idps.length) { - userTypes.push({ - id: "oidc", - title: t("userTypeExternal"), - description: t("userTypeExternalDescription") - }); + setUserTypes((prev) => + prev.map((type) => { + if (type.id === "oidc") { + return { + ...type, + disabled: false + }; + } + return type; + }) + ); } } } - setDataLoaded(false); - fetchRoles(); - if (userType !== "internal") { - fetchIdps(); + async function fetchInitialData() { + setDataLoaded(false); + await fetchRoles(); + await fetchIdps(); + setDataLoaded(true); } - }, [userType]); + + fetchInitialData(); + }, []); async function onSubmitInternal( values: z.infer @@ -323,7 +330,7 @@ export default function Page() {
- {!inviteLink && userTypes.length > 1 ? ( + {!inviteLink && build !== "saas" ? ( diff --git a/src/components/StrategySelect.tsx b/src/components/StrategySelect.tsx index f6a899f8..b431b96c 100644 --- a/src/components/StrategySelect.tsx +++ b/src/components/StrategySelect.tsx @@ -4,7 +4,7 @@ import { cn } from "@app/lib/cn"; import { RadioGroup, RadioGroupItem } from "./ui/radio-group"; import { useState } from "react"; -interface StrategyOption { +export interface StrategyOption { id: TValue; title: string; description: string;