diff --git a/helpers/date.test.ts b/helpers/date.test.ts new file mode 100644 index 0000000..85af6ea --- /dev/null +++ b/helpers/date.test.ts @@ -0,0 +1,12 @@ +import { daysFormatFrontend } from './date' + +test('daysFormatFrontend', () => { + expect(daysFormatFrontend([])).toEqual('') + expect(daysFormatFrontend(['2020-01-01'])).toEqual('01.01.2020') + expect(daysFormatFrontend(['2020-01-01', '2020-01-02'])).toEqual( + '01.01.2020-02.01.2020' + ) + expect( + daysFormatFrontend(['2020-01-01', '2020-01-02', '2020-01-05']) + ).toEqual('01.01.2020-05.01.2020') +}) diff --git a/helpers/date.ts b/helpers/date.ts index 8169806..24f0d44 100644 --- a/helpers/date.ts +++ b/helpers/date.ts @@ -3,6 +3,20 @@ import { parse, format, addDays } from 'date-fns' const FRONTEND_FORMAT = 'dd.MM.yyyy' const BACKEND_FORMAT = 'yyyy-MM-dd' +export function daysFormatFrontend(days: string[]) { + if (days.length === 0) { + return '' + } + + if (days.length === 1) { + return dateFormatFrontend(new Date(days[0])) + } + + return [days[0], days.slice(-1)] + .map((day: string) => dateFormatFrontend(new Date(day))) + .join('-') +} + export function getDays({ startDate, endDate, diff --git a/helpers/mail.ts b/helpers/mail.ts index 481354e..0b6ced8 100644 --- a/helpers/mail.ts +++ b/helpers/mail.ts @@ -1,5 +1,6 @@ import { Booking } from '../db/booking' import { getBaseURL } from '../helpers/url' +import { daysFormatFrontend } from './date' const SENDGRID_API_KEY = process.env.SENDGRID_API_KEY const ADMIN_EMAIL = process.env.ADMIN_EMAIL @@ -31,7 +32,9 @@ Tel. 0151/212 253 62 function getReceivedBookingBookerText(booking: Booking) { return `Hallo liebe/r ${booking.booker.name}, -Vielen Dank für Deine Buchung. Nach Prüfung bestätigen wir die Buchung bald per E-Mail! +Vielen Dank für Deine Buchungsanfrage zum ${daysFormatFrontend(booking.days)}! + +Nach Prüfung bestätigen wir die Buchung bald per E-Mail! Du kannst sie jederzeit unter @@ -46,7 +49,9 @@ ${footer} function getBookingConfirmedText(booking: Booking) { return `Hallo liebe/r ${booking.booker.name}, -deine Buchung ist bestätigt! +deine Buchunganfrage zum ${daysFormatFrontend( + booking.days + )} bestätigen wir gerne! Bitte melde dich spätestens 7 Tage vor dem Buchungstermin per E-Mail oder Telefon um eine Schlüsselübergabe zu vereinbaren. @@ -60,7 +65,9 @@ ${footer} function getBookingRejectedText(booking: Booking) { return `Hallo liebe/r ${booking.booker.name}, -es tut uns leid aber deine Buchung konnte leider nicht bestätigt werden. +es tut uns leid aber deine Buchungsanfrage zum ${daysFormatFrontend( + booking.days + )} konnten wir leider nicht bestätigen. Willst du das Bussle an einem anderen Termin buchen? Dann stelle bitte nochmal eine Buchungsanfrage auf ${getBaseURL()}.