move rest into pages

This commit is contained in:
Thomas Ruoff
2020-08-01 16:05:58 +02:00
parent 528f46a533
commit 793b499c76
9 changed files with 32 additions and 8 deletions

25
pages/helpers/date.js Normal file
View File

@@ -0,0 +1,25 @@
import moment from 'moment'
export function getDays({ startDate, endDate }) {
let currentDay = moment(startDate)
const days = [dateFormat(currentDay)]
if (!endDate) {
return days
}
const end = moment(endDate)
while (currentDay < end) {
currentDay = currentDay.add(1, 'day')
days.push(dateFormat(currentDay))
}
return days
}
export function dateFormat(date) {
if (!date) {
return null
}
return moment(date).format('YYYY-MM-DD')
}

17
pages/helpers/storage.js Normal file
View File

@@ -0,0 +1,17 @@
const FORM_DATA_KEY = 'pfadiBussleFormData'
function getStorage() {
return localStorage
}
export function storeFormData({ org, name, email, street, zip, city }) {
getStorage().setItem(
FORM_DATA_KEY,
JSON.stringify({ org, name, email, street, zip, city })
)
}
export function loadFormData() {
const dataAsString = getStorage().getItem(FORM_DATA_KEY)
return JSON.parse(dataAsString || '{}')
}