@@ -129,16 +129,23 @@ const YesNoField: React.FC<YesNoFieldProps> = ({
129129
130130interface NewRoomRequestProps {
131131 createRoomRequest : ( payload : RoomRequestFormValues ) => Promise < RoomRequestPostResponse > ;
132+ initialValues ?: RoomRequestFormValues ;
133+ disabled ?: boolean ;
132134}
133135
134- const NewRoomRequest : React . FC < NewRoomRequestProps > = ( { createRoomRequest } ) => {
136+ const NewRoomRequest : React . FC < NewRoomRequestProps > = ( {
137+ createRoomRequest,
138+ initialValues,
139+ disabled,
140+ } ) => {
135141 const [ active , setActive ] = useState ( 0 ) ;
136142 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
137143 const numSteps = 4 ;
138144 const navigate = useNavigate ( ) ;
139145
140146 const form = useForm < RoomRequestFormValues > ( {
141- initialValues : {
147+ enhanceGetInputProps : ( ) => ( { disabled } ) ,
148+ initialValues : initialValues || {
142149 host : '' ,
143150 title : '' ,
144151 theme : '' ,
@@ -160,6 +167,9 @@ const NewRoomRequest: React.FC<NewRoomRequestProps> = ({ createRoomRequest }) =>
160167 } ,
161168
162169 validate : ( values ) => {
170+ if ( disabled ) {
171+ return { } ;
172+ }
163173 if ( active === 0 ) {
164174 return {
165175 host : OrganizationList . includes ( values . host ) ? null : 'Invalid organization selected.' ,
@@ -264,6 +274,9 @@ const NewRoomRequest: React.FC<NewRoomRequestProps> = ({ createRoomRequest }) =>
264274 } , [ form . values . locationType ] ) ;
265275
266276 const handleSubmit = async ( ) => {
277+ if ( disabled ) {
278+ return ;
279+ }
267280 const apiFormValues = { ...form . values } ;
268281 Object . keys ( apiFormValues ) . forEach ( ( key ) => {
269282 const value = apiFormValues [ key as keyof RoomRequestFormValues ] ;
@@ -534,23 +547,23 @@ const NewRoomRequest: React.FC<NewRoomRequestProps> = ({ createRoomRequest }) =>
534547 { ...form . getInputProps ( 'comments' ) }
535548 />
536549 </ Stepper . Step >
537-
538- < Stepper . Completed >
539- Click the Submit button to submit the following room request:
540- < Code block mt = "xl" >
541- { JSON . stringify ( form . values , null , 2 ) }
542- </ Code >
543- </ Stepper . Completed >
550+ { ! disabled && (
551+ < Stepper . Completed >
552+ Click the Submit button to submit the following room request:
553+ < Code block mt = "xl" >
554+ { JSON . stringify ( form . values , null , 2 ) }
555+ </ Code >
556+ </ Stepper . Completed >
557+ ) }
544558 </ Stepper >
545-
546559 < Group justify = "flex-end" mt = "xl" >
547560 { active !== 0 && (
548561 < Button variant = "default" onClick = { prevStep } >
549562 Back
550563 </ Button >
551564 ) }
552565 { active !== numSteps && < Button onClick = { nextStep } > Next step</ Button > }
553- { active === numSteps && (
566+ { active === numSteps && ! disabled && (
554567 < Button onClick = { handleSubmit } color = "green" >
555568 { isSubmitting ? (
556569 < >
0 commit comments