1
|
|
|
import { useStaticQuery, graphql } from "gatsby" |
2
|
|
|
import { useState } from "react" |
3
|
|
|
import { TeamsListProps } from "../Types/Team" |
4
|
|
|
import Select, { OnChangeValue } from "react-select" |
5
|
|
|
import React from "react" |
6
|
|
|
import QRCode from "qrcode.react" |
7
|
|
|
import Layout from "../layouts" |
8
|
|
|
import { Seo } from "../components/Seo" |
9
|
|
|
import "./calendar.scss" |
10
|
|
|
|
11
|
|
|
const CalendarForm = () => { |
12
|
|
|
const calendarUrl = `webcal://footbalisto.be/calendar` |
13
|
|
|
const [teamsSelected, setTeamSelected] = useState<string[]>([]) |
14
|
|
|
const [sideSelected, setSideSelected] = useState<string>(``) |
15
|
|
|
|
16
|
|
|
const sides = [ |
17
|
|
|
{ value: `home`, label: `Alleen thuiswedstrijden` }, |
18
|
|
|
{ value: `away`, label: `Alleen uitwedstrijden` }, |
19
|
|
|
{ value: `all`, label: `Alle wedstrijden` }, |
20
|
|
|
] |
21
|
|
|
|
22
|
|
|
const { teamEdges }: TeamsListProps = useStaticQuery(graphql` |
23
|
|
|
query { |
24
|
|
|
teamEdges: allNodeTeam(filter: { field_vv_id: { ne: null } }) { |
25
|
|
|
edges { |
26
|
|
|
node { |
27
|
|
|
field_division_full |
28
|
|
|
field_vv_id |
29
|
|
|
title |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
`) |
35
|
|
|
|
36
|
|
|
const teams = teamEdges.edges.map(({ node }) => ({ |
37
|
|
|
value: node.field_vv_id, |
38
|
|
|
label: `${node.title} ${node.field_division_full !== null ? `(${node.field_division_full})` : ``}`, |
39
|
|
|
})) |
40
|
|
|
|
41
|
|
|
const handleSideChange = (inputValue: { value: string; label: string } | null) => { |
42
|
|
|
if (inputValue?.value) { |
43
|
|
|
setSideSelected(inputValue.value) |
44
|
|
|
} else { |
45
|
|
|
setSideSelected(`all`) |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
const handleTeamsChange = (inputValue: OnChangeValue<{ value: string; label: string }, boolean>) => { |
50
|
|
|
if (Array.isArray(inputValue)) { |
51
|
|
|
setTeamSelected(inputValue.map(({ value }) => value)) |
52
|
|
|
} else { |
53
|
|
|
setTeamSelected([]) |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return ( |
58
|
|
|
<div> |
59
|
|
|
<form> |
60
|
|
|
<p> |
61
|
|
|
<label htmlFor="calendar__sides">Wedstrijden:</label> |
62
|
|
|
</p> |
63
|
|
|
<Select |
64
|
|
|
options={sides} |
65
|
|
|
name="sides" |
66
|
|
|
id="calendar__sides" |
67
|
|
|
className="select__input" |
68
|
|
|
onChange={handleSideChange} |
69
|
|
|
/> |
70
|
|
|
<p> |
71
|
|
|
<label htmlFor="calendar__teams">Teams:</label> |
72
|
|
|
</p> |
73
|
|
|
<Select |
74
|
|
|
options={teams} |
75
|
|
|
isMulti |
76
|
|
|
name="teams" |
77
|
|
|
id="calendar__teams" |
78
|
|
|
className="select__input" |
79
|
|
|
onChange={handleTeamsChange} |
80
|
|
|
/> |
81
|
|
|
</form> |
82
|
|
|
<p> |
83
|
|
|
Calendar:{` `} |
84
|
|
|
<a |
85
|
|
|
href={`${calendarUrl}?teams=${teamsSelected}&side=${sideSelected}`} |
86
|
|
|
>{`${calendarUrl}?teams=${teamsSelected}&side=${sideSelected}`}</a> |
87
|
|
|
</p> |
88
|
|
|
<p> |
89
|
|
|
<QRCode value={`${calendarUrl}?teams=${teamsSelected}&side=${sideSelected}`} /> |
90
|
|
|
</p> |
91
|
|
|
</div> |
92
|
|
|
) |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
const CalendarPage = () => { |
96
|
|
|
return ( |
97
|
|
|
<Layout> |
98
|
|
|
<header className="page_header__wrapper"> |
99
|
|
|
<div className="page_header"> |
100
|
|
|
<h1>Stel je kalender samen</h1> |
101
|
|
|
</div> |
102
|
|
|
</header> |
103
|
|
|
|
104
|
|
|
<div className="calendar__wrapper page__wrapper page__wrapper--limited"> |
105
|
|
|
<section> |
106
|
|
|
<CalendarForm /> |
107
|
|
|
</section> |
108
|
|
|
</div> |
109
|
|
|
</Layout> |
110
|
|
|
) |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
export const Head = () => { |
114
|
|
|
return ( |
115
|
|
|
<Seo |
116
|
|
|
title="Maak uw eigen kalender" |
117
|
|
|
description="Stel een eigen seizoenskalender samen met de teams die jou interesseren." |
118
|
|
|
path="/calendar/" |
119
|
|
|
/> |
120
|
|
|
) |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
export default CalendarPage |
124
|
|
|
|