mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 23:17:12 +01:00
fix most type errors
still have a few things outstanding
This commit is contained in:
committed by
Thomas Ruoff
parent
c3d8c6f3e0
commit
90ac05a907
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import * as React from 'react'
|
||||||
|
|
||||||
export default function Footer() {
|
export default function Footer() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import * as React from 'react'
|
||||||
|
|
||||||
export default function Header() {
|
export default function Header() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import React, { useContext } from 'react'
|
import * as React from 'react'
|
||||||
|
import { useContext } from 'react'
|
||||||
import { WizardContext } from './context/wizardStore'
|
import { WizardContext } from './context/wizardStore'
|
||||||
import Required from './required'
|
import Required from './required'
|
||||||
|
|
||||||
export default function Contact() {
|
export default function Contact() {
|
||||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'state' does not exist on type '{}'.
|
|
||||||
const { state, onChangeEvent } = useContext(WizardContext)
|
const { state, onChangeEvent } = useContext(WizardContext)
|
||||||
|
|
||||||
const { name, email, street, zip, city } = state.formData
|
const { name, email, street, zip, city } = state.formData
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { useReducer, useEffect } from 'react'
|
import * as React from 'react'
|
||||||
|
import { useReducer, useEffect } from 'react'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
storeBookingData,
|
storeBookingData,
|
||||||
@@ -6,8 +7,52 @@ import {
|
|||||||
clearBookingData,
|
clearBookingData,
|
||||||
} from '../../../helpers/storage'
|
} from '../../../helpers/storage'
|
||||||
|
|
||||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 1 arguments, but got 0.
|
interface WizardFormData {
|
||||||
export const WizardContext = React.createContext()
|
startDate: string
|
||||||
|
endDate: string
|
||||||
|
purpose: string
|
||||||
|
org: string
|
||||||
|
destination: string
|
||||||
|
name: string
|
||||||
|
email: string
|
||||||
|
street: string
|
||||||
|
zip: string
|
||||||
|
city: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Booking {
|
||||||
|
uuid: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface WizardStoreState {
|
||||||
|
postData?: boolean
|
||||||
|
postDataError?: string
|
||||||
|
postDataSuccess?: boolean
|
||||||
|
formData: WizardFormData
|
||||||
|
formDataChanged: string[]
|
||||||
|
booking?: Booking
|
||||||
|
dataStored: boolean
|
||||||
|
dataStoredLoaded: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
interface WizardStore {
|
||||||
|
state: WizardStoreState
|
||||||
|
dispatch: React.Dispatch<WizardAction>
|
||||||
|
onChange: (data: object) => void
|
||||||
|
onChangeEvent: (event: React.ChangeEvent<React.ElementRef<'input'>>) => void
|
||||||
|
onSubmit: () => void
|
||||||
|
storeData: (value: boolean) => void
|
||||||
|
forgetData: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
interface WizardAction {
|
||||||
|
type: string
|
||||||
|
payload?: any
|
||||||
|
}
|
||||||
|
|
||||||
|
export const WizardContext: React.Context<WizardStore> = React.createContext<
|
||||||
|
WizardStore
|
||||||
|
>(null)
|
||||||
|
|
||||||
export const ACTIONS = {
|
export const ACTIONS = {
|
||||||
SET_FORM_DATA: 'setFormData',
|
SET_FORM_DATA: 'setFormData',
|
||||||
@@ -19,7 +64,7 @@ export const ACTIONS = {
|
|||||||
DATA_STORED_FORGOTTEN: 'dataStoredForgotten',
|
DATA_STORED_FORGOTTEN: 'dataStoredForgotten',
|
||||||
}
|
}
|
||||||
|
|
||||||
function reducer(state, action) {
|
function reducer(state: WizardStoreState, action: WizardAction) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ACTIONS.SET_FORM_DATA:
|
case ACTIONS.SET_FORM_DATA:
|
||||||
return {
|
return {
|
||||||
@@ -84,14 +129,7 @@ function reducer(state, action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function debugReducer(state, action) {
|
const initialState: WizardStoreState = {
|
||||||
console.debug('applying action', action)
|
|
||||||
const newState = reducer(state, action)
|
|
||||||
console.debug(newState)
|
|
||||||
return newState
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialState = {
|
|
||||||
postData: false,
|
postData: false,
|
||||||
postDataError: null,
|
postDataError: null,
|
||||||
postDataSuccess: null,
|
postDataSuccess: null,
|
||||||
@@ -108,9 +146,11 @@ const initialState = {
|
|||||||
city: '',
|
city: '',
|
||||||
},
|
},
|
||||||
formDataChanged: [],
|
formDataChanged: [],
|
||||||
|
dataStored: undefined,
|
||||||
|
dataStoredLoaded: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createBooking(formData) {
|
async function createBooking(formData: WizardFormData) {
|
||||||
const response = await fetch('/api/booking', {
|
const response = await fetch('/api/booking', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
@@ -126,7 +166,7 @@ async function createBooking(formData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function WizardStore({ children }) {
|
export default function WizardStore({ children }) {
|
||||||
const [state, dispatch] = useReducer(debugReducer, initialState)
|
const [state, dispatch] = useReducer(reducer, initialState)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const data = loadBookingData()
|
const data = loadBookingData()
|
||||||
@@ -135,7 +175,9 @@ export default function WizardStore({ children }) {
|
|||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const onChangeEvent = (event) => {
|
const onChangeEvent = (
|
||||||
|
event: React.ChangeEvent<React.ElementRef<'input'>>
|
||||||
|
) => {
|
||||||
const { name, value } = event.target
|
const { name, value } = event.target
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
@@ -144,7 +186,7 @@ export default function WizardStore({ children }) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const onChange = (data) => {
|
const onChange = (data: object) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.SET_FORM_DATA,
|
type: ACTIONS.SET_FORM_DATA,
|
||||||
payload: data,
|
payload: data,
|
||||||
@@ -163,7 +205,7 @@ export default function WizardStore({ children }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const storeData = (value) => {
|
const storeData = (value: boolean) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
storeBookingData(state.booking)
|
storeBookingData(state.booking)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,27 @@
|
|||||||
import React, { useContext, useState, useRef, useEffect } from 'react'
|
import * as React from 'react'
|
||||||
|
import { useEffect, useContext, useState, useRef } from 'react'
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
|
|
||||||
import { WizardContext } from './context/wizardStore'
|
import { WizardContext } from './context/wizardStore'
|
||||||
|
|
||||||
import { DateUtils } from 'react-day-picker'
|
import { DateUtils, RangeModifier } from 'react-day-picker'
|
||||||
import DayPickerInput from 'react-day-picker/DayPickerInput'
|
import DayPickerInput from 'react-day-picker/DayPickerInput'
|
||||||
|
|
||||||
import Required from './required'
|
import Required from './required'
|
||||||
import { dateFormatBackend } from '../../helpers/date'
|
import { dateFormatBackend } from '../../helpers/date'
|
||||||
import { getNextSmaller, getNextBigger } from '../../helpers/array'
|
import { getNextSmaller, getNextBigger } from '../../helpers/array'
|
||||||
|
|
||||||
import MomentLocaleUtils, {
|
import MomentLocaleUtils from 'react-day-picker/moment'
|
||||||
// @ts-expect-error ts-migrate(2614) FIXME: Module '"../../node_modules/react-day-picker/types... Remove this comment to see the full error message
|
|
||||||
formatDate,
|
|
||||||
// @ts-expect-error ts-migrate(2614) FIXME: Module '"../../node_modules/react-day-picker/types... Remove this comment to see the full error message
|
|
||||||
parseDate,
|
|
||||||
} from 'react-day-picker/moment'
|
|
||||||
import 'moment/locale/de'
|
import 'moment/locale/de'
|
||||||
|
|
||||||
const fetcher = (path) => fetch(path).then((r) => r.json())
|
const fetcher = (path: string) => fetch(path).then((r) => r.json())
|
||||||
|
|
||||||
export default function DateSelect() {
|
export default function DateSelect() {
|
||||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'state' does not exist on type '{}'.
|
const { onChange } = useContext(WizardContext)
|
||||||
const { state, onChange } = useContext(WizardContext)
|
const [range, setRange] = useState<RangeModifier>({
|
||||||
const [range, setRange] = useState({
|
from: undefined, //state.startDate && new Date(state.startDate),
|
||||||
form: state.startDate && new Date(state.startDate),
|
to: undefined, //state.endDate && new Date(state.endDate),
|
||||||
to: state.endDate && new Date(state.endDate),
|
|
||||||
})
|
})
|
||||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'from' does not exist on type '{ form: Da... Remove this comment to see the full error message
|
|
||||||
const { from, to } = range
|
const { from, to } = range
|
||||||
const { data: daysBooked, error: fetchBookedOnError } = useSWR(
|
const { data: daysBooked, error: fetchBookedOnError } = useSWR(
|
||||||
'/api/daysbooked',
|
'/api/daysbooked',
|
||||||
@@ -39,14 +33,14 @@ export default function DateSelect() {
|
|||||||
)
|
)
|
||||||
const nextBookedDay = getNextBigger(daysBooked, dateFormatBackend(from || to))
|
const nextBookedDay = getNextBigger(daysBooked, dateFormatBackend(from || to))
|
||||||
|
|
||||||
const fromRef = useRef()
|
const fromRef = useRef<DayPickerInput>()
|
||||||
const toRef = useRef()
|
const toRef = useRef<DayPickerInput>()
|
||||||
|
|
||||||
function dayBooked(day) {
|
function dayBooked(day: Date) {
|
||||||
return daysBooked && daysBooked.includes(dateFormatBackend(day))
|
return daysBooked && daysBooked.includes(dateFormatBackend(day))
|
||||||
}
|
}
|
||||||
|
|
||||||
function dayDisabled(day) {
|
function dayDisabled(day: Date) {
|
||||||
return (
|
return (
|
||||||
DateUtils.isPastDay(day) ||
|
DateUtils.isPastDay(day) ||
|
||||||
dayBooked(day) ||
|
dayBooked(day) ||
|
||||||
@@ -57,7 +51,6 @@ export default function DateSelect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// @ts-expect-error ts-migrate(2532) FIXME: Object is possibly 'undefined'.
|
|
||||||
toRef.current?.getInput().focus()
|
toRef.current?.getInput().focus()
|
||||||
}, [from])
|
}, [from])
|
||||||
|
|
||||||
@@ -92,8 +85,8 @@ export default function DateSelect() {
|
|||||||
inputProps={{ className: 'input-text' }}
|
inputProps={{ className: 'input-text' }}
|
||||||
value={from}
|
value={from}
|
||||||
placeholder="Von"
|
placeholder="Von"
|
||||||
formatDate={formatDate}
|
formatDate={MomentLocaleUtils.formatDate}
|
||||||
parseDate={parseDate}
|
parseDate={MomentLocaleUtils.parseDate}
|
||||||
dayPickerProps={{
|
dayPickerProps={{
|
||||||
locale: 'de',
|
locale: 'de',
|
||||||
localeUtils: MomentLocaleUtils,
|
localeUtils: MomentLocaleUtils,
|
||||||
@@ -102,7 +95,6 @@ export default function DateSelect() {
|
|||||||
modifiers,
|
modifiers,
|
||||||
numberOfMonths: 1,
|
numberOfMonths: 1,
|
||||||
}}
|
}}
|
||||||
// @ts-expect-error ts-migrate(2345) FIXME: Object literal may only specify known properties, ... Remove this comment to see the full error message
|
|
||||||
onDayChange={(from) => setRange({ ...range, from })}
|
onDayChange={(from) => setRange({ ...range, from })}
|
||||||
/>
|
/>
|
||||||
{' - '}
|
{' - '}
|
||||||
@@ -111,8 +103,8 @@ export default function DateSelect() {
|
|||||||
inputProps={{ className: 'input-text', disabled: !from }}
|
inputProps={{ className: 'input-text', disabled: !from }}
|
||||||
value={to}
|
value={to}
|
||||||
placeholder="Bis"
|
placeholder="Bis"
|
||||||
formatDate={formatDate}
|
formatDate={MomentLocaleUtils.formatDate}
|
||||||
parseDate={parseDate}
|
parseDate={MomentLocaleUtils.parseDate}
|
||||||
dayPickerProps={{
|
dayPickerProps={{
|
||||||
locale: 'de',
|
locale: 'de',
|
||||||
localeUtils: MomentLocaleUtils,
|
localeUtils: MomentLocaleUtils,
|
||||||
@@ -126,8 +118,10 @@ export default function DateSelect() {
|
|||||||
}}
|
}}
|
||||||
onDayChange={(to) => setRange({ ...range, to })}
|
onDayChange={(to) => setRange({ ...range, to })}
|
||||||
/>
|
/>
|
||||||
{/* @ts-expect-error ts-migrate(2345) FIXME: Type '{}' provides no match for the signature '(pr... Remove this comment to see the full error message */}
|
<button
|
||||||
<button onClick={() => setRange({})} className="ibtn">
|
onClick={() => setRange({ from: undefined, to: undefined })}
|
||||||
|
className="ibtn"
|
||||||
|
>
|
||||||
<svg className="w-full" viewBox="0 0 352 512">
|
<svg className="w-full" viewBox="0 0 352 512">
|
||||||
<path
|
<path
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { useContext } from 'react'
|
import * as React from 'react'
|
||||||
|
import { useContext } from 'react'
|
||||||
|
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
|
||||||
@@ -9,7 +10,6 @@ import Reason from './reason'
|
|||||||
import Contact from './contact'
|
import Contact from './contact'
|
||||||
|
|
||||||
function WizardInternal() {
|
function WizardInternal() {
|
||||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'onSubmit' does not exist on type '{}'.
|
|
||||||
const { onSubmit, state, forgetData, storeData } = useContext(WizardContext)
|
const { onSubmit, state, forgetData, storeData } = useContext(WizardContext)
|
||||||
const {
|
const {
|
||||||
postData,
|
postData,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import React, { useContext } from 'react'
|
import * as React from 'react'
|
||||||
|
import { useContext } from 'react'
|
||||||
import { WizardContext } from './context/wizardStore'
|
import { WizardContext } from './context/wizardStore'
|
||||||
import Required from './required'
|
import Required from './required'
|
||||||
|
|
||||||
export default function Contact() {
|
export default function Contact() {
|
||||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'state' does not exist on type '{}'.
|
|
||||||
const { state, onChangeEvent } = useContext(WizardContext)
|
const { state, onChangeEvent } = useContext(WizardContext)
|
||||||
|
|
||||||
const { formDataChanged } = state
|
const { formDataChanged } = state
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import * as React from 'react'
|
||||||
|
|
||||||
const Required = () => <span>*</span>
|
const Required = () => <span>*</span>
|
||||||
export default Required
|
export default Required
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import Booker from './booker'
|
|||||||
import Booking from './booking'
|
import Booking from './booking'
|
||||||
import { BOOKING_STATUS } from './bookingStatus'
|
import { BOOKING_STATUS } from './bookingStatus'
|
||||||
|
|
||||||
let connectedPromise
|
let connectedPromise: Promise<typeof mongoose>
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
if (connectedPromise) {
|
if (connectedPromise) {
|
||||||
@@ -39,13 +39,13 @@ export async function getBookedDays() {
|
|||||||
.sort()
|
.sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getBookingByUUID(uuid) {
|
export async function getBookingByUUID(uuid: string) {
|
||||||
await connect()
|
await connect()
|
||||||
const booking = await Booking.findOne({ uuid })
|
const booking = await Booking.findOne({ uuid })
|
||||||
return booking.populate('booker').execPopulate()
|
return booking.populate('booker').execPopulate()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getBookingByUUIDAsJSON(uuid) {
|
export async function getBookingByUUIDAsJSON(uuid: string) {
|
||||||
const booking = await getBookingByUUID(uuid)
|
const booking = await getBookingByUUID(uuid)
|
||||||
return booking.toJSON()
|
return booking.toJSON()
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ export async function createBooking({
|
|||||||
const booking = new Booking({ startDate, endDate, purpose, org, destination })
|
const booking = new Booking({ startDate, endDate, purpose, org, destination })
|
||||||
const bookedDays = await getBookedDays()
|
const bookedDays = await getBookedDays()
|
||||||
|
|
||||||
if (booking.days.some((day) => bookedDays.includes(day))) {
|
if (booking.days.some((day: string) => bookedDays.includes(day))) {
|
||||||
throw new mongoose.Error.ValidationError(booking)
|
throw new mongoose.Error.ValidationError(booking)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
import { getNextSmaller, getNextBigger } from './array'
|
import { getNextSmaller, getNextBigger } from './array'
|
||||||
|
|
||||||
// @ts-expect-error ts-migrate(2582) FIXME: Cannot find name 'test'. Do you need to install ty... Remove this comment to see the full error message
|
|
||||||
test('getPreviousInOrder', () => {
|
test('getPreviousInOrder', () => {
|
||||||
const result = getNextSmaller([3, 1, 2, 0, 8, 9, 10], 5)
|
const result = getNextSmaller([3, 1, 2, 0, 8, 9, 10], 5)
|
||||||
|
|
||||||
// @ts-expect-error ts-migrate(2304) FIXME: Cannot find name 'expect'.
|
|
||||||
expect(result).toEqual(3)
|
expect(result).toEqual(3)
|
||||||
})
|
})
|
||||||
|
|
||||||
// @ts-expect-error ts-migrate(2582) FIXME: Cannot find name 'test'. Do you need to install ty... Remove this comment to see the full error message
|
|
||||||
test('getNextInOrder', () => {
|
test('getNextInOrder', () => {
|
||||||
const result = getNextBigger([7, 8, 9, 3, 1, 2], 4)
|
const result = getNextBigger([7, 8, 9, 3, 1, 2], 4)
|
||||||
|
|
||||||
// @ts-expect-error ts-migrate(2304) FIXME: Cannot find name 'expect'.
|
|
||||||
expect(result).toEqual(7)
|
expect(result).toEqual(7)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export function getNextSmaller(array, pivot) {
|
export function getNextSmaller<T>(array: T[], pivot: T) {
|
||||||
if (!array || !Array.isArray(array) || !array.length) {
|
if (!array || !Array.isArray(array) || !array.length) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ export function getNextSmaller(array, pivot) {
|
|||||||
.find((item) => item < pivot)
|
.find((item) => item < pivot)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNextBigger(array, pivot) {
|
export function getNextBigger<T>(array: T[], pivot: T) {
|
||||||
if (!array || !Array.isArray(array) || !array.length) {
|
if (!array || !Array.isArray(array) || !array.length) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,13 @@ import moment from 'moment'
|
|||||||
const FRONTEND_FORMAT = 'DD.MM.YYYY'
|
const FRONTEND_FORMAT = 'DD.MM.YYYY'
|
||||||
const BACKEND_FORMAT = 'YYYY-MM-DD'
|
const BACKEND_FORMAT = 'YYYY-MM-DD'
|
||||||
|
|
||||||
export function getDays({ startDate, endDate }) {
|
export function getDays({
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
}: {
|
||||||
|
startDate: moment.MomentInput
|
||||||
|
endDate: moment.MomentInput
|
||||||
|
}) {
|
||||||
let currentDay = moment(startDate)
|
let currentDay = moment(startDate)
|
||||||
const days = [dateFormatBackend(currentDay)]
|
const days = [dateFormatBackend(currentDay)]
|
||||||
|
|
||||||
@@ -20,31 +26,30 @@ export function getDays({ startDate, endDate }) {
|
|||||||
return days
|
return days
|
||||||
}
|
}
|
||||||
|
|
||||||
function dateFormat(date, format) {
|
function dateFormat(date: moment.MomentInput, format: string) {
|
||||||
if (!date) {
|
if (!date) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return moment(date).format(format)
|
return moment(date).format(format)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dateFormatBackend(date) {
|
export function dateFormatBackend(date: moment.MomentInput) {
|
||||||
return dateFormat(date, BACKEND_FORMAT)
|
return dateFormat(date, BACKEND_FORMAT)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dateFormatFrontend(date) {
|
export function dateFormatFrontend(date: moment.MomentInput) {
|
||||||
return dateFormat(date, FRONTEND_FORMAT)
|
return dateFormat(date, FRONTEND_FORMAT)
|
||||||
}
|
}
|
||||||
|
|
||||||
function dateParse(string, format) {
|
function dateParse(input: string, format: string) {
|
||||||
const date = moment(string, format)
|
const date = moment(input, format)
|
||||||
if (date.isValid()) {
|
if (date.isValid()) {
|
||||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'getDate' does not exist on type 'Moment'... Remove this comment to see the full error message
|
return date.toDate()
|
||||||
return date.getDate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dateParseFrontend(string) {
|
export function dateParseFrontend(input: string) {
|
||||||
return dateParse(string, FRONTEND_FORMAT)
|
return dateParse(input, FRONTEND_FORMAT)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ if (!SENDGRID_API_KEY) {
|
|||||||
throw new Error('NO SENDGRID_API_KEY set!')
|
throw new Error('NO SENDGRID_API_KEY set!')
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendMail(data) {
|
async function sendMail(data: object) {
|
||||||
const fetchOptions = {
|
const fetchOptions = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -24,13 +24,11 @@ async function sendMail(data) {
|
|||||||
const response = await fetch(SENDGRID_URL, fetchOptions)
|
const response = await fetch(SENDGRID_URL, fetchOptions)
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(
|
throw new Error(`Unable to send mail`)
|
||||||
`Failed to send booking ${data._id} to booking admin with status ${response.status}: ${response.statusText}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getReceivedBookingText(booking) {
|
function getReceivedBookingText(booking: { uuid: string }) {
|
||||||
return `Hallo lieber Admin,
|
return `Hallo lieber Admin,
|
||||||
|
|
||||||
es ging folgende Buchung ein: https://${process.env.VERCEL_URL}/booking/${booking.uuid}
|
es ging folgende Buchung ein: https://${process.env.VERCEL_URL}/booking/${booking.uuid}
|
||||||
@@ -38,7 +36,7 @@ function getReceivedBookingText(booking) {
|
|||||||
MfG`
|
MfG`
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendReceivedBookingMail(booking) {
|
export async function sendReceivedBookingMail(booking: { uuid: string }) {
|
||||||
const data = {
|
const data = {
|
||||||
personalizations: [
|
personalizations: [
|
||||||
{
|
{
|
||||||
@@ -46,9 +44,13 @@ export async function sendReceivedBookingMail(booking) {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
from: { email: FROM_EMAIL },
|
from: { email: FROM_EMAIL },
|
||||||
subject: 'Pfadi Bussle - Buchung eingegangen!',
|
subject: `Pfadi Bussle - Buchung ${booking.uuid} eingegangen!`,
|
||||||
content: [{ type: 'text/plain', value: getReceivedBookingText(booking) }],
|
content: [{ type: 'text/plain', value: getReceivedBookingText(booking) }],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await sendMail(data)
|
await sendMail(data)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Failed in sendReceivedBookingMail for ${booking.uuid}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
154
package-lock.json
generated
154
package-lock.json
generated
@@ -2129,6 +2129,14 @@
|
|||||||
"@babel/types": "^7.3.0"
|
"@babel/types": "^7.3.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/bson": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/bson/-/bson-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-+uWmsejEHfmSjyyM/LkrP0orfE2m5Mx9Xel4tXNeqi1ldK5XMQcDsFkBmLDtuyKUbxj2jGDo0H240fbCRJZo7Q==",
|
||||||
|
"requires": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/color-name": {
|
"@types/color-name": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
|
||||||
@@ -2167,11 +2175,148 @@
|
|||||||
"@types/istanbul-lib-report": "*"
|
"@types/istanbul-lib-report": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/jest": {
|
||||||
|
"version": "26.0.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.10.tgz",
|
||||||
|
"integrity": "sha512-i2m0oyh8w/Lum7wWK/YOZJakYF8Mx08UaKA1CtbmFeDquVhAEdA7znacsVSf2hJ1OQ/OfVMGN90pw/AtzF8s/Q==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"jest-diff": "^25.2.1",
|
||||||
|
"pretty-format": "^25.2.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@jest/types": {
|
||||||
|
"version": "25.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jest/types/-/types-25.5.0.tgz",
|
||||||
|
"integrity": "sha512-OXD0RgQ86Tu3MazKo8bnrkDRaDXXMGUqd+kTtLtK1Zb7CRzQcaSRPPPV37SvYTdevXEBVxe0HXylEjs8ibkmCw==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/istanbul-lib-coverage": "^2.0.0",
|
||||||
|
"@types/istanbul-reports": "^1.1.1",
|
||||||
|
"@types/yargs": "^15.0.0",
|
||||||
|
"chalk": "^3.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@types/istanbul-reports": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-P/W9yOX/3oPZSpaYOCQzGqgCQRXn0FFO/V8bWrCQs+wLmvVVxk6CRBXALEvNs9OHIatlnlFokfhuDo2ug01ciw==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/istanbul-lib-coverage": "*",
|
||||||
|
"@types/istanbul-lib-report": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ansi-styles": {
|
||||||
|
"version": "4.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz",
|
||||||
|
"integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/color-name": "^1.1.1",
|
||||||
|
"color-convert": "^2.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"chalk": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"ansi-styles": "^4.1.0",
|
||||||
|
"supports-color": "^7.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"color-convert": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"color-name": "~1.1.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"color-name": {
|
||||||
|
"version": "1.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||||
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"diff-sequences": {
|
||||||
|
"version": "25.2.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-25.2.6.tgz",
|
||||||
|
"integrity": "sha512-Hq8o7+6GaZeoFjtpgvRBUknSXNeJiCx7V9Fr94ZMljNiCr9n9L8H8aJqgWOQiDDGdyn29fRNcDdRVJ5fdyihfg==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"has-flag": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"jest-diff": {
|
||||||
|
"version": "25.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-25.5.0.tgz",
|
||||||
|
"integrity": "sha512-z1kygetuPiREYdNIumRpAHY6RXiGmp70YHptjdaxTWGmA085W3iCnXNx0DhflK3vwrKmrRWyY1wUpkPMVxMK7A==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"chalk": "^3.0.0",
|
||||||
|
"diff-sequences": "^25.2.6",
|
||||||
|
"jest-get-type": "^25.2.6",
|
||||||
|
"pretty-format": "^25.5.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"jest-get-type": {
|
||||||
|
"version": "25.2.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-25.2.6.tgz",
|
||||||
|
"integrity": "sha512-DxjtyzOHjObRM+sM1knti6or+eOgcGU4xVSb2HNP1TqO4ahsT+rqZg+nyqHWJSvWgKC5cG3QjGFBqxLghiF/Ig==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"pretty-format": {
|
||||||
|
"version": "25.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-25.5.0.tgz",
|
||||||
|
"integrity": "sha512-kbo/kq2LQ/A/is0PQwsEHM7Ca6//bGPPvU6UnsdDRSKTWxT/ru/xb88v4BJf6a69H+uTytOEsTusT9ksd/1iWQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@jest/types": "^25.5.0",
|
||||||
|
"ansi-regex": "^5.0.0",
|
||||||
|
"ansi-styles": "^4.0.0",
|
||||||
|
"react-is": "^16.12.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"supports-color": {
|
||||||
|
"version": "7.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz",
|
||||||
|
"integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"has-flag": "^4.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@types/mongodb": {
|
||||||
|
"version": "3.5.26",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-3.5.26.tgz",
|
||||||
|
"integrity": "sha512-p0X2VJgIBNHfNBdZdzzG8eQ/3bf6mQoXDT0UhVyVEdSzXEa1+2pFcwGvEZp72sjztyBwfRKlgrXMjCVavLcuGg==",
|
||||||
|
"requires": {
|
||||||
|
"@types/bson": "*",
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@types/mongoose": {
|
||||||
|
"version": "5.7.36",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/mongoose/-/mongoose-5.7.36.tgz",
|
||||||
|
"integrity": "sha512-ggFXgvkHgCNlT35B9d/heDYfSqOSwTmQjkRoR32sObGV5Xjd0N0WWuYlLzqeCg94j4hYN/OZxZ1VNNLltX/IVQ==",
|
||||||
|
"requires": {
|
||||||
|
"@types/mongodb": "*",
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "14.0.27",
|
"version": "14.0.27",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.27.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.27.tgz",
|
||||||
"integrity": "sha512-kVrqXhbclHNHGu9ztnAwSncIgJv/FaxmzXJvGXNdcCpV1b8u1/Mi6z6m0vwy0LzKeXFTPLH0NzwmoJ3fNCIq0g==",
|
"integrity": "sha512-kVrqXhbclHNHGu9ztnAwSncIgJv/FaxmzXJvGXNdcCpV1b8u1/Mi6z6m0vwy0LzKeXFTPLH0NzwmoJ3fNCIq0g=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"@types/normalize-package-data": {
|
"@types/normalize-package-data": {
|
||||||
"version": "2.4.0",
|
"version": "2.4.0",
|
||||||
@@ -2220,6 +2365,11 @@
|
|||||||
"integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==",
|
"integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@types/uuid": {
|
||||||
|
"version": "8.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.0.tgz",
|
||||||
|
"integrity": "sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ=="
|
||||||
|
},
|
||||||
"@types/yargs": {
|
"@types/yargs": {
|
||||||
"version": "15.0.5",
|
"version": "15.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.5.tgz",
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
"test:ci": "jest"
|
"test:ci": "jest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/mongoose": "^5.7.36",
|
||||||
|
"@types/uuid": "^8.3.0",
|
||||||
"moment": "^2.27.0",
|
"moment": "^2.27.0",
|
||||||
"mongoose": "^5.9.25",
|
"mongoose": "^5.9.25",
|
||||||
"next": "^9.5.2",
|
"next": "^9.5.2",
|
||||||
@@ -21,6 +23,7 @@
|
|||||||
"uuid": "^8.3.0"
|
"uuid": "^8.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/jest": "^26.0.10",
|
||||||
"@types/react": "^16.9.48",
|
"@types/react": "^16.9.48",
|
||||||
"babel-jest": "^26.3.0",
|
"babel-jest": "^26.3.0",
|
||||||
"eslint": "^7.6.0",
|
"eslint": "^7.6.0",
|
||||||
|
|||||||
@@ -1,29 +1,20 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"lib": [
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
"dom",
|
|
||||||
"dom.iterable",
|
|
||||||
"esnext"
|
|
||||||
],
|
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"strict": false,
|
"strict": false,
|
||||||
"forceConsistentCasingInFileNames": false,
|
"forceConsistentCasingInFileNames": false,
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"jsx": "preserve"
|
"jsx": "preserve"
|
||||||
},
|
},
|
||||||
"include": [
|
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
|
||||||
"next-env.d.ts",
|
"exclude": ["node_modules"]
|
||||||
"**/*.ts",
|
|
||||||
"**/*.tsx"
|
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"node_modules"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user