prettier all the things

This commit is contained in:
Thomas Ruoff
2022-02-19 23:18:49 +01:00
committed by Thomas Ruoff
parent c35d3009c6
commit 36f8719531
28 changed files with 433 additions and 428 deletions

View File

@@ -22,7 +22,10 @@ function BookForm() {
{dataStoredLoaded && (
<p className="mb-6 info-message">
Buchungsdaten wurden aus Deinem Browser geladen und vorausgefüllt.{' '}
<a className="font-medium text-blue-400 underline cursor-pointer hover:text-blue-600" onClick={forgetData}>
<a
className="font-medium text-blue-400 underline cursor-pointer hover:text-blue-600"
onClick={forgetData}
>
Daten wieder vergessen
</a>
</p>

View File

@@ -9,7 +9,10 @@ export default function Denied() {
onClick={(e) => {
e.preventDefault()
signIn()
}}>Melde dich an um diese Seite zu sehen.</a>
}}
>
Melde dich an um diese Seite zu sehen.
</a>
</p>
</>
)

View File

@@ -7,10 +7,18 @@ type InputProps = React.InputHTMLAttributes<HTMLInputElement> & {
}
export default function Input(props: InputProps) {
const { label, name, required, type = 'text', className = "", ...rest } = props
const {
label,
name,
required,
type = 'text',
className = '',
...rest
} = props
const defaultClasses = "appearance-none bg-gray-50 text-gray-500 border rounded py-2 px-3 mb-3 leading-tight disabled:bg-gray-200 disabled:cursor-not-allowed focus: outline-none focus:bg-white w-full"
const classes = `${defaultClasses} ${className}`;
const defaultClasses =
'appearance-none bg-gray-50 text-gray-500 border rounded py-2 px-3 mb-3 leading-tight disabled:bg-gray-200 disabled:cursor-not-allowed focus: outline-none focus:bg-white w-full'
const classes = `${defaultClasses} ${className}`
return (
<InputWrapper label={label} name={name} required={required}>

View File

@@ -13,7 +13,10 @@ export default function Input(props: {
<>
<div className="flex flex-wrap -mx-3 mb-2">
<div className="w-full px-3 mb-2">
<label className="block uppercase tracking-wide text-gray-500 text-xs font-bold mb-2" htmlFor={name}>
<label
className="block uppercase tracking-wide text-gray-500 text-xs font-bold mb-2"
htmlFor={name}
>
{label} {required && <Required />}
</label>
{children}

View File

@@ -3,30 +3,34 @@ const H1 = (props: any) => (
className="pb-2 mt-6 mb-4 text-4xl font-semibold leading-tight border-b"
{...props}
/>
)
)
const H2 = (props: any) => (
<h2
className="pb-2 mt-6 mb-4 text-2xl font-semibold leading-tight border-b"
{...props}
/>
)
)
const H3 = (props: any) => (
<h3 className="mt-6 mb-4 text-lg font-semibold leading-snug" {...props} />
)
)
const H4 = (props: any) => (
<h4 className="mt-6 mb-4 text-base font-semibold leading-none" {...props} />
)
)
const H5 = (props: any) => (
<h5 className="mt-6 mb-4 text-sm font-semibold leading-tight" {...props} />
)
)
const H6 = (props: any) => (
<h6
className="mt-6 mb-4 text-sm font-semibold leading-tight text-gray-600"
{...props}
/>
)
const UL = (props: any) => <ul className="pl-8 text-base list-disc" {...props} />
const OL = (props: any) => <ol className="pl-8 text-base list-decimal" {...props} />
)
const UL = (props: any) => (
<ul className="pl-8 text-base list-disc" {...props} />
)
const OL = (props: any) => (
<ol className="pl-8 text-base list-decimal" {...props} />
)
const MdComponents = {
h1: H1,
@@ -39,4 +43,4 @@ const MdComponents = {
ol: OL,
}
export default MdComponents;
export default MdComponents

View File

@@ -5,7 +5,6 @@ import { useSession } from 'next-auth/react'
import User from './user'
const pathNameLabelMap = {
'/login': 'Login',
'/admin': 'Buchungsübersicht',
@@ -21,7 +20,7 @@ function getPathNameMap(route: string) {
}
export default function Navigation() {
const { data, status } = useSession();
const { data, status } = useSession()
const router = useRouter()
const pathname = router.pathname

View File

@@ -1,11 +1,10 @@
import { useSession, signOut } from 'next-auth/react'
export default function User() {
const { data, status } = useSession();
const { data, status } = useSession()
if (status === 'loading' || !data?.user?.email) {
return null;
return null
}
return (

View File

@@ -34,9 +34,8 @@ type BookAction = {
payload?: any
}
export const BookContext: React.Context<BookProvider> = React.createContext<
BookProvider
>(null)
export const BookContext: React.Context<BookProvider> =
React.createContext<BookProvider>(null)
export const ACTIONS = {
SET_FORM_DATA: 'setFormData',

View File

@@ -22,8 +22,8 @@ export type Booking = {
purpose?: string
org?: string
destination?: string
days?: string[],
calendarEventId: string,
days?: string[]
calendarEventId: string
}
export type BookingDocument = Booking &
@@ -128,18 +128,20 @@ BookingSchema.pre('save', async function (next: () => void): Promise<void> {
if (!booking.calendarEventId) {
// create calendar event before saving to database
await createCalendarEvent(booking);
} else if ([BOOKING_STATUS.CANCELED, BOOKING_STATUS.REJECTED].includes(booking.status)) {
await createCalendarEvent(booking)
} else if (
[BOOKING_STATUS.CANCELED, BOOKING_STATUS.REJECTED].includes(booking.status)
) {
// event has been canceled or rejected, delete calendar event again to free up the slot
await deleteCalendarEvent(booking);
await deleteCalendarEvent(booking)
}
next();
});
next()
})
BookingSchema.static('findBookedDays', async function (
uuidsToIngore: string[] = []
): Promise<string[]> {
BookingSchema.static(
'findBookedDays',
async function (uuidsToIngore: string[] = []): Promise<string[]> {
const model = this as BookingModel
const now = nowInTz()
const bookedDays = await model
@@ -158,7 +160,11 @@ BookingSchema.static('findBookedDays', async function (
.map((b) => b.days)
.flat()
.sort()
})
}
)
export default (mongoose.models.Booking ||
mongoose.model<BookingDocument, BookingModel>('Booking', BookingSchema)) as BookingModel
mongoose.model<BookingDocument, BookingModel>(
'Booking',
BookingSchema
)) as BookingModel

View File

@@ -5,7 +5,7 @@ import { BOOKING_STATUS } from './enums'
let connectedPromise: Promise<mongoose.Mongoose>
export const MONGO_URI = process.env.MONGO_URI;
export const MONGO_URI = process.env.MONGO_URI
export const MONGODB_OPTIONS = {
useCreateIndex: true,
@@ -45,7 +45,9 @@ export async function getBookings({
return await BookingModel.find({
status: { $in: status },
startDate: { $gte: startDateGreaterThan },
}).sort({ startDate: -1 }).exec()
})
.sort({ startDate: -1 })
.exec()
}
export async function createBooking({

View File

@@ -39,7 +39,10 @@ Buchungs-Link: ${getBaseURL()}/bookings/${booking.uuid}
}
export function generateBookedCalendar(bookings: Booking[]): string {
const events = bookings.map((booking): {
const events = bookings.map(
(
booking
): {
productId: string
calName: string
start: [number, number, number]
@@ -67,7 +70,8 @@ Link: ${getBaseURL()}/admin/bookings/${booking.uuid}
booking.status === BOOKING_STATUS.CONFIRMED
? ('CONFIRMED' as EventStatus)
: ('TENTATIVE' as EventStatus),
}))
})
)
const { error, value } = createEvents(events)

View File

@@ -14,9 +14,8 @@ export type ServerSideRecentBooking = {
}
}
export const getServerSideRecentBookings = async (): Promise<
ServerSideRecentBooking
> => {
export const getServerSideRecentBookings =
async (): Promise<ServerSideRecentBooking> => {
const bookings = await getBookings({
startDateGreaterThan: startOfYear(nowInTz()).toISOString(),
})
@@ -30,7 +29,7 @@ export const getServerSideRecentBookings = async (): Promise<
bookings: bookingsJSON,
},
}
}
}
export const getServerSideBooking = async (
context: any

View File

@@ -1,46 +1,44 @@
import { google } from 'googleapis'
import { Booking } from '../db/booking'
import {google} from 'googleapis';
import { Booking } from '../db/booking';
const keyFile = process.env.GOOGLE_SERVICE_ACCOUNT_KEY_FILE;
const calendarId = process.env.GOOGLE_CALENDAR_ID;
const keyFile = process.env.GOOGLE_SERVICE_ACCOUNT_KEY_FILE
const calendarId = process.env.GOOGLE_CALENDAR_ID
const auth = new google.auth.GoogleAuth({
keyFile,
scopes: [
'https://www.googleapis.com/auth/calendar',
'https://www.googleapis.com/auth/calendar.readonly'
'https://www.googleapis.com/auth/calendar.readonly',
],
});
})
const calendar = google.calendar({
version: 'v3',
auth,
});
})
export async function getNewEvents() {
const { data } = await calendar.events.list({
calendarId,
timeMin: new Date().toISOString()}
);
timeMin: new Date().toISOString(),
})
return data.items;
return data.items
}
function getSummary(booking: Partial<Booking>) : string {
let summary = "";
function getSummary(booking: Partial<Booking>): string {
let summary = ''
if (booking.org) {
summary += `${booking.org} - `;
summary += `${booking.org} - `
}
summary += booking.name;
summary += booking.name
return summary;
return summary
}
export async function createCalendarEvent(booking : Booking) : Promise<Booking> {
export async function createCalendarEvent(booking: Booking): Promise<Booking> {
const response = await calendar.events.insert({
auth,
calendarId,
@@ -49,12 +47,12 @@ export async function createCalendarEvent(booking : Booking) : Promise<Booking>
// description,
start: { date: booking.startDate },
end: { date: booking.endDate },
}
});
},
})
booking.calendarEventId = response.data.id;
booking.calendarEventId = response.data.id
return booking;
return booking
}
export async function deleteCalendarEvent(booking: Booking) {
@@ -62,9 +60,9 @@ export async function deleteCalendarEvent(booking: Booking) {
auth,
calendarId,
eventId: booking.calendarEventId,
});
})
booking.calendarEventId = null;
booking.calendarEventId = null
}
//export async function patchCalendarEvent(booking: { calendarEventId: string } & Partial<Booking> ) : Promise<Booking> {
@@ -76,4 +74,3 @@ export async function deleteCalendarEvent(booking: Booking) {
//
// return booking;
//}

View File

@@ -1,6 +1,6 @@
import { useEffect } from 'react';
import { useEffect } from 'react'
import { useSession, signIn, SessionProvider } from "next-auth/react"
import { useSession, signIn, SessionProvider } from 'next-auth/react'
import '../styles/index.css'
function Auth({ children }) {
@@ -21,8 +21,10 @@ function Auth({ children }) {
return <div>Loading...</div>
}
export default function MyApp({ Component, pageProps: { session, ...pageProps } }) {
export default function MyApp({
Component,
pageProps: { session, ...pageProps },
}) {
return (
<div className="flex flex-col min-h-screen">
<SessionProvider session={session}>
@@ -37,4 +39,3 @@ export default function MyApp({ Component, pageProps: { session, ...pageProps }
</div>
)
}

View File

@@ -18,7 +18,7 @@ export const getServerSideProps = async (context) => {
...serverSideBookingProps.props,
milageMax,
},
};
}
}
const milageTarifOptions = Object.values(MILAGE_TARIFS).map((tarif) => {
@@ -144,8 +144,7 @@ function BookingBillPage({
<strong>Bucher:</strong> {booking.name}
</div>
<div>
<strong>Buchungsstatus:</strong>{' '}
{getBookingStatus(booking.status)}
<strong>Buchungsstatus:</strong> {getBookingStatus(booking.status)}
</div>
<div>
<Input
@@ -193,14 +192,13 @@ function BookingBillPage({
<div className="mb-3" key={`label${index}`}>
<button
className="ibtn btn-gray mr-3"
onClick={(event) =>
onRemoveAdditionalCost(event, index)
}
onClick={(event) => onRemoveAdditionalCost(event, index)}
title="Entfernen"
>
-
</button>
<label className="flabel inline">{`Kostenpunkt ${index + 1
<label className="flabel inline">{`Kostenpunkt ${
index + 1
}`}</label>
</div>
<div className="ml-10 mb-3" key={`input{index}`}>
@@ -263,6 +261,6 @@ function BookingBillPage({
)
}
BookingBillPage.auth = true;
BookingBillPage.auth = true
export default BookingBillPage;
export default BookingBillPage

View File

@@ -9,13 +9,9 @@ import { getBookingStatus, patchBooking } from '../../../../helpers/booking'
import { daysFormatFrontend } from '../../../../helpers/date'
import { BOOKING_STATUS } from '../../../../db/enums'
export const getServerSideProps = getServerSideBooking;
export const getServerSideProps = getServerSideBooking
function ShowBookingAdmin({
booking: bookingProp,
}: {
booking: Booking
}) {
function ShowBookingAdmin({ booking: bookingProp }: { booking: Booking }) {
const router = useRouter()
const [booking, setBooking] = useState(bookingProp)
const [storingBooking, setStoringBooking] = useState(false)
@@ -78,6 +74,6 @@ function ShowBookingAdmin({
)
}
ShowBookingAdmin.auth = true;
ShowBookingAdmin.auth = true
export default ShowBookingAdmin;
export default ShowBookingAdmin

View File

@@ -1,20 +1,20 @@
import React from 'react'
import Link from 'next/link'
import { useSession } from 'next-auth/react'
import Layout from '../../components/layout';
import Denied from '../../components/denied';
import Layout from '../../components/layout'
import Denied from '../../components/denied'
import { daysFormatFrontend } from '../../helpers/date'
import { getServerSideRecentBookings } from '../../lib/getServerSideProps'
export const getServerSideProps = getServerSideRecentBookings;
export const getServerSideProps = getServerSideRecentBookings
function AdminRecentBookings({ bookings }) {
const { data: session, status} = useSession();
const { data: session, status } = useSession()
if (typeof window !== 'undefined' && status === "loading") return null;
if (typeof window !== 'undefined' && status === 'loading') return null
if (!bookings) return null;
if (!bookings) return null
return (
<Layout>
@@ -71,4 +71,4 @@ function AdminRecentBookings({ bookings }) {
AdminRecentBookings.auth = true
export default AdminRecentBookings;
export default AdminRecentBookings

View File

@@ -1,20 +1,20 @@
import { NextApiRequest, NextApiResponse } from 'next'
import NextAuth from "next-auth"
import EmailProvider from "next-auth/providers/email"
import NextAuth from 'next-auth'
import EmailProvider from 'next-auth/providers/email'
import { MongoDBAdapter } from "@next-auth/mongodb-adapter"
import { MONGO_URI, MONGODB_OPTIONS } from "../../../db"
import { MongoClient } from "mongodb";
import { MongoDBAdapter } from '@next-auth/mongodb-adapter'
import { MONGO_URI, MONGODB_OPTIONS } from '../../../db'
import { MongoClient } from 'mongodb'
let client: MongoClient;
let client: MongoClient
async function getMongoClient() {
if (!client) {
client = new MongoClient(MONGO_URI, MONGODB_OPTIONS);
await client.connect();
client = new MongoClient(MONGO_URI, MONGODB_OPTIONS)
await client.connect()
}
return client;
return client
}
export default async function auth(req: NextApiRequest, res: NextApiResponse) {
@@ -24,17 +24,15 @@ export default async function auth(req: NextApiRequest, res: NextApiResponse) {
providers: [
EmailProvider({
server: {
host: "smtp.sendgrid.net",
host: 'smtp.sendgrid.net',
port: 587,
auth: {
user: "apikey",
user: 'apikey',
pass: process.env.SENDGRID_API_KEY,
},
},
from: process.env.FROM_EMAIL
from: process.env.FROM_EMAIL,
}),
],
})
}

View File

@@ -2,7 +2,6 @@ import { Bill } from '../../../../db/bill'
import { createBill, patchBill } from '../../../../db/index'
export default async function billHandler(req, res): Promise<void> {
const {
method,
query: { uuid: uuids },

View File

@@ -20,7 +20,9 @@ export default function ShowBookingStored({ booking }: { booking: Booking }) {
return (
<Layout>
<h3 className="thanks mb-3 mt-6 text-lg">Vielen Dank für die Buchungsanfrage</h3>
<h3 className="thanks mb-3 mt-6 text-lg">
Vielen Dank für die Buchungsanfrage
</h3>
<p className="mb-6">
Nach Prüfung bestätigen wir die Buchung zeitnah per E-Mail.
</p>
@@ -29,8 +31,8 @@ export default function ShowBookingStored({ booking }: { booking: Booking }) {
<Link href={`/bookings/${booking.uuid}`}>
<a className="link underline">Link</a>
</Link>{' '}
zur Buchung schicken wir Dir auch per E-Mail. Dort kann die Buchung
auch jederzeit storniert werden.
zur Buchung schicken wir Dir auch per E-Mail. Dort kann die Buchung auch
jederzeit storniert werden.
</p>
{!storedBookingData && !bookingDataStored && (
<div className="mt-6">
@@ -46,8 +48,7 @@ export default function ShowBookingStored({ booking }: { booking: Booking }) {
{bookingDataStored === true && (
<div className="mt-6">
<p className="info-message">
Ok, deine Buchungsdaten wurden für die nächste Buchung
gespeichert.
Ok, deine Buchungsdaten wurden für die nächste Buchung gespeichert.
</p>
</div>
)}

View File

@@ -10,7 +10,7 @@ import Layout from '../components/layout'
export default function TermsPage({ source }) {
return (
<Layout>
<MDXRemote {...source} components={{...mdComponents}} />
<MDXRemote {...source} components={{ ...mdComponents }} />
</Layout>
)
}

View File

@@ -4,7 +4,6 @@ import Layout from '../components/layout'
export default function Home() {
const hello = 'fooo'
return (
<Layout>
<div className="mt-6 sm:text-center">

View File

@@ -9,7 +9,7 @@ export default function TermsPage({ source }) {
return (
<Layout>
<div className="text-gray-700">
<MDXRemote {...source} components={{...mdComponents}}/>
<MDXRemote {...source} components={{ ...mdComponents }} />
</div>
</Layout>
)

View File

@@ -10,8 +10,8 @@ import Layout from '../components/layout'
export default function TermsPage({ source }) {
return (
<Layout>
<div className="text-gray-700" >
<MDXRemote {...source} components={{...mdComponents}} />
<div className="text-gray-700">
<MDXRemote {...source} components={{ ...mdComponents }} />
</div>
</Layout>
)

View File

@@ -1,8 +1,5 @@
{
"extends": [
"config:base",
":dependencyDashboard"
],
"extends": ["config:base", ":dependencyDashboard"],
"schedule": "every weekend",
"packageRules": [
{

View File

@@ -1,11 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
@@ -20,12 +16,6 @@
"jsx": "preserve",
"incremental": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}