fix external user select box

This commit is contained in:
miloschwartz
2025-07-18 14:45:16 -07:00
parent b34c3db956
commit 7a59e3acf7
2 changed files with 33 additions and 26 deletions

View File

@@ -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<StrategyOption<string>[]>([
{
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;
})
);
}
}
}
async function fetchInitialData() {
setDataLoaded(false);
fetchRoles();
if (userType !== "internal") {
fetchIdps();
await fetchRoles();
await fetchIdps();
setDataLoaded(true);
}
}, [userType]);
fetchInitialData();
}, []);
async function onSubmitInternal(
values: z.infer<typeof internalFormSchema>
@@ -323,7 +330,7 @@ export default function Page() {
<div>
<SettingsContainer>
{!inviteLink && userTypes.length > 1 ? (
{!inviteLink && build !== "saas" ? (
<SettingsSection>
<SettingsSectionHeader>
<SettingsSectionTitle>

View File

@@ -4,7 +4,7 @@ import { cn } from "@app/lib/cn";
import { RadioGroup, RadioGroupItem } from "./ui/radio-group";
import { useState } from "react";
interface StrategyOption<TValue extends string> {
export interface StrategyOption<TValue extends string> {
id: TValue;
title: string;
description: string;