Skip to content

Commit 67a590d

Browse files
committed
edit current participant arrival and password
1 parent b6011eb commit 67a590d

File tree

3 files changed

+72
-65
lines changed

3 files changed

+72
-65
lines changed
Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Button, Flex, Text } from '@chakra-ui/react';
2-
import React from 'react'
2+
import React, { useState } from 'react'
3+
import EditParticipantCard from './EditParticipantCard';
34

45
type CurrentParticipantCardProps = {
56
roomNumber: string;
@@ -9,32 +10,50 @@ type CurrentParticipantCardProps = {
910
}
1011

1112
const CurrentParticipantCard = ({roomNumber, participantId, arrival, password}: CurrentParticipantCardProps) => {
12-
return (
13-
<Flex
14-
w="180px"
15-
h="130px"
16-
border="2px solid"
17-
borderColor="#E2E8F0"
18-
borderRadius="5px"
19-
flexDir="column"
20-
justifyContent="top"
21-
alignItems="center"
22-
>
23-
<Flex w="full" justifyContent="center" p="5px" bg="#E3ECEB" fontSize="small" fontWeight="700">Room {roomNumber}</Flex>
24-
<Flex
25-
w="full"
26-
h="full"
13+
const [editParticipant, setEditParticipant] = useState(false);
14+
return (
15+
<Flex
16+
w="180px"
17+
h="130px"
18+
border="2px solid"
19+
borderColor="#E2E8F0"
20+
borderRadius="5px"
2721
flexDir="column"
22+
justifyContent="top"
2823
alignItems="center"
29-
justifyContent="center"
30-
gap="5px"
3124
>
32-
<Flex fontSize="xs">ID Number: { participantId }</Flex>
33-
<Flex fontSize="xs">Arrival Date: { arrival }</Flex>
34-
<Button size="xs" bg="orange.500" color="white" mt="3px">Edit Participant</Button>
25+
<Flex w="full" justifyContent="center" p="5px" bg="#E3ECEB" fontSize="small" fontWeight="700">Room {roomNumber}</Flex>
26+
<Flex
27+
w="full"
28+
h="full"
29+
flexDir="column"
30+
alignItems="center"
31+
justifyContent="center"
32+
gap="5px"
33+
>
34+
<Flex fontSize="xs">ID Number: { participantId }</Flex>
35+
<Flex fontSize="xs">Arrival Date: { arrival }</Flex>
36+
<Button
37+
size="xs"
38+
bg="orange.500"
39+
color="white"
40+
mt="3px"
41+
onClick={() => setEditParticipant(true)}
42+
>
43+
Edit Participant
44+
</Button>
45+
</Flex>
46+
{editParticipant &&
47+
<EditParticipantCard
48+
selectedRoomNumber={roomNumber}
49+
selectedParticipantId={participantId}
50+
selectedArrival={arrival}
51+
selectedPassword={password}
52+
close={() => setEditParticipant(false)}
53+
/>
54+
}
3555
</Flex>
36-
</Flex>
37-
)
56+
)
3857
}
3958

4059
export default CurrentParticipantCard

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

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,50 @@ import { UPDATE_PARTICIPANT_BY_ID } from "../../../gql/mutations";
99
import ModalContainer from "../../common/ModalContainer";
1010
import FormInputField from "../../common/FormInputField";
1111
import FormSelectField from "../../common/FormSelectField";
12-
import { TableData } from "../../common/CommonTable";
1312

1413
type EditParticipantCardProps = {
15-
selected: TableData;
14+
selectedRoomNumber: string;
15+
selectedParticipantId: string;
16+
selectedArrival: string;
17+
selectedPassword: string;
1618
close: () => void;
1719
};
1820

1921
const EditParticipantCard = ({
20-
selected,
22+
selectedRoomNumber,
23+
selectedParticipantId,
24+
selectedArrival,
25+
selectedPassword,
2126
close,
2227
}: EditParticipantCardProps): React.ReactElement => {
23-
const [roomNumber, setRoomNumber] = useState(selected.roomNumber);
24-
const [arrivalDate, setArrivalDate] = useState(selected.arrival);
25-
const [departureDate, setDepartureDate] = useState(selected.departure);
26-
const [password, setPassword] = useState(selected.password);
28+
// eslint-disable-next-line prefer-template
29+
const title = "Edit Participant in Room " + selectedRoomNumber;
2730

31+
const [arrivalDate, setArrivalDate] = useState(selectedArrival);
32+
const [password, setPassword] = useState(selectedPassword);
2833
const [error, setError] = useState("");
2934

30-
const {
31-
loading: getAvailableRoomsLoading,
32-
error: getAvailableRoomsError,
33-
data: getAvailableRoomsData,
34-
} = useQuery(GET_AVAILABLE_ROOMS);
35+
// const {
36+
// loading: getAvailableRoomsLoading,
37+
// error: getAvailableRoomsError,
38+
// data: getAvailableRoomsData,
39+
// } = useQuery(GET_AVAILABLE_ROOMS);
3540
const [updateParticipantById] = useMutation(UPDATE_PARTICIPANT_BY_ID);
3641

3742
const reset = () => {
38-
setRoomNumber(selected.roomNumber);
39-
setArrivalDate(selected.arrival);
40-
setDepartureDate(selected.departure);
41-
setPassword(selected.password);
43+
setArrivalDate(selectedArrival);
44+
setPassword(selectedPassword);
4245
setError("");
4346
};
4447

45-
const validate = async () => {
46-
if (!roomNumber || !arrivalDate || !password) {
48+
const validate = () => {
49+
if (!arrivalDate || !password) {
4750
setError("Missing fields.");
4851
return false;
4952
}
5053
if (
51-
roomNumber === selected.roomNumber &&
52-
arrivalDate === selected.arrival &&
53-
departureDate === selected.departure &&
54-
password === selected.password
54+
arrivalDate === selectedArrival &&
55+
password === selectedPassword
5556
) {
5657
setError("No changes made.");
5758
return false;
@@ -62,15 +63,12 @@ const EditParticipantCard = ({
6263
const handleSubmit = async () => {
6364
setError("");
6465
try {
65-
const valid: boolean = await validate();
66+
const valid: boolean = validate();
6667
if (valid) {
67-
const room = parseInt(roomNumber, 10);
6868
await updateParticipantById({
69-
variables: {
70-
participantId: selected.participantId,
71-
roomNumber: room,
69+
variables: {
70+
participantId: selectedParticipantId,
7271
arrival: arrivalDate,
73-
departure: departureDate,
7472
password,
7573
},
7674
});
@@ -85,18 +83,18 @@ const EditParticipantCard = ({
8583
};
8684

8785
return (
88-
<ModalContainer title="Edit Participant">
86+
<ModalContainer title={title}>
8987
<Flex flexDir="column" gap="20px">
9088
{error && <Flex textColor="red.500">{error}</Flex>}
9189

9290
<Flex flexDir="column">
9391
<Flex mb="5px" color="gray.main" fontWeight="700">
9492
ID Number
9593
</Flex>
96-
<Flex>{selected.participantId}</Flex>
94+
<Flex>{selectedParticipantId}</Flex>
9795
</Flex>
9896

99-
{getAvailableRoomsLoading ? (
97+
{/* {getAvailableRoomsLoading ? (
10098
<Spinner />
10199
) : getAvailableRoomsError || !getAvailableRoomsData ? (
102100
<Flex p="10px">Error getting rooms.</Flex>
@@ -116,7 +114,7 @@ const EditParticipantCard = ({
116114
setRoomNumber(e.target.value || selected.roomNumber)
117115
}
118116
/>
119-
)}
117+
)} */}
120118

121119
<FormInputField
122120
label="Arrival Date"
@@ -127,15 +125,6 @@ const EditParticipantCard = ({
127125
}}
128126
/>
129127

130-
<FormInputField
131-
label="Departure Date"
132-
value={departureDate}
133-
type="date"
134-
onChange={(e) => {
135-
setDepartureDate(e.target.value);
136-
}}
137-
/>
138-
139128
<FormInputField
140129
label="Password"
141130
value={password}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import CommonTable, {
2020
} from "../../common/CommonTable";
2121
import SideBar from "../../common/SideBar";
2222
import AddParticipantCard from "./AddParticipantCard";
23-
import EditParticipantCard from "./EditParticipantCard";
2423
import EditPastParticipantCard from "./EditPastParticipantCard";
2524
import CurrentParticipantCard from "./CurrentParticipantCard";
2625
import EmptyParticipantCard from "./EmptyParticipantCard";

0 commit comments

Comments
 (0)