Skip to content

Commit b6011eb

Browse files
committed
new add participant flow
1 parent e8db002 commit b6011eb

File tree

2 files changed

+42
-62
lines changed

2 files changed

+42
-62
lines changed

frontend/src/components/pages/participants/AddParticipantCard.tsx

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,39 @@
11
import 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";
96
import { CREATE_PARTICIPANT } from "../../../gql/mutations";
107

118
import ModalContainer from "../../common/ModalContainer";
129
import FormInputField from "../../common/FormInputField";
13-
import FormSelectField from "../../common/FormSelectField";
1410

1511
type 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}
Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,47 @@
11
import { Button, Flex, Text } from '@chakra-ui/react';
2-
import React from 'react'
2+
import React, { useState } from 'react'
3+
import AddParticipantCard from './AddParticipantCard';
34

45
type EmptyParticipantCardProps = {
56
roomNumber: string;
67
}
78

89
const EmptyParticipantCard = ({roomNumber}: EmptyParticipantCardProps) => {
9-
return (
10-
<Flex
11-
w="180px"
12-
h="130px"
13-
border="2px solid"
14-
borderColor="#E2E8F0"
15-
borderRadius="5px"
16-
flexDir="column"
17-
justifyContent="top"
18-
alignItems="center"
19-
>
20-
<Flex w="full" justifyContent="center" p="5px" bg="#E3ECEB" fontSize="small" fontWeight="700">Room {roomNumber}</Flex>
21-
<Flex
22-
w="full"
23-
h="full"
10+
const [addParticipant, setAddParticipant] = useState(false);
11+
return (
12+
<Flex
13+
w="180px"
14+
h="130px"
15+
border="2px solid"
16+
borderColor="#E2E8F0"
17+
borderRadius="5px"
2418
flexDir="column"
19+
justifyContent="top"
2520
alignItems="center"
26-
justifyContent="center"
27-
gap="5px"
2821
>
29-
<Flex fontSize="xs">The room is empty.</Flex>
30-
<Button size="xs" bg="orange.500" color="white" mt="3px">Add Participant</Button>
22+
<Flex w="full" justifyContent="center" p="5px" bg="#E3ECEB" fontSize="small" fontWeight="700">Room {roomNumber}</Flex>
23+
<Flex
24+
w="full"
25+
h="full"
26+
flexDir="column"
27+
alignItems="center"
28+
justifyContent="center"
29+
gap="5px"
30+
>
31+
<Flex fontSize="xs">The room is empty.</Flex>
32+
<Button
33+
size="xs"
34+
bg="orange.500"
35+
color="white"
36+
mt="3px"
37+
onClick={() => setAddParticipant(true)}
38+
>
39+
Add Participant
40+
</Button>
41+
</Flex>
42+
{addParticipant && <AddParticipantCard roomNumber={roomNumber} close={() => setAddParticipant(false)} />}
3143
</Flex>
32-
</Flex>
33-
)
44+
)
3445
}
3546

3647
export default EmptyParticipantCard

0 commit comments

Comments
 (0)