11import { useState } from 'react' ;
22
33import { snakeToCamelCase } from '@douglasneuroinformatics/libjs' ;
4- import { Button , ClientTable , Form , Heading , SearchBar , Sheet } from '@douglasneuroinformatics/libui/components' ;
4+ import { Button , ClientTable , Heading , SearchBar , Sheet } from '@douglasneuroinformatics/libui/components' ;
55import { useTranslation } from '@douglasneuroinformatics/libui/hooks' ;
6- import { $UpdateUserData , type User } from '@opendatacapture/schemas/user' ;
6+ import type { User } from '@opendatacapture/schemas/user' ;
77import { Link } from 'react-router-dom' ;
88
99import { PageHeader } from '@/components/PageHeader' ;
@@ -13,6 +13,7 @@ import { useAppStore } from '@/store';
1313import { useDeleteUserMutation } from '../hooks/useDeleteUserMutation' ;
1414import { useUpdateUserMutation } from '../hooks/useUpdateUserMutation' ;
1515import { useUsersQuery } from '../hooks/useUsersQuery' ;
16+ import { UpdateUserForm } from './UpdateUserForm' ;
1617
1718export const ManageUsersPage = ( ) => {
1819 const currentUser = useAppStore ( ( store ) => store . currentUser ) ;
@@ -89,127 +90,19 @@ export const ManageUsersPage = () => {
8990 </ Sheet . Description >
9091 </ Sheet . Header >
9192 < Sheet . Body className = "grid gap-4" >
92- < Form
93- additionalButtons = { {
94- left : (
95- < Button
96- className = "w-full"
97- disabled = { currentUserIsSelected }
98- type = "button"
99- variant = "danger"
100- onClick = { ( ) => {
101- deleteUserMutation . mutate ( { id : selectedUser ! . id } ) ;
102- setSelectedUser ( null ) ;
103- } }
104- >
105- { t ( 'core.delete' ) }
106- </ Button >
107- )
108- } }
109- content = { [
110- {
111- description : t ( {
112- en : 'IMPORTANT: These permissions are not specific to any group. To manage granular permissions, please use the API.' ,
113- fr : "IMPORTANT : Ces autorisations ne sont pas spécifiques à un groupe. Pour gérer des autorisations granulaires, veuillez utiliser l'API."
114- } ) ,
115- fields : {
116- additionalPermissions : {
117- fieldset : {
118- action : {
119- kind : 'string' ,
120- label : t ( {
121- en : 'Action' ,
122- fr : 'Action'
123- } ) ,
124- options : {
125- create : t ( {
126- en : 'Create' ,
127- fr : 'Créer'
128- } ) ,
129- delete : t ( {
130- en : 'Delete' ,
131- fr : 'Effacer'
132- } ) ,
133- manage : t ( {
134- en : 'Manage (All)' ,
135- fr : 'Gérer (Tout)'
136- } ) ,
137- read : t ( {
138- en : 'Read' ,
139- fr : 'Lire'
140- } ) ,
141- update : t ( {
142- en : 'Update' ,
143- fr : 'Mettre à jour'
144- } )
145- } ,
146- variant : 'select'
147- } ,
148- subject : {
149- kind : 'string' ,
150- label : t ( {
151- en : 'Resource' ,
152- fr : 'Resource'
153- } ) ,
154- options : {
155- all : t ( {
156- en : 'All' ,
157- fr : 'Tous'
158- } ) ,
159- Assignment : t ( {
160- en : 'Assignment' ,
161- fr : 'Devoir'
162- } ) ,
163- Group : t ( {
164- en : 'Group' ,
165- fr : 'Groupe'
166- } ) ,
167- Instrument : t ( {
168- en : 'Instrument' ,
169- fr : 'Instrument'
170- } ) ,
171- InstrumentRecord : t ( {
172- en : 'Instrument Record' ,
173- fr : "Enregistrement de l'instrument"
174- } ) ,
175- Session : t ( {
176- en : 'Session' ,
177- fr : 'Session'
178- } ) ,
179- Subject : t ( {
180- en : 'Subject' ,
181- fr : 'Client'
182- } ) ,
183- User : t ( {
184- en : 'User' ,
185- fr : 'Utilisateur'
186- } )
187- } ,
188- variant : 'select'
189- }
190- } ,
191- kind : 'record-array' ,
192- label : t ( {
193- en : 'Permission' ,
194- fr : 'Autorisations supplémentaires'
195- } )
196- }
197- } ,
198- title : t ( {
199- en : 'Authorization' ,
200- fr : 'Autorisation'
201- } )
202- }
203- ] }
93+ < UpdateUserForm
94+ disableDelete = { currentUserIsSelected }
20495 initialValues = {
20596 selectedUser ?. additionalPermissions . length
20697 ? {
20798 additionalPermissions : selectedUser . additionalPermissions
20899 }
209100 : undefined
210101 }
211- submitBtnLabel = { t ( 'core.save' ) }
212- validationSchema = { $UpdateUserData . pick ( { additionalPermissions : true } ) . required ( ) }
102+ onDelete = { ( ) => {
103+ deleteUserMutation . mutate ( { id : selectedUser ! . id } ) ;
104+ setSelectedUser ( null ) ;
105+ } }
213106 onSubmit = { ( data ) => {
214107 void updateUserMutation . mutateAsync ( { data, id : selectedUser ! . id } ) . then ( ( ) => {
215108 setSelectedUser ( null ) ;
0 commit comments