11import { useRef , useState } from "react" ;
2- import { Stack , TableRow , TableCell , TextField } from "@mui/material" ;
2+ import { TableRow , TableCell , TextField } from "@mui/material" ;
33import Image from "next/image" ;
44import { z } from "zod" ;
55
@@ -86,6 +86,10 @@ function Staff({
8686 setTimeout ( ( ) => focusRef . current ?. focus ( ) , 0 ) ;
8787 }
8888
89+ function onCancel ( ) {
90+ setRecord ( undefined ) ;
91+ }
92+
8993 const utils = trpc . useUtils ( ) ;
9094 const addRecord = trpc . user . createUser . useMutation ( {
9195 meta : { disableGlobalOnError : true } ,
@@ -105,6 +109,7 @@ function Staff({
105109 record,
106110 records : data ?. records ,
107111 onAddRecord,
112+ onCancel,
108113 onSubmit,
109114 columns : COLUMNS ,
110115 emptyElement : (
@@ -114,61 +119,37 @@ function Staff({
114119 < Button onClick = { onAddRecord } > Add User</ Button >
115120 </ >
116121 ) ,
117- renderFormRow : ( record , hasError ) => (
118- < TableRow >
119- < TableCell >
120- < TextField
121- inputRef = { focusRef }
122- label = "First Name"
123- value = { record . first_name }
124- onChange = { ( e ) =>
125- setRecord ( { ...record , first_name : e . target . value } )
126- }
127- error = { hasError ( [ "first_name" ] ) }
128- />
129- </ TableCell >
130- < TableCell >
131- < TextField
132- label = "Last Name"
133- value = { record . last_name }
134- onChange = { ( e ) =>
135- setRecord ( { ...record , last_name : e . target . value } )
136- }
137- error = { hasError ( [ "last_name" ] ) }
138- />
139- </ TableCell >
140- < TableCell >
141- < TextField
142- type = "email"
143- label = "Email"
144- value = { record . email }
145- onChange = { ( e ) => setRecord ( { ...record , email : e . target . value } ) }
146- error = { hasError ( [ "email" ] ) }
147- />
148- </ TableCell >
149- < TableCell >
150- < Dropdown
151- itemList = { [ ...ROLE_OPTIONS ] }
152- selectedOption = { record . role }
153- setSelectedOption = { ( role ) =>
154- setRecord ( { ...record , role : role as string } )
155- }
156- label = "Role"
157- />
158- </ TableCell >
159- < TableCell >
160- < Stack
161- direction = "row"
162- spacing = { 1 }
163- sx = { { justifyContent : "flex-end" } }
164- >
165- < Button type = "submit" > Save</ Button >
166- < Button variant = "secondary" onClick = { ( ) => setRecord ( undefined ) } >
167- Cancel
168- </ Button >
169- </ Stack >
170- </ TableCell >
171- </ TableRow >
122+ renderForm : ( record , hasError ) => (
123+ < >
124+ < TextField
125+ inputRef = { focusRef }
126+ label = "First Name"
127+ value = { record . first_name }
128+ onChange = { ( e ) => setRecord ( { ...record , first_name : e . target . value } ) }
129+ error = { hasError ( [ "first_name" ] ) }
130+ />
131+ < TextField
132+ label = "Last Name"
133+ value = { record . last_name }
134+ onChange = { ( e ) => setRecord ( { ...record , last_name : e . target . value } ) }
135+ error = { hasError ( [ "last_name" ] ) }
136+ />
137+ < TextField
138+ type = "email"
139+ label = "Email"
140+ value = { record . email }
141+ onChange = { ( e ) => setRecord ( { ...record , email : e . target . value } ) }
142+ error = { hasError ( [ "email" ] ) }
143+ />
144+ < Dropdown
145+ itemList = { [ ...ROLE_OPTIONS ] }
146+ selectedOption = { record . role }
147+ setSelectedOption = { ( role ) =>
148+ setRecord ( { ...record , role : role as string } )
149+ }
150+ label = "Role"
151+ />
152+ </ >
172153 ) ,
173154 renderRow : ( record , router ) => (
174155 < TableRow
0 commit comments