Refinements to date handling in booking form

This commit is contained in:
2023-11-28 21:03:39 -05:00
parent a3cdbbfbbd
commit aed0462e05
9 changed files with 274 additions and 165 deletions

95
src/stores/schedule.ts Normal file
View File

@@ -0,0 +1,95 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
import { Boat, useBoatStore } from './boat';
import { date } from 'quasar';
import { DateOptions } from 'quasar';
export interface Reservation {
user: string;
start: Date;
end: Date;
resource: Boat;
reservationDate: Date;
status?: string;
}
function getSampleData(): Reservation[] {
const sampleData = [
{
user: 'John Smith',
start: '12:00',
end: '14:00',
boat: 1,
status: 'confirmed',
},
{
user: 'Bob Barker',
start: '18:00',
end: '20:00',
boat: 1,
status: 'confirmed',
},
{
user: 'Peter Parker',
start: '8:00',
end: '10:00',
boat: 2,
status: 'tentative',
},
{
user: 'Vince McMahon',
start: '13:00',
end: '17:00',
boat: 2,
status: 'pending',
},
{
user: 'Heather Graham',
start: '06:00',
end: '09:00',
boat: 3,
status: 'confirmed',
},
{ user: 'Lawrence Fishburne', start: '18:00', end: '20:00', boat: 3 },
];
const boatStore = useBoatStore();
const now = new Date();
const splitTime = (x: string): string[] => {
return x.split(':');
};
const makeOpts = (x: string[]): DateOptions => {
return { hour: parseInt(x[0]), minute: parseInt(x[1]) };
};
return sampleData.map((entry): Reservation => {
const boat = <Boat>boatStore.boats.find((b) => b.id == entry.boat);
return {
user: entry.user,
start: date.adjustDate(now, makeOpts(splitTime(entry.start))),
end: date.adjustDate(now, makeOpts(splitTime(entry.end))),
resource: boat,
reservationDate: now,
status: entry.status,
};
});
}
export const useScheduleStore = defineStore('schedule', () => {
const reservations = ref<Reservation[]>(getSampleData());
const getBoatReservations = (
boat: number | string,
curDate: Date
): Reservation[] => {
console.log(reservations.value);
return reservations.value.filter((x) => {
return (
(x.start.getDate() == curDate.getDate() ||
x.end.getDate() == curDate.getDate()) &&
(typeof boat == 'number'
? x.resource.id == boat
: x.resource.name == boat)
);
});
};
return { reservations, getBoatReservations };
});