Newer
Older
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
145
146
147
148
149
150
151
152
153
154
155
import { useRouter } from "next/router";
import { useSession, signIn } from "next-auth/react";
import { useTranslation } from "next-i18next";
import {
Alert,
Button,
Card,
Group,
List,
Space,
useMantineTheme,
} from "@mantine/core";
import { Icon, ICONS } from "vseth-canine-ui";
import parse from "html-react-parser";
import hasAccess from "../utilities/hasAccess";
import { getAccentColor } from "../utilities/colors";
import { formatDateFromDB, formatTimeFromDB } from "../utilities/dates";
import { isRegistered } from "../utilities/signUp";
import { gql, useMutation } from "@apollo/client";
const addSignUpMutation = gql`
mutation addSignUp($id: Int) {
addSignUp(id: $id)
}
`;
const removeSignUpMutation = gql`
mutation removeSignUp($id: Int) {
removeSignUp(id: $id)
}
`;
export default function EventCard({
event,
setEvent,
setOpen,
refetch,
setSignUpOpen,
}) {
const [addSignUp] = useMutation(addSignUpMutation);
const [removeSignUp] = useMutation(removeSignUpMutation);
const { data: session } = useSession();
const { t } = useTranslation("common");
const theme = useMantineTheme();
const { locale } = useRouter();
const accentColor = getAccentColor(theme);
const signedUp = isRegistered(session, event);
const signUp = async (id) => {
if (!session) signIn();
await addSignUp({
variables: {
id: event.id,
},
});
refetch();
};
const signOff = async (id) => {
await removeSignUp({
variables: {
id: event.id,
},
});
refetch();
};
const editEvent = (event) => {
setEvent(event);
setOpen(true);
};
const viewSignUps = (event) => {
setEvent(event);
setSignUpOpen(true);
};
return (
<Card
shadow="md"
radius="md"
style={{
display: "flex",
justifyContent: "space-between",
flexDirection: "column",
width: "100%",
color: event.isStammtisch ? "gray" : "",
}}
withBorder
>
<div>
<Group>
<h2 style={{ margin: 0 }}>{event.title}</h2>
</Group>
{signedUp && (
<>
<Space h="xs" />
<Alert
color="green"
variant="light"
icon={<Icon icon={ICONS.CHECK} color="green" />}
title={t("signedUpTitle")}
>
{t("signedUpText")}
</Alert>
</>
)}
<Space h="lg" />
<List
spacing="md"
size="md"
center
style={{ color: event.isStammtisch ? "gray" : "" }}
>
{event.speaker && (
<List.Item
icon={<Icon icon={ICONS.USER} color="#f28a20" size={16} />}
>
<p>{event.speaker}</p>
</List.Item>
)}
<List.Item
icon={<Icon icon={ICONS.LOCATION} color="#f28a20" size={16} />}
>
<p>{event.place}</p>
</List.Item>
<List.Item
icon={<Icon icon={ICONS.CALENDAR} color="#f28a20" size={16} />}
>
<p>{formatDateFromDB(event.date, locale)}</p>
</List.Item>
<List.Item
icon={<Icon icon={ICONS.CLOCK} color="#f28a20" size={16} />}
>
<p>{formatTimeFromDB(event.startTime, event.endTime)}</p>
</List.Item>
</List>
<Space h="lg" />
<p>{parse(event.description)}</p>
</div>
<div>
{!event.isStammtisch && (
<Group mt="xl" style={{ verticalAlign: "middle" }} grow>
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
{event.signUp ? (
<Button
href={event.signUp}
target="_blank"
rightIcon={<Icon icon={ICONS.RIGHT} color="#f28a20" />}
component="a"
>
{t("externalSignUp")}
</Button>
) : (
<>
{signedUp ? (
<Button
onClick={() => signOff(event.id)}
leftIcon={<Icon icon={ICONS.USER_MINUS} color="white" />}
>
{t("signOff")}
</Button>
) : (
<Button
onClick={() => signUp(event.id)}
leftIcon={<Icon icon={ICONS.USER_PLUS} color="#f28a20" />}
style={{ color: "#f28a20" }}
>
{t("signUp")}
</Button>
)}
</>
)}
</Group>
)}
{hasAccess(session, true) && (
<Group grow mt="md" style={{ verticalAlign: "middle" }}>
<Button
leftIcon={<Icon icon={ICONS.EDIT} color={accentColor} />}
variant="light"
onClick={() => editEvent(event)}
>
{t("editEvent")}
</Button>
{!event.isStammtisch && (
leftIcon={<Icon icon={ICONS.LIST} color={accentColor} />}
onClick={() => viewSignUps(event)}
{t("viewParticipants")}
)}
</Group>
)}