11import { Show , createEffect , createMemo , useContext } from "solid-js" ;
22import { createSignal } from "solid-js" ;
3- import { Dialog , DialogOverlay , DialogPanel , DialogTitle , DisclosurePanel , DisclosureStateProperties , DisclosureButton , Disclosure } from "terracotta" ;
3+ import {
4+ Dialog ,
5+ DialogOverlay ,
6+ DialogPanel ,
7+ DialogTitle ,
8+ DisclosurePanel ,
9+ DisclosureStateProperties ,
10+ DisclosureButton ,
11+ Disclosure ,
12+ } from "terracotta" ;
413import { UserContext } from "../contexts/UserContext" ;
514import { DefaultError , fromI32ToUserRole } from "shared/types" ;
615import { UserRole , fromUserRoleToI32 , stringToUserRole } from "shared/types" ;
@@ -12,7 +21,6 @@ import { MultiSelect } from "./MultiSelect";
1221import { FaRegularCircleQuestion } from "solid-icons/fa" ;
1322import { Tooltip } from "shared/ui" ;
1423import { ApiRoutes , RouteScope } from "./Routes" ;
15- import { g } from "shiki/dist/types/wasm-dynamic.mjs" ;
1624
1725export interface InviteUserModalProps {
1826 editingUser : SlimUser | null ;
@@ -31,9 +39,9 @@ export const EditUserModal = (props: InviteUserModalProps) => {
3139 } ) ) ;
3240
3341 const getScopePresets = ( scopes : ( string | null ) [ ] ) => {
34- return Object . keys ( ApiRoutes ) . filter ( presetName => {
42+ return Object . keys ( ApiRoutes ) . filter ( ( presetName ) => {
3543 const presetRoutes = ApiRoutes [ presetName as RouteScope ] ;
36- return presetRoutes . every ( route => scopes . includes ( route ) ) ;
44+ return presetRoutes . every ( ( route ) => scopes . includes ( route ) ) ;
3745 } ) ;
3846 } ;
3947
@@ -42,10 +50,12 @@ export const EditUserModal = (props: InviteUserModalProps) => {
4250
4351 const matchedPresets = getScopePresets ( editingUserScopes ( ) ?? [ ] ) ;
4452
45- setScopes ( matchedPresets . map ( ( name ) => ( {
46- id : name ,
47- name,
48- } ) ) ) ;
53+ setScopes (
54+ matchedPresets . map ( ( name ) => ( {
55+ id : name ,
56+ name,
57+ } ) ) ,
58+ ) ;
4959 } ) ;
5060
5161 const currentUserRole = createMemo ( ( ) => {
@@ -60,10 +70,12 @@ export const EditUserModal = (props: InviteUserModalProps) => {
6070 } ) ?. role ;
6171 } ) ;
6272
63- const editingUserScopes = createMemo ( ( ) => {
64- return props . editingUser ?. user_orgs . find ( ( val ) => {
65- return val . organization_id === userContext . selectedOrg ( ) . id ;
66- } ) ?. scopes ;
73+ const editingUserScopes = createMemo ( ( ) : string [ ] => {
74+ return (
75+ ( props . editingUser ?. user_orgs . find ( ( val ) => {
76+ return val . organization_id === userContext . selectedOrg ( ) . id ;
77+ } ) ?. scopes as string [ ] ) ?? [ ]
78+ ) ;
6779 } ) ;
6880
6981 const inviteUser = ( ) => {
@@ -78,7 +90,12 @@ export const EditUserModal = (props: InviteUserModalProps) => {
7890 organization_id : userContext . selectedOrg ( ) . id ,
7991 user_id : props . editingUser ?. id ,
8092 role : fromUserRoleToI32 ( role ( ) ) ,
81- scopes : scopes ( ) . length > 0 ? scopes ( ) . map ( ( val ) => ApiRoutes [ val . name as RouteScope ] ) . flat ( ) : undefined ,
93+ scopes :
94+ scopes ( ) . length > 0
95+ ? scopes ( )
96+ . map ( ( val ) => ApiRoutes [ val . name as RouteScope ] )
97+ . flat ( )
98+ : undefined ,
8299 } ) ,
83100 } ) . then ( ( res ) => {
84101 createEffect ( ( ) => {
@@ -201,8 +218,9 @@ export const EditUserModal = (props: InviteUserModalProps) => {
201218 />
202219 </ div >
203220 < FaSolidChevronDown
204- class = { `${ isOpen ( ) ? "rotate-180 transform" : ""
205- } h-4 w-4`}
221+ class = { `${
222+ isOpen ( ) ? "rotate-180 transform" : ""
223+ } h-4 w-4`}
206224 title = { isOpen ( ) ? "Close" : "Open" }
207225 />
208226 </ >
@@ -239,7 +257,12 @@ export const EditUserModal = (props: InviteUserModalProps) => {
239257 </ button >
240258 < button
241259 disabled = {
242- role ( ) === fromI32ToUserRole ( editingUserRole ( ) ?? 0 ) && scopes ( ) . every ( scope => getScopePresets ( editingUserScopes ( ) ?? [ ] ) . includes ( scope . id ) )
260+ role ( ) === fromI32ToUserRole ( editingUserRole ( ) ?? 0 ) &&
261+ scopes ( ) . every ( ( scope ) =>
262+ getScopePresets ( editingUserScopes ( ) ?? [ ] ) . includes (
263+ scope . id ,
264+ ) ,
265+ )
243266 }
244267 type = "submit"
245268 class = "inline-flex justify-center rounded-md bg-magenta-500 px-3 py-2 font-semibold text-white shadow-sm hover:bg-magenta-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-magenta-600 disabled:bg-magenta-200"
0 commit comments