-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send notifications to KM when new booking requests are made + new boo…
…king review page (#527) * Initial concept for sending booking notifications to KM * Removed unnecessary type * Improved notification message * Fixed incorrect time when editing booking requests * Added new page for accepting/denying booking requests and linked notifications there * Refactored identical code for accepting/rejecting booking requests to sharedActions.ts * Refactored code for handling accept/reject actions into one function * Refactored code for getting weekly booking requests * Changed StatusComponent.svelte to support two different modes * Formatting fix and added link to inspect page from /booking/admin * Fixed incorrect date format on /booking/admin * Refactored identical code for getting bookingRequest and form into sharedUtils.ts * Removed old, unnecessary code * Fixed invalid bookingRequest id error * Removed unused parameter * Removed old testing code * Added error handling for KM notifications * Removed unused variable * Moved sharedUtils.ts * Edited import * Added TODO * Changed the booking inspector to match the updated booking editor * Update to booking inspector: * Added review mode and functionality to BookingEditor.svelte * Removed old BookingInspector.svelte * Renamed instances of "inspect" to "review" * Added translations message for admin/[id] page title * Moved StatusComponent.svelte to reflect its new usage * Changed notification bookable names to nameEn * Fixed the calendar on review booking page so it does not display *all* bookings * General refactoring
- Loading branch information
Showing
12 changed files
with
300 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,15 @@ | ||
import apiNames from "$lib/utils/apiNames"; | ||
import { authorize } from "$lib/utils/authorization"; | ||
import sendNotification from "$lib/utils/notifications"; | ||
import { NotificationType } from "$lib/utils/notifications/types"; | ||
import dayjs from "dayjs"; | ||
import type { Actions, PageServerLoad } from "./$types"; | ||
import type { PageServerLoad } from "./$types"; | ||
import { actions, getUpcomingBookingRequests } from "../utils"; | ||
|
||
export const load: PageServerLoad = async ({ locals }) => { | ||
const { prisma, user } = locals; | ||
authorize(apiNames.BOOKINGS.UPDATE, user); | ||
|
||
const bookingRequests = await prisma.bookingRequest.findMany({ | ||
where: { | ||
start: { | ||
gte: dayjs().subtract(1, "week").toDate(), | ||
}, | ||
}, | ||
orderBy: [{ start: "asc" }, { end: "asc" }, { status: "asc" }], | ||
include: { | ||
bookables: true, | ||
booker: true, | ||
}, | ||
}); | ||
const bookingRequests = await getUpcomingBookingRequests(prisma); | ||
|
||
return { bookingRequests }; | ||
}; | ||
|
||
export const actions: Actions = { | ||
accept: async (event) => { | ||
const { request, locals } = event; | ||
const { prisma, user } = locals; | ||
const formData = await request.formData(); | ||
const id = formData.get("id"); | ||
if (id && typeof id === "string") { | ||
await prisma.bookingRequest.update({ | ||
where: { id }, | ||
data: { | ||
status: "ACCEPTED", | ||
}, | ||
}); | ||
const request = await prisma.bookingRequest.findFirst({ | ||
where: { | ||
id, | ||
}, | ||
select: { | ||
bookerId: true, | ||
event: true, | ||
}, | ||
}); | ||
if (request && request.bookerId != null && user && user.memberId) { | ||
sendNotification({ | ||
title: "Booking request accepted", | ||
message: `Your booking request for ${request.event} has been accepted`, | ||
type: NotificationType.BOOKING_REQUEST, | ||
link: "/booking", | ||
memberIds: [request.bookerId], | ||
fromMemberId: user.memberId, | ||
}); | ||
} | ||
} | ||
}, | ||
reject: async (event) => { | ||
const { request, locals } = event; | ||
const { prisma, user } = locals; | ||
const formData = await request.formData(); | ||
const id = formData.get("id"); | ||
if (id && typeof id === "string") { | ||
await prisma.bookingRequest.update({ | ||
where: { id }, | ||
data: { | ||
status: "DENIED", | ||
}, | ||
}); | ||
const request = await prisma.bookingRequest.findFirst({ | ||
where: { | ||
id, | ||
}, | ||
select: { | ||
bookerId: true, | ||
event: true, | ||
}, | ||
}); | ||
if (request && request.bookerId != null && user && user.memberId) { | ||
sendNotification({ | ||
title: "Booking request denied", | ||
message: `Your booking request for ${request.event} has been denied`, | ||
type: NotificationType.BOOKING_REQUEST, | ||
link: "/booking", | ||
memberIds: [request.bookerId], | ||
fromMemberId: user.memberId, | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
export { actions }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { authorize } from "$lib/utils/authorization"; | ||
import apiNames from "$lib/utils/apiNames"; | ||
import dayjs from "dayjs"; | ||
import { | ||
actions, | ||
getUpcomingBookingRequests, | ||
getBookingRequestOrThrow, | ||
getSuperValidatedForm, | ||
} from "../../utils"; | ||
|
||
export const load = async ({ locals, params }) => { | ||
const { prisma, user } = locals; | ||
authorize(apiNames.BOOKINGS.UPDATE, user); | ||
const bookables = await prisma.bookable.findMany(); | ||
|
||
const allBookingRequests = await prisma.bookingRequest.findMany({ | ||
where: { | ||
start: { | ||
gte: dayjs().subtract(1, "week").toDate(), | ||
}, | ||
}, | ||
orderBy: [{ start: "asc" }, { end: "asc" }, { status: "asc" }], | ||
include: { | ||
bookables: true, | ||
}, | ||
}); | ||
|
||
const bookingRequest = await getBookingRequestOrThrow(prisma, params.id); | ||
const form = await getSuperValidatedForm(bookingRequest); | ||
|
||
return { | ||
bookables, | ||
form, | ||
booking: bookingRequest, | ||
allBookingRequests, | ||
bookingRequests: await getUpcomingBookingRequests(prisma), | ||
}; | ||
}; | ||
|
||
export { actions }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script lang="ts"> | ||
import type { PageData } from "./$types"; | ||
import SetPageTitle from "$lib/components/nav/SetPageTitle.svelte"; | ||
import BookingCalendar from "../../BookingCalendar.svelte"; | ||
import BookingEditor from "../../BookingEditor.svelte"; | ||
import * as m from "$paraglide/messages"; | ||
export let data: PageData; | ||
</script> | ||
|
||
<SetPageTitle title={m.booking_reviewBooking()} /> | ||
|
||
<BookingEditor {data} mode="review" /> | ||
|
||
<BookingCalendar {...data} class="mt-16" /> |
Oops, something went wrong.