11import React , { useState } from "react" ;
2- import { Button , Flex , Spinner } from "@chakra-ui/react" ;
2+ import { Button , Flex } from "@chakra-ui/react" ;
33
4- import { useMutation , useQuery , useLazyQuery } from "@apollo/client" ;
5- import {
6- GET_AVAILABLE_ROOMS ,
7- GET_PARTICIPANT_BY_ID ,
8- } from "../../../gql/queries" ;
4+ import { useMutation , useLazyQuery } from "@apollo/client" ;
5+ import { GET_PARTICIPANT_BY_ID } from "../../../gql/queries" ;
96import { CREATE_PARTICIPANT } from "../../../gql/mutations" ;
107
118import ModalContainer from "../../common/ModalContainer" ;
129import FormInputField from "../../common/FormInputField" ;
13- import FormSelectField from "../../common/FormSelectField" ;
1410
1511type AddParticipantCardProps = {
12+ roomNumber : string ;
1613 close : ( ) => void ;
1714} ;
1815
19- const AddParticipantCard = ( {
20- close ,
21- } : AddParticipantCardProps ) : React . ReactElement => {
16+ const AddParticipantCard = ( { roomNumber , close } : AddParticipantCardProps ) : React . ReactElement => {
17+ // eslint-disable-next-line prefer-template
18+ const title = "Add Participant to Room " + roomNumber ;
2219 const [ participantId , setParticipantId ] = useState ( "" ) ;
23- const [ roomNumber , setRoomNumber ] = useState ( "" ) ;
2420 const [ arrivalDate , setArrivalDate ] = useState ( "" ) ;
2521 const [ password , setPassword ] = useState ( "" ) ;
2622
2723 const [ error , setError ] = useState ( "" ) ;
2824
29- const {
30- loading : getAvailableRoomsLoading ,
31- error : getAvailableRoomsError ,
32- data : getAvailableRoomsData ,
33- } = useQuery ( GET_AVAILABLE_ROOMS ) ;
3425 const [ getParticipantById ] = useLazyQuery ( GET_PARTICIPANT_BY_ID ) ;
3526 const [ createParticipant ] = useMutation ( CREATE_PARTICIPANT ) ;
3627
3728 const reset = ( ) => {
3829 setParticipantId ( "" ) ;
39- setRoomNumber ( "" ) ;
4030 setArrivalDate ( "" ) ;
4131 setPassword ( "" ) ;
4232 setError ( "" ) ;
4333 } ;
4434
4535 const validate = async ( ) => {
46- if ( ! participantId || ! roomNumber || ! arrivalDate || ! password ) {
36+ if ( ! participantId || ! arrivalDate || ! password ) {
4737 setError ( "Missing fields." ) ;
4838 return false ;
4939 }
@@ -88,7 +78,7 @@ const AddParticipantCard = ({
8878 } ;
8979
9080 return (
91- < ModalContainer title = "Add Participant" >
81+ < ModalContainer title = { title } >
9282 < Flex flexDir = "column" gap = "20px" >
9383 { error && < Flex textColor = "red.500" > { error } </ Flex > }
9484
@@ -102,27 +92,6 @@ const AddParticipantCard = ({
10292 required
10393 />
10494
105- { getAvailableRoomsLoading ? (
106- < Spinner />
107- ) : getAvailableRoomsError || ! getAvailableRoomsData ? (
108- < Flex p = "10px" > Error getting rooms.</ Flex >
109- ) : (
110- < FormSelectField
111- label = "Room Number"
112- placeholder = "Please select a room"
113- value = { roomNumber }
114- options = { getAvailableRoomsData . getAvailableRooms . map (
115- ( room : number ) => ( {
116- key : room ,
117- value : room ,
118- display : `Room ${ room } ` ,
119- } ) ,
120- ) }
121- onChange = { ( e ) => setRoomNumber ( e . target . value ) }
122- required
123- />
124- ) }
125-
12695 < FormInputField
12796 label = "Arrival Date"
12897 value = { arrivalDate }
0 commit comments