mirror of
https://github.com/fosrl/pangolin.git
synced 2025-12-12 19:18:30 +00:00
fix external user select box
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
|||||||
SettingsSectionHeader,
|
SettingsSectionHeader,
|
||||||
SettingsSectionTitle
|
SettingsSectionTitle
|
||||||
} from "@app/components/Settings";
|
} from "@app/components/Settings";
|
||||||
import { StrategySelect } from "@app/components/StrategySelect";
|
import { StrategyOption, StrategySelect } from "@app/components/StrategySelect";
|
||||||
import HeaderTitle from "@app/components/SettingsSectionTitle";
|
import HeaderTitle from "@app/components/SettingsSectionTitle";
|
||||||
import { Button } from "@app/components/ui/button";
|
import { Button } from "@app/components/ui/button";
|
||||||
import { useParams, useRouter } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
@@ -45,15 +45,10 @@ import { createApiClient } from "@app/lib/api";
|
|||||||
import { Checkbox } from "@app/components/ui/checkbox";
|
import { Checkbox } from "@app/components/ui/checkbox";
|
||||||
import { ListIdpsResponse } from "@server/routers/idp";
|
import { ListIdpsResponse } from "@server/routers/idp";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
|
import { build } from "@server/build";
|
||||||
|
|
||||||
type UserType = "internal" | "oidc";
|
type UserType = "internal" | "oidc";
|
||||||
|
|
||||||
interface UserTypeOption {
|
|
||||||
id: UserType;
|
|
||||||
title: string;
|
|
||||||
description: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IdpOption {
|
interface IdpOption {
|
||||||
idpId: number;
|
idpId: number;
|
||||||
name: string;
|
name: string;
|
||||||
@@ -147,13 +142,20 @@ export default function Page() {
|
|||||||
}
|
}
|
||||||
}, [userType, env.email.emailEnabled, internalForm, externalForm]);
|
}, [userType, env.email.emailEnabled, internalForm, externalForm]);
|
||||||
|
|
||||||
const userTypes: UserTypeOption[] = [
|
const [userTypes, setUserTypes] = useState<StrategyOption<string>[]>([
|
||||||
{
|
{
|
||||||
id: "internal",
|
id: "internal",
|
||||||
title: t("userTypeInternal"),
|
title: t("userTypeInternal"),
|
||||||
description: t("userTypeInternalDescription")
|
description: t("userTypeInternalDescription"),
|
||||||
|
disabled: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "oidc",
|
||||||
|
title: t("userTypeExternal"),
|
||||||
|
description: t("userTypeExternalDescription"),
|
||||||
|
disabled: true
|
||||||
}
|
}
|
||||||
];
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!userType) {
|
if (!userType) {
|
||||||
@@ -177,9 +179,6 @@ export default function Page() {
|
|||||||
|
|
||||||
if (res?.status === 200) {
|
if (res?.status === 200) {
|
||||||
setRoles(res.data.data.roles);
|
setRoles(res.data.data.roles);
|
||||||
if (userType === "internal") {
|
|
||||||
setDataLoaded(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,24 +199,32 @@ export default function Page() {
|
|||||||
|
|
||||||
if (res?.status === 200) {
|
if (res?.status === 200) {
|
||||||
setIdps(res.data.data.idps);
|
setIdps(res.data.data.idps);
|
||||||
setDataLoaded(true);
|
|
||||||
|
|
||||||
if (res.data.data.idps.length) {
|
if (res.data.data.idps.length) {
|
||||||
userTypes.push({
|
setUserTypes((prev) =>
|
||||||
id: "oidc",
|
prev.map((type) => {
|
||||||
title: t("userTypeExternal"),
|
if (type.id === "oidc") {
|
||||||
description: t("userTypeExternalDescription")
|
return {
|
||||||
});
|
...type,
|
||||||
|
disabled: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchInitialData() {
|
||||||
setDataLoaded(false);
|
setDataLoaded(false);
|
||||||
fetchRoles();
|
await fetchRoles();
|
||||||
if (userType !== "internal") {
|
await fetchIdps();
|
||||||
fetchIdps();
|
setDataLoaded(true);
|
||||||
}
|
}
|
||||||
}, [userType]);
|
|
||||||
|
fetchInitialData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
async function onSubmitInternal(
|
async function onSubmitInternal(
|
||||||
values: z.infer<typeof internalFormSchema>
|
values: z.infer<typeof internalFormSchema>
|
||||||
@@ -323,7 +330,7 @@ export default function Page() {
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<SettingsContainer>
|
<SettingsContainer>
|
||||||
{!inviteLink && userTypes.length > 1 ? (
|
{!inviteLink && build !== "saas" ? (
|
||||||
<SettingsSection>
|
<SettingsSection>
|
||||||
<SettingsSectionHeader>
|
<SettingsSectionHeader>
|
||||||
<SettingsSectionTitle>
|
<SettingsSectionTitle>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { cn } from "@app/lib/cn";
|
|||||||
import { RadioGroup, RadioGroupItem } from "./ui/radio-group";
|
import { RadioGroup, RadioGroupItem } from "./ui/radio-group";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
interface StrategyOption<TValue extends string> {
|
export interface StrategyOption<TValue extends string> {
|
||||||
id: TValue;
|
id: TValue;
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user