Skip to content

Commit

Permalink
hot: resolve issues
Browse files Browse the repository at this point in the history
  • Loading branch information
c0repwn3r committed Nov 26, 2024
1 parent 150a0c8 commit 1a9aafd
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 48 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
PUBLIC_SENTRY_DSN: ${{ secrets.PUBLIC_SENTRY_DSN }}
API_MASTER_KEY: ${{ secrets.API_MASTER_KEY }}
BASE_URL: ${{ vars.BASE_URL }}
steps:
- name: Checkout source
uses: actions/checkout@v4
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@
"sveltekit-superforms": "^2.20.0",
"tailwind-merge": "^2.5.4",
"ulid": "^2.3.0"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
3 changes: 2 additions & 1 deletion src/lib/emails/AppointmentBooked.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import type { AppointmentBookedProps } from '$lib/emails/appointment_booked';
import { DateTime } from 'luxon';
import { BASE_URL } from '$env/static/private';
let {
startTime,
Expand All @@ -13,7 +14,7 @@
reschedule
}: AppointmentBookedProps = $props();
let reschedule_link = `https://scheddy.ztlartcc.org/schedule${link_params}`;
let reschedule_link = `${BASE_URL}schedule${link_params}`;
let title = reschedule ? 'Appointment updated' : 'Appointment booked';
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/lib/emails/AppointmentBooked.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ This is your confirmation email for your upcoming session.
-- Duration: {duration} minutes
-- Mentor: {mentorName}

Cancel/Reschedule
Cancel/Reschedule: {rescheduleLink}

---

Confirmation ID {sessionId}.
You are receiving this email because you have booked a session with the ZTL ARTCC. If you believe to have received this email in error, please contact [email protected].
You are receiving this email because you have booked a session with the ZTL ARTCC. If you believe to have received this email in error, please contact [email protected].
4 changes: 3 additions & 1 deletion src/lib/emails/appointment_booked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { type EmailContent, templateOut } from '$lib/email';
import plaintextTemplate from './AppointmentBooked.txt?raw';
import AppointmentBooked from './AppointmentBooked.svelte';
import { render } from 'svelte/server';
import { BASE_URL } from '$env/static/private';

