@@ -17,7 +17,8 @@ import {
1717 TextField ,
1818 TextInput ,
1919 required ,
20- useRecordContext
20+ useRecordContext ,
21+ useResourceContext
2122} from "react-admin" ;
2223import { useFormContext , useWatch } from "react-hook-form" ;
2324import CardActions from "@mui/material/CardActions" ;
@@ -49,7 +50,9 @@ export const AccountOrgAdminUserEdit = ({ user, region, ...props }) => (
4950 mutationMode = "pessimistic"
5051 filter = { { searchURI : "orgAdmin" } }
5152 >
52- < UserForm edit user = { user } region = { region } />
53+ < SimpleForm toolbar = { < CustomToolbar /> } redirect = "list" >
54+ < UserFormFields edit user = { user } region = { region } />
55+ </ SimpleForm >
5356 </ Edit >
5457) ;
5558
@@ -82,12 +85,14 @@ export const AccountOrgAdminUserList = props => (
8285
8386const CustomShowActions = ( ) => {
8487 const record = useRecordContext ( ) ;
88+ const resource = useResourceContext ( ) ;
8589 return record ? (
8690 < CardActions style = { { zIndex : 2 , display : "inline-block" , float : "right" } } >
8791 < EditButton label = "Edit User" />
8892 < EnableDisableButton
8993 disabled = { record . disabledInCognito }
9094 record = { record }
95+ resource = { resource }
9196 />
9297 </ CardActions >
9398 ) : null ;
@@ -115,18 +120,29 @@ export const AccountOrgAdminUserDetail = ({ user, ...props }) => (
115120 source = "accountIds"
116121 >
117122 < SingleFieldList >
118- < TitleChip source = "name" />
123+ < TitleChip />
119124 </ SingleFieldList >
120125 </ ReferenceArrayField >
121126 </ SimpleShowLayout >
122127 </ Show >
123128) ;
124129
125130const UserForm = ( { edit = false , region } ) => {
131+ return (
132+ < SimpleForm toolbar = { < CustomToolbar /> } redirect = "list" >
133+ < UserFormFields edit = { edit } region = { region } />
134+ </ SimpleForm >
135+ ) ;
136+ } ;
137+
138+ const UserFormFields = ( { edit = false , region } ) => {
126139 const [ nameSuffix , setNameSuffix ] = useState ( "" ) ;
127- const { control, setValue } = useFormContext ( ) ;
140+
141+ const formContext = useFormContext ( ) ;
142+
143+ const { control, setValue } = formContext ;
128144 const organisationId = useWatch ( { control, name : "organisationId" } ) ;
129- const ignored = useWatch ( { control, name : "ignored " } ) ;
145+ const username = useWatch ( { control, name : "username " } ) ;
130146
131147 const autoComplete = ApplicationContext . isDevEnv ( ) ? "on" : "off" ;
132148
@@ -139,13 +155,13 @@ const UserForm = ({ edit = false, region }) => {
139155 } , [ organisationId ] ) ;
140156
141157 useEffect ( ( ) => {
142- if ( ignored && nameSuffix ) {
143- setValue ( "username" , `${ ignored } @${ nameSuffix } ` ) ;
158+ if ( username && nameSuffix && setValue ) {
159+ setValue ( "username" , `${ username } @${ nameSuffix } ` ) ;
144160 }
145- } , [ ignored , nameSuffix , setValue ] ) ;
161+ } , [ username , nameSuffix , setValue ] ) ;
146162
147163 return (
148- < SimpleForm toolbar = { < CustomToolbar /> } redirect = "list" >
164+ < >
149165 < ReferenceArrayInput
150166 reference = "account"
151167 source = "accountIds"
@@ -158,19 +174,24 @@ const UserForm = ({ edit = false, region }) => {
158174 </ ReferenceArrayInput >
159175
160176 { edit ? (
161- < TextInput
162- disabled
163- source = "username"
164- label = "Login ID (admin username)"
165- />
177+ < >
178+ < TextInput
179+ disabled
180+ source = "username"
181+ label = "Login ID (admin username)"
182+ />
183+ { /* Hidden field to ensure username is included in payload */ }
184+ < TextInput source = "username" style = { { display : "none" } } />
185+ </ >
166186 ) : (
167187 < >
168188 < TextInput
169- source = "ignored "
189+ source = "username "
170190 validate = { isRequired }
171191 label = "Login ID (username)"
172192 />
173193 { nameSuffix && < span > @{ nameSuffix } </ span > }
194+ < TextInput source = "username" style = { { display : "none" } } />
174195 </ >
175196 ) }
176197
@@ -192,6 +213,6 @@ const UserForm = ({ edit = false, region }) => {
192213 validate = { getPhoneValidator ( region ) }
193214 autoComplete = { autoComplete }
194215 />
195- </ SimpleForm >
216+ </ >
196217 ) ;
197218} ;
0 commit comments