mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
add booking status as calendar
This commit is contained in:
committed by
Thomas Ruoff
parent
b3c1b18e50
commit
a03a837615
64
components/calendar.tsx
Normal file
64
components/calendar.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
import React, { useState } from 'react'
|
||||
import cx from 'classnames'
|
||||
import useSWR from 'swr'
|
||||
import moment from 'moment'
|
||||
import { Calendar } from 'react-calendar-component'
|
||||
import { dateFormatBackend } from '../helpers/date'
|
||||
|
||||
const fetcher = (path: string) => fetch(path).then((r) => r.json())
|
||||
|
||||
export default function MyCalendar() {
|
||||
const { data: daysBooked, error: fetchBookedOnError } = useSWR(
|
||||
'/api/daysbooked',
|
||||
fetcher
|
||||
)
|
||||
|
||||
const [date, setDate] = useState(moment())
|
||||
|
||||
function dayBooked(day: Date) {
|
||||
return daysBooked && daysBooked.includes(dateFormatBackend(day))
|
||||
}
|
||||
|
||||
if (fetchBookedOnError) {
|
||||
return (
|
||||
<div>
|
||||
Entschuldige, aber die Buchungszeiten konnten nicht geladen werden.
|
||||
Versuchen Sie es später nochmals.
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<h2>Buchungsübersicht</h2>
|
||||
<Calendar
|
||||
onChangeMonth={(date) => setDate(date)}
|
||||
date={date}
|
||||
renderDay={({ day, classNames, onPickDate }) => (
|
||||
<div
|
||||
key={day.format()}
|
||||
className={cx(
|
||||
'Calendar-grid-item',
|
||||
day.isSame(moment(), 'day') && 'Calendar-grid-item--current',
|
||||
dayBooked(day.toDate()) && 'Calendar-grid-item--booked',
|
||||
classNames
|
||||
)}
|
||||
onClick={(e) => onPickDate(day)}
|
||||
>
|
||||
{day.format('D')}
|
||||
</div>
|
||||
)}
|
||||
renderHeader={({ date, onPrevMonth, onNextMonth }) => (
|
||||
<div className="Calendar-header">
|
||||
<button onClick={onPrevMonth}>«</button>
|
||||
<div className="Calendar-header-currentDate">
|
||||
{date.format('MMMM YYYY')}
|
||||
</div>
|
||||
<button onClick={onNextMonth}>»</button>
|
||||
</div>
|
||||
)}
|
||||
onPickDate={() => {}}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
11
package-lock.json
generated
11
package-lock.json
generated
@@ -9525,6 +9525,17 @@
|
||||
"prop-types": "^15.6.2"
|
||||
}
|
||||
},
|
||||
"react-calendar-component": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/react-calendar-component/-/react-calendar-component-3.0.0.tgz",
|
||||
"integrity": "sha512-vua/pu+hTeLD9SSc+NH79IwCLc3REvl4gL9C3dtUo/+cGhPiQo6CGC/Jm8AVgTBhO4CtNr21tEWAdlCVqIxBbA==",
|
||||
"requires": {
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"classnames": "^2.2.5",
|
||||
"moment": "^2.19.1",
|
||||
"prop-types": "^15.7.2"
|
||||
}
|
||||
},
|
||||
"react-dom": {
|
||||
"version": "16.13.1",
|
||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.13.1.tgz",
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"mongoose": "^5.9.25",
|
||||
"next": "^9.5.2",
|
||||
"react": "16.13.1",
|
||||
"react-calendar-component": "^3.0.0",
|
||||
"react-dom": "16.13.1",
|
||||
"rebass": "^4.0.7",
|
||||
"swr": "^0.3.0",
|
||||
|
||||
@@ -2,6 +2,7 @@ import Head from 'next/head'
|
||||
import React from 'react'
|
||||
import Footer from '../components/footer'
|
||||
import Header from '../components/header'
|
||||
import Calendar from '../components/calendar'
|
||||
import Wizard from '../components/wizard/index'
|
||||
|
||||
export default function Home() {
|
||||
@@ -14,6 +15,7 @@ export default function Home() {
|
||||
|
||||
<Header />
|
||||
<main className="main">
|
||||
<Calendar />
|
||||
<Wizard />
|
||||
</main>
|
||||
<Footer />
|
||||
|
||||
@@ -110,6 +110,64 @@
|
||||
@apply text-blue-700;
|
||||
}
|
||||
|
||||
.Calendar-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.Calendar-header {
|
||||
height: 50px;
|
||||
background: #333;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
line-height: 50px;
|
||||
display: flex;
|
||||
font-size: 20px;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.Calendar-header button {
|
||||
width: 50px;
|
||||
font-size: 20px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: #ddd;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.Calendar-grid-item {
|
||||
flex: 0 14.28571%;
|
||||
text-align: center;
|
||||
border-right: 1px solid #ddd;
|
||||
border-bottom: 1px solid #ddd;
|
||||
padding: 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.Calendar-grid-item--current {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.Calendar-grid-item--booked {
|
||||
@apply bg-red-300;
|
||||
}
|
||||
|
||||
.Calendar-grid-item.nextMonth,
|
||||
.Calendar-grid-item.prevMonth {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.Calendar-grid-item:nth-child(7n + 1) {
|
||||
border-left: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.Calendar-grid-item:nth-child(-n + 7) {
|
||||
border-top: 1px solid #ddd;
|
||||
}
|
||||
|
||||
/* Start purging... */
|
||||
@tailwind utilities;
|
||||
/* Stop purging. */
|
||||
|
||||
Reference in New Issue
Block a user