export interface AppointmentBookedProps {
startTime: DateTime;
Expand All @@ -25,7 +26,8 @@ export function appointment_booked(props: AppointmentBookedProps): EmailContent
sessionId: props.sessionId,
timezone: props.timezone,
link_params: props.link_params,
reschedule: props.reschedule ? 'rescheduled' : ''
reschedule: props.reschedule ? 'rescheduled' : '',
reschedule_link: `${BASE_URL}schedule/${props.link_params}`
}),
html: render(AppointmentBooked, {
props: props
Expand Down
16 changes: 11 additions & 5 deletions src/routes/(authed)/schedule/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export const load: PageServerLoad = async ({ cookies, url }) => {
: null;

const originalSessionId = url.searchParams.get('sessionId')!;
const ogSession = await db.select().from(sessions).where(eq(sessions.id, originalSessionId));

return {
user,
Expand All @@ -213,20 +214,23 @@ export const load: PageServerLoad = async ({ cookies, url }) => {
sessionTypes: sTypes,
slotData,
originalSessionType,
originalSessionId
originalSessionId,
ogSession
};
};

export const actions: Actions = {
book: async ({ cookies, request, url }) => {
book: async ({ cookies, request }) => {
const { user } = (await loadUserData(cookies))!;

const formData = await request.formData();
const requestedSlotId = formData.get('timeslot')!;
const requestedType = formData.get('type')!;
const timezone = formData.get('timezone')!;
const orginalSessionId = url.searchParams.get('sessionId')!;
const reschedule = url.searchParams.has('reschedule')!;
const orginalSessionId = formData.get('sessionId');
const reschedule = formData.has('reschedule') || false;

console.log(formData);

const sTypes = await db.select().from(sessionTypes);
const mentors = await db
Expand Down Expand Up @@ -343,6 +347,8 @@ export const actions: Actions = {
redirect(307, '/schedule');
}

await db.delete(sessions).where(eq(sessions.id, request.sessionId));
const formData = await request.formData();

await db.delete(sessions).where(eq(sessions.id, formData.get('sessionId')!.toString()));
}
};
92 changes: 54 additions & 38 deletions src/routes/(authed)/schedule/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,23 @@
let bookingState: 'success' | 'fail' | 'loading' = $state('loading');
const bookingUrl = data.originalSessionType
? `?/book?sessionId=${data.originalSessionId}&reschedule=true&type=${data.originalSessionType}`
: '?/book';
let cancelOpen = $state(false);
function check_time(t: string) {
function check_time(t: string): boolean {
const start_time = DateTime.fromISO(t);
const now = DateTime.now();
const interval = start_time.diff(now, 'hours');
return interval.hours < 24;
return interval.hours >= 24;
}
let canCancelReschedule = $derived.by(() => {
console.log(data.originalSessionType, data.ogSession);
if (data.originalSessionType && data.ogSession.length !== 0) {
return check_time(data.ogSession[0].start);
} else {
return true;
}
});
let cancelOpen = $state(false);
async function cancel() {
let udata = new URLSearchParams();
udata.set('sessionId', data.originalSessionId);
Expand All @@ -96,8 +100,8 @@
},
body: udata.toString()
});
await goto('/dash');
await invalidateAll();
await goto('/');
}
async function book() {
Expand All @@ -106,17 +110,19 @@
step = 4;
bookingState = 'loading';
let data = new URLSearchParams();
data.set('timeslot', timeslot);
data.set('type', sessionType!);
data.set('timezone', timezone);
let rdata = new URLSearchParams();
rdata.set('timeslot', timeslot);
rdata.set('type', sessionType!);
rdata.set('timezone', timezone);
rdata.set('sessionId', data.originalSessionId);
rdata.set('reschedule', true);
let r = await fetch(bookingUrl, {
let r = await fetch('?/book', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: data.toString()
body: rdata.toString()
});
if (r.ok) {
bookingState = 'success';
Expand All @@ -137,11 +143,16 @@
</p>

<h1 class="mt-1 font-bold text-2xl text-center">
Schedule appointment at {PUBLIC_FACILITY_NAME}
{data.originalSessionType ? 'Reschedule' : 'Schedule'} appointment at {PUBLIC_FACILITY_NAME}
</h1>

<div class="text-left mt-3 mb-6 flex flex-col gap-4 justify-center">
{#if step === 1}
{#if !canCancelReschedule}
<p>
You cannot cancel or reschedule this session, as it is within 24 hours. Contact your
mentor.
</p>
{:else if step === 1}
<Select bind:value={sessionType} label="Session Type">
{#each Object.entries(categories) as [k, v]}
<optgroup label={k}>
Expand All @@ -159,16 +170,6 @@
>
Next
</Button>
{#if data.originalSessionType}
<Button
onclick={() => {
cancelOpen = true;
}}
variant="danger"
>
Cancel
</Button>
{/if}
{/if}
{:else if step === 2}
<Select name="timezone" bind:value={timezone} label="Timezone">
Expand All @@ -177,7 +178,11 @@
{/each}
</Select>
{#if sessionType}
<Select name="slot" bind:value={timeslot} label="Session Date/Time">
<Select
name="slot"
bind:value={timeslot}
label={data.originalSessionType ? 'New Session Date/Time' : 'Session Date/Time'}
>
{#each data.slotData[sessionType] as slot}
<option value="{slot.slot}@{slot.mentor}"
>{Interval.fromISO(slot.slot)
Expand All @@ -191,15 +196,25 @@
</Select>
{/if}
<div class="flex flex-row justify-center gap-4 flex-grow">
<Button
class="flex-1"
variant="ghost"
onclick={() => {
step = 1;
}}
>
Back
</Button>
{#if data.originalSessionType}
<Button
class="flex-1"
variant="danger"
onclick={() => {
cancelOpen = true;
}}>Cancel Appointment</Button
>
{:else}
<Button
class="flex-1"
variant="ghost"
onclick={() => {
step = 1;
}}
>
Back
</Button>
{/if}
{#if timeslot !== null}
<Button
class="flex-1"
Expand Down Expand Up @@ -307,7 +322,7 @@
>
</div>
</Card>
{#if data.originalSessionType && check_time(timeslot)}
{#if data.originalSessionType}
<Modal
onclose={() => {
cancelOpen = false;
Expand All @@ -320,6 +335,7 @@
}}
title="Confirm cancellation"
/>
<p class="mx-4">You'll need to re-book another session.</p>
<ModalFooter>
<Button
onclick={() => {
Expand Down

0 comments on commit 1a9aafd

Please sign in to comment.