Skip to content

Commit 531e296

Browse files
committed
new design past participants implementation
1 parent cdbaed3 commit 531e296

File tree

9 files changed

+298
-123
lines changed

9 files changed

+298
-123
lines changed

backend/graphql/resolvers/participantResolver.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import IParticipantService from "../../services/interface/participantInterface";
55
const participantService: IParticipantService = new ParticipantService();
66
const participantResolvers = {
77
Query: {
8-
getAllParticipants: async (): Promise<Participant[]> => {
9-
return participantService.getAllParticipants();
8+
getPastParticipants: async (): Promise<Participant[]> => {
9+
return participantService.getPastParticipants();
1010
},
1111
getParticipantById: async (
1212
_parent: undefined,
@@ -47,10 +47,10 @@ const participantResolvers = {
4747
password,
4848
}: {
4949
participantId: string;
50-
roomNumber: number;
51-
arrival: string;
52-
departure: string;
53-
password: string;
50+
roomNumber?: number;
51+
arrival?: string;
52+
departure?: string;
53+
password?: string;
5454
},
5555
): Promise<boolean> => {
5656
return participantService.updateParticipantById(

backend/graphql/types/resolvers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { gql } from "apollo-server-express";
22

33
const resolverTypes = gql`
44
type Query {
5-
getAllParticipants: [Participant]
5+
getPastParticipants: [Participant]
66
getParticipantById(participantId: String!): Participant
77
getAvailableRooms: [Int]
88
}
@@ -16,10 +16,10 @@ const resolverTypes = gql`
1616
): Boolean
1717
updateParticipantById(
1818
participantId: String!
19-
roomNumber: Int!
20-
arrival: String!
21-
departure: String!
22-
password: String!
19+
roomNumber: Int
20+
arrival: String
21+
departure: String
22+
password: String
2323
): Boolean
2424
}
2525
`;

backend/services/implementation/participantImplementation.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import prisma from "../../prisma";
33
import IParticipantService from "../interface/participantInterface";
44

55
class ParticipantService implements IParticipantService {
6-
async getAllParticipants(): Promise<Participant[]> {
6+
async getPastParticipants(): Promise<Participant[]> {
77
try {
88
const participants = await prisma.participant.findMany({
9-
orderBy: [{ departure: "asc" }, { arrival: "asc" }],
9+
where: {departure: { not: "" }},
10+
orderBy: [{ departure: "desc" }],
1011
});
1112
return participants;
1213
} catch (err) {
@@ -56,20 +57,21 @@ class ParticipantService implements IParticipantService {
5657

5758
async updateParticipantById(
5859
participantId: string,
59-
roomNumber: number,
60-
arrival: string,
61-
departure: string,
62-
password: string,
60+
roomNumber?: number,
61+
arrival?: string,
62+
departure?: string,
63+
password?: string,
6364
): Promise<boolean> {
65+
const updatedData: Record<string, any> = {};
66+
if (roomNumber) updatedData.roomNumber = roomNumber;
67+
if (arrival) updatedData.arrival = arrival;
68+
if (departure) updatedData.departure = departure;
69+
if (password) updatedData.password = password;
70+
6471
try {
6572
await prisma.participant.update({
6673
where: { participantId },
67-
data: {
68-
roomNumber,
69-
arrival,
70-
departure,
71-
password,
72-
},
74+
data: updatedData,
7375
});
7476
return true;
7577
} catch (err) {

backend/services/interface/participantInterface.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Participant } from "@prisma/client";
22

33
interface IParticipantService {
4-
getAllParticipants(): Promise<Participant[]>;
4+
getPastParticipants(): Promise<Participant[]>;
55
getParticipantById(participantId: string): Promise<Participant | null>;
66
createParticipant(
77
participantId: string,
@@ -11,10 +11,10 @@ interface IParticipantService {
1111
): Promise<boolean>;
1212
updateParticipantById(
1313
participantId: string,
14-
roomNumber: number,
15-
arrival: string,
16-
departure: string,
17-
password: string,
14+
roomNumber?: number,
15+
arrival?: string,
16+
departure?: string,
17+
password?: string,
1818
): Promise<boolean>;
1919
}
2020

frontend/src/components/common/CommonTable.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,15 @@ const CommonTable = ({
170170
flexDir="column"
171171
alignContent="space-between"
172172
justifyContent="space-between"
173-
h="100%"
174173
>
175174
<TableContainer
176-
m="10px"
177175
border="2px solid"
178-
borderColor="#E3ECEB"
176+
borderColor="#E2E8F0"
179177
borderRadius="6px"
180178
>
181179
<Table>
182180
<Thead>
183-
<Tr backgroundColor="#E3ECEB" w="100%">
181+
<Tr backgroundColor="#EDF2F7" w="100%">
184182
{isSelectable ? (
185183
<Th p="0px 0px 0px 20px" w="16px">
186184
<Checkbox
@@ -253,7 +251,7 @@ const CommonTable = ({
253251
.slice((page - 1) * maxResults, page * maxResults)
254252
.map((row, index) => {
255253
return (
256-
<Tr key={index}>
254+
<Tr key={index} borderTop="2px solid" borderColor="#E2E8F0">
257255
{isSelectable ? (
258256
<Td p="0px 0px 0px 20px" w="16px">
259257
<Checkbox
@@ -318,8 +316,8 @@ const CommonTable = ({
318316
</ModalContainer>
319317
)}
320318

321-
<Box h="50px" position="relative">
322-
<Box position="absolute" w="250px" h="50px" ml="10px">
319+
<Box h="50px" position="relative" mt="20px">
320+
<Box position="absolute" w="250px" h="50px">
323321
{`Showing ${(page - 1) * maxResults + 1} to ${Math.min(
324322
page * maxResults,
325323
data.length,
@@ -338,7 +336,7 @@ const CommonTable = ({
338336
_hover={{
339337
cursor: "pointer",
340338
}}
341-
color="#0E373B"
339+
color="#15646E"
342340
backgroundColor="white"
343341
aria-label="Previous Page"
344342
icon={<ChevronLeftOutlinedIcon />}
@@ -347,15 +345,15 @@ const CommonTable = ({
347345
{pageArray.map((item, index) => {
348346
return (
349347
<Center
350-
backgroundColor={item === page ? "#0E373B" : "white"}
348+
backgroundColor={item === page ? "#15646E" : "white"}
351349
h="35px"
352350
p="10px"
353351
flexBasis="35px"
354352
borderRadius="7px"
355353
_hover={{
356354
cursor: "pointer",
357355
color: "white",
358-
backgroundColor: "#0E373B",
356+
backgroundColor: "#15646E",
359357
}}
360358
textColor={item === page ? "white" : "gray.main"}
361359
onClick={() => numberPaginate(item)}
@@ -371,7 +369,7 @@ const CommonTable = ({
371369
_hover={{
372370
cursor: "pointer",
373371
}}
374-
color="#0E373B"
372+
color="#15646E"
375373
backgroundColor="white"
376374
aria-label="Next Page"
377375
icon={<ChevronRightOutlinedIcon />}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import React, { useState } from "react";
2+
import { Button, Flex, Spinner } from "@chakra-ui/react";
3+
4+
import { useMutation, useQuery } from "@apollo/client";
5+
6+
import { GET_AVAILABLE_ROOMS } from "../../../gql/queries";
7+
import { UPDATE_PARTICIPANT_BY_ID } from "../../../gql/mutations";
8+
9+
import ModalContainer from "../../common/ModalContainer";
10+
import FormInputField from "../../common/FormInputField";
11+
import FormSelectField from "../../common/FormSelectField";
12+
import { TableData } from "../../common/CommonTable";
13+
14+
type EditParticipantCardProps = {
15+
selected: TableData;
16+
close: () => void;
17+
};
18+
19+
const EditPastParticipantCard = ({
20+
selected,
21+
close,
22+
}: EditParticipantCardProps): React.ReactElement => {
23+
const [arrivalDate, setArrivalDate] = useState(selected.arrival);
24+
const [departureDate, setDepartureDate] = useState(selected.departure);
25+
const [error, setError] = useState("");
26+
27+
const [updateParticipantById] = useMutation(UPDATE_PARTICIPANT_BY_ID);
28+
29+
const reset = () => {
30+
setArrivalDate(selected.arrival);
31+
setDepartureDate(selected.departure);
32+
setError("");
33+
};
34+
35+
const validate = () => {
36+
if (!arrivalDate || !departureDate) {
37+
setError("Missing fields.");
38+
return false;
39+
}
40+
if (arrivalDate === selected.arrival && departureDate === selected.departure) {
41+
setError("No changes made.");
42+
return false;
43+
}
44+
const start = new Date(arrivalDate);
45+
const end = new Date(departureDate);
46+
if (start > end) {
47+
setError("Invalid update.")
48+
return false;
49+
}
50+
return true;
51+
};
52+
53+
const handleSubmit = async () => {
54+
setError("");
55+
try {
56+
const valid: boolean = validate();
57+
if (valid) {
58+
await updateParticipantById({
59+
variables: {
60+
participantId: selected.participantId,
61+
arrival: arrivalDate,
62+
departure: departureDate
63+
},
64+
});
65+
reset();
66+
close();
67+
window.location.reload();
68+
}
69+
} catch (err) {
70+
setError("Unable to update participant.");
71+
console.log(err);
72+
}
73+
};
74+
75+
return (
76+
<ModalContainer title="Edit Past Participant">
77+
<Flex flexDir="column" gap="10px">
78+
{error && <Flex textColor="red.500">{error}</Flex>}
79+
80+
<Flex flexDir="column">
81+
<Flex mb="5px" color="gray.main" fontWeight="700">
82+
ID Number
83+
</Flex>
84+
<Flex>{selected.participantId}</Flex>
85+
</Flex>
86+
87+
<FormInputField
88+
label="Arrival Date"
89+
value={arrivalDate}
90+
type="date"
91+
onChange={(e) => {
92+
setArrivalDate(e.target.value);
93+
}}
94+
/>
95+
96+
<FormInputField
97+
label="Departure Date"
98+
value={departureDate}
99+
type="date"
100+
onChange={(e) => {
101+
setDepartureDate(e.target.value);
102+
}}
103+
/>
104+
105+
<Flex justifyContent="flex-end" mt="10px">
106+
<Button
107+
variant="cancel"
108+
mr="10px"
109+
onClick={() => {
110+
reset();
111+
close();
112+
}}
113+
>
114+
Cancel
115+
</Button>
116+
<Button variant="primary" onClick={handleSubmit}>
117+
Save
118+
</Button>
119+
</Flex>
120+
</Flex>
121+
</ModalContainer>
122+
);
123+
};
124+
125+
export default EditPastParticipantCard;

0 commit comments

Comments
 (0)