mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-11 23:04:59 +00:00
✨ replace user select in resource auth and alert rule field
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { RolesSelector } from "@app/components/roles-selector";
|
||||||
import SetResourceHeaderAuthForm from "@app/components/SetResourceHeaderAuthForm";
|
import SetResourceHeaderAuthForm from "@app/components/SetResourceHeaderAuthForm";
|
||||||
import SetResourcePincodeForm from "@app/components/SetResourcePincodeForm";
|
import SetResourcePincodeForm from "@app/components/SetResourcePincodeForm";
|
||||||
import {
|
import {
|
||||||
@@ -33,6 +34,7 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue
|
SelectValue
|
||||||
} from "@app/components/ui/select";
|
} from "@app/components/ui/select";
|
||||||
|
import { UsersSelector } from "@app/components/users-selector";
|
||||||
import type { ResourceContextType } from "@app/contexts/resourceContext";
|
import type { ResourceContextType } from "@app/contexts/resourceContext";
|
||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
import { useOrgContext } from "@app/hooks/useOrgContext";
|
import { useOrgContext } from "@app/hooks/useOrgContext";
|
||||||
@@ -497,46 +499,27 @@ export default function ResourceAuthenticationPage() {
|
|||||||
{t("roles")}
|
{t("roles")}
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<TagInput
|
<RolesSelector
|
||||||
{...field}
|
selectedRoles={
|
||||||
activeTagIndex={
|
field.value ??
|
||||||
activeRolesTagIndex
|
[]
|
||||||
}
|
}
|
||||||
setActiveTagIndex={
|
restrictAdminRole
|
||||||
setActiveRolesTagIndex
|
orgId={
|
||||||
|
org.org
|
||||||
|
.orgId
|
||||||
}
|
}
|
||||||
placeholder={t(
|
onSelectRoles={(
|
||||||
"accessRoleSelect2"
|
newUsers
|
||||||
)}
|
|
||||||
size="sm"
|
|
||||||
tags={
|
|
||||||
usersRolesForm.getValues()
|
|
||||||
.roles
|
|
||||||
}
|
|
||||||
setTags={(
|
|
||||||
newRoles
|
|
||||||
) => {
|
) => {
|
||||||
usersRolesForm.setValue(
|
usersRolesForm.setValue(
|
||||||
"roles",
|
"roles",
|
||||||
newRoles as [
|
newUsers as [
|
||||||
Tag,
|
Tag,
|
||||||
...Tag[]
|
...Tag[]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
enableAutocomplete={
|
|
||||||
true
|
|
||||||
}
|
|
||||||
autocompleteOptions={
|
|
||||||
allRoles
|
|
||||||
}
|
|
||||||
allowDuplicates={
|
|
||||||
false
|
|
||||||
}
|
|
||||||
restrictTagsToAutocompleteOptions={
|
|
||||||
true
|
|
||||||
}
|
|
||||||
sortTags={true}
|
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
@@ -557,23 +540,16 @@ export default function ResourceAuthenticationPage() {
|
|||||||
{t("users")}
|
{t("users")}
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<TagInput
|
<UsersSelector
|
||||||
{...field}
|
selectedUsers={
|
||||||
activeTagIndex={
|
field.value ??
|
||||||
activeUsersTagIndex
|
[]
|
||||||
}
|
}
|
||||||
setActiveTagIndex={
|
orgId={
|
||||||
setActiveUsersTagIndex
|
org.org
|
||||||
|
.orgId
|
||||||
}
|
}
|
||||||
placeholder={t(
|
onSelectUsers={(
|
||||||
"accessUserSelect"
|
|
||||||
)}
|
|
||||||
tags={
|
|
||||||
usersRolesForm.getValues()
|
|
||||||
.users
|
|
||||||
}
|
|
||||||
size="sm"
|
|
||||||
setTags={(
|
|
||||||
newUsers
|
newUsers
|
||||||
) => {
|
) => {
|
||||||
usersRolesForm.setValue(
|
usersRolesForm.setValue(
|
||||||
@@ -584,19 +560,6 @@ export default function ResourceAuthenticationPage() {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
enableAutocomplete={
|
|
||||||
true
|
|
||||||
}
|
|
||||||
autocompleteOptions={
|
|
||||||
allUsers
|
|
||||||
}
|
|
||||||
allowDuplicates={
|
|
||||||
false
|
|
||||||
}
|
|
||||||
restrictTagsToAutocompleteOptions={
|
|
||||||
true
|
|
||||||
}
|
|
||||||
sortTags={true}
|
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ import { useEffect, useMemo, useRef, useState } from "react";
|
|||||||
import type { Control, UseFormReturn } from "react-hook-form";
|
import type { Control, UseFormReturn } from "react-hook-form";
|
||||||
import { useFormContext, useWatch } from "react-hook-form";
|
import { useFormContext, useWatch } from "react-hook-form";
|
||||||
import { useDebounce } from "use-debounce";
|
import { useDebounce } from "use-debounce";
|
||||||
|
import { RolesSelector } from "../roles-selector";
|
||||||
|
import { UsersSelector } from "../users-selector";
|
||||||
|
|
||||||
export function AddActionPanel({
|
export function AddActionPanel({
|
||||||
onAdd
|
onAdd
|
||||||
@@ -593,29 +595,16 @@ function NotifyActionFields({
|
|||||||
<FormItem className="flex flex-col items-start">
|
<FormItem className="flex flex-col items-start">
|
||||||
<FormLabel>{t("alertingNotifyUsers")}</FormLabel>
|
<FormLabel>{t("alertingNotifyUsers")}</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<TagInput
|
<UsersSelector
|
||||||
{...field}
|
selectedUsers={field.value ?? []}
|
||||||
activeTagIndex={activeUsersTagIndex}
|
orgId={orgId}
|
||||||
setActiveTagIndex={setActiveUsersTagIndex}
|
onSelectUsers={(newUsers) => {
|
||||||
placeholder={t("alertingSelectUsers")}
|
|
||||||
size="sm"
|
|
||||||
tags={userTags}
|
|
||||||
setTags={(newTags) => {
|
|
||||||
const next =
|
|
||||||
typeof newTags === "function"
|
|
||||||
? newTags(userTags)
|
|
||||||
: newTags;
|
|
||||||
form.setValue(
|
form.setValue(
|
||||||
`actions.${index}.userTags`,
|
`actions.${index}.userTags`,
|
||||||
next as Tag[],
|
newUsers as [Tag, ...Tag[]],
|
||||||
{ shouldDirty: true }
|
{ shouldDirty: true }
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
enableAutocomplete={true}
|
|
||||||
autocompleteOptions={allUsers}
|
|
||||||
allowDuplicates={false}
|
|
||||||
restrictTagsToAutocompleteOptions={true}
|
|
||||||
sortTags={true}
|
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
@@ -629,29 +618,17 @@ function NotifyActionFields({
|
|||||||
<FormItem className="flex flex-col items-start">
|
<FormItem className="flex flex-col items-start">
|
||||||
<FormLabel>{t("alertingNotifyRoles")}</FormLabel>
|
<FormLabel>{t("alertingNotifyRoles")}</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<TagInput
|
<RolesSelector
|
||||||
{...field}
|
selectedRoles={field.value ?? []}
|
||||||
activeTagIndex={activeRolesTagIndex}
|
restrictAdminRole
|
||||||
setActiveTagIndex={setActiveRolesTagIndex}
|
orgId={orgId}
|
||||||
placeholder={t("alertingSelectRoles")}
|
onSelectRoles={(newUsers) => {
|
||||||
size="sm"
|
|
||||||
tags={roleTags}
|
|
||||||
setTags={(newTags) => {
|
|
||||||
const next =
|
|
||||||
typeof newTags === "function"
|
|
||||||
? newTags(roleTags)
|
|
||||||
: newTags;
|
|
||||||
form.setValue(
|
form.setValue(
|
||||||
`actions.${index}.roleTags`,
|
`actions.${index}.roleTags`,
|
||||||
next as Tag[],
|
newUsers as [Tag, ...Tag[]],
|
||||||
{ shouldDirty: true }
|
{ shouldDirty: true }
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
enableAutocomplete={true}
|
|
||||||
autocompleteOptions={allRoles}
|
|
||||||
allowDuplicates={false}
|
|
||||||
restrictTagsToAutocompleteOptions={true}
|
|
||||||
sortTags={true}
|
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|||||||
Reference in New Issue
Block a user