mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-27 15:26:41 +00:00
♻️correctly init the form
This commit is contained in:
@@ -232,8 +232,91 @@ export default function ResourceAuthenticationPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!pageLoading || hasInitializedRef.current) return;
|
if (!pageLoading || hasInitializedRef.current) return;
|
||||||
|
|
||||||
usersRolesForm.setValue("roles", allRoles);
|
/**
|
||||||
usersRolesForm.setValue("users", allUsers);
|
|
||||||
|
|
||||||
|
setAllUsers(
|
||||||
|
usersResponse.data.data.users.map((user) => ({
|
||||||
|
id: user.id.toString(),
|
||||||
|
text: `${user.email || user.username}${user.type !== UserType.Internal ? ` (${user.idpName})` : ""}`
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
whitelistForm.setValue(
|
||||||
|
"emails",
|
||||||
|
whitelist.data.data.whitelist.map((w) => ({
|
||||||
|
id: w.email,
|
||||||
|
text: w.email
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (build === "saas") {
|
||||||
|
if (subscription?.subscribed) {
|
||||||
|
setAllIdps(
|
||||||
|
idpsResponse.data.data.idps.map((idp) => ({
|
||||||
|
id: idp.idpId,
|
||||||
|
text: idp.name
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setAllIdps(
|
||||||
|
idpsResponse.data.data.idps.map((idp) => ({
|
||||||
|
id: idp.idpId,
|
||||||
|
text: idp.name
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
autoLoginEnabled &&
|
||||||
|
!selectedIdpId &&
|
||||||
|
idpsResponse.data.data.idps.length > 0
|
||||||
|
) {
|
||||||
|
setSelectedIdpId(idpsResponse.data.data.idps[0].idpId);
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
usersRolesForm.setValue(
|
||||||
|
"roles",
|
||||||
|
resourceRolesResponse.data.data.roles
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.roleId.toString(),
|
||||||
|
text: i.name
|
||||||
|
}))
|
||||||
|
.filter((role) => role.text !== "Admin")
|
||||||
|
);
|
||||||
|
|
||||||
|
usersRolesForm.setValue(
|
||||||
|
"users",
|
||||||
|
resourceUsersResponse.data.data.users.map((i) => ({
|
||||||
|
id: i.userId.toString(),
|
||||||
|
text: `${i.email || i.username}${i.type !== UserType.Internal ? ` (${i.idpName})` : ""}`
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
|
usersRolesForm.setValue(
|
||||||
|
"roles",
|
||||||
|
resourceRoles
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.roleId.toString(),
|
||||||
|
text: i.name
|
||||||
|
}))
|
||||||
|
.filter((role) => role.text !== "Admin")
|
||||||
|
);
|
||||||
|
usersRolesForm.setValue(
|
||||||
|
"users",
|
||||||
|
resourceUsers.map((i) => ({
|
||||||
|
id: i.userId.toString(),
|
||||||
|
text: `${i.email || i.username}${i.type !== UserType.Internal ? ` (${i.idpName})` : ""}`
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
whitelistForm.setValue(
|
whitelistForm.setValue(
|
||||||
"emails",
|
"emails",
|
||||||
whitelist.map((w) => ({
|
whitelist.map((w) => ({
|
||||||
@@ -247,8 +330,8 @@ export default function ResourceAuthenticationPage() {
|
|||||||
hasInitializedRef.current = true;
|
hasInitializedRef.current = true;
|
||||||
}, [
|
}, [
|
||||||
pageLoading,
|
pageLoading,
|
||||||
allRoles,
|
resourceRoles,
|
||||||
allUsers,
|
resourceUsers,
|
||||||
whitelist,
|
whitelist,
|
||||||
autoLoginEnabled,
|
autoLoginEnabled,
|
||||||
selectedIdpId,
|
selectedIdpId,
|
||||||
|
|||||||
Reference in New Issue
Block a user