-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGroupManager.jsx
More file actions
144 lines (136 loc) · 4.08 KB
/
GroupManager.jsx
File metadata and controls
144 lines (136 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import {
Box,
Button,
Divider,
Grid,
Stack,
TextField,
Typography,
} from "@mui/material";
import { LoadingButton } from "@mui/lab";
import { useEffect, useMemo, useState } from "react";
import { GroupRest } from "../../../rest/GroupRest";
export function GroupManager(props) {
const [loadingNewTeam, setLoadingNewTeam] = useState(false);
const [fetchingExistingTeam, setFetchingExistingTeam] = useState(false);
const [group, setGroup] = useState(false);
const [groupInput, setGroupInput] = useState("");
const [groupInputError, setGroupInputError] = useState(false);
const [groupName, setGroupName] = useState("");
const groupRest = useMemo(() => new GroupRest(), []);
function createNewGroup() {
setLoadingNewTeam(true);
setGroupInputError(false);
groupRest
.createGroup(props.eventId, groupName)
.then((response) => {
setLoadingNewTeam(false);
setGroup(response.data);
})
.catch((err) => {
console.error(err);
setLoadingNewTeam(false);
});
}
function getGroup() {
setFetchingExistingTeam(true);
setGroupInputError(false);
groupRest
.getGroup(props.eventId, groupInput)
.then((response) => {
setFetchingExistingTeam(false);
setGroup(response.data);
})
.catch((error) => {
setFetchingExistingTeam(false);
setGroupInput("");
setGroupInputError(true);
});
}
useEffect(() => {
props.onGroupChange(group);
}, [group]);
function renderGroupSelection() {
return (
<Box sx={{ pt: 5, pb: 5 }}>
<Stack direction="row" spacing={2}>
<TextField
fullWidth
label={"Enter team identification (e.g. chalk-increase-vague)"}
value={groupInput}
onChange={(event) => setGroupInput(event.target.value)}
error={groupInputError}
helperText={
groupInputError ? "Did not find specified group" : undefined
}
/>
<LoadingButton
variant={"outlined"}
disabled={loadingNewTeam}
loading={fetchingExistingTeam}
onClick={getGroup}
>
Join
</LoadingButton>
</Stack>
<Typography variant={"body2"} color={"text.disabled"} pt={1}>
Identifier given by the group creator
</Typography>
<Divider sx={{ pt: 2, pb: 2 }}> or </Divider>
<Stack direction="row" spacing={2}>
<TextField
fullWidth
label={"Enter team name (e.g. Carbon Coders)"}
value={groupName}
onChange={(event) => setGroupName(event.target.value)}
disabled={fetchingExistingTeam}
/>
<LoadingButton
sx={{ flexWrap: "nowrap" }}
width={"100px"}
variant={"outlined"}
color={"primary"}
onClick={createNewGroup}
loading={loadingNewTeam}
disabled={
fetchingExistingTeam ||
groupName.length < 3 ||
groupName.length > 30
}
>
Create
</LoadingButton>
</Stack>
<Typography variant={"body2"} color={"text.disabled"} pt={1}>
This will be your team name at the event
</Typography>
</Box>
);
}
function renderGroup() {
return (
<Box sx={{ pt: 5, pb: 5 }}>
<Typography gutterBottom>
You are assigned to the group with identifier
</Typography>
<Typography sx={{ fontWeight: 800, pb: 3 }} variant={"h5"}>
{group.phrase}
</Typography>
<Button variant="outlined" onClick={() => setGroup(null)}>
Reset Group
</Button>
<Typography sx={{ pt: 4 }}>
share this identifier to your team members
</Typography>
<Typography color={"text.secondary"}>
This is not your actual team name at the event
</Typography>
</Box>
);
}
return (
<Grid item md={12} xs={12}>
{group ? renderGroup() : renderGroupSelection()}
</Grid>
);
}