+page.svelte 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <script lang="ts">
  2. import { goto } from '$app/navigation';
  3. import { page } from '$app/stores';
  4. import { api_host } from '$lib';
  5. import type { Appointment, AppointmentDateTimes, AppointmentInputs, DynamicJson } from '$lib/dbdata';
  6. import AppointmentConfirmDialog from '$lib/modules/AppointmentConfirmDialog.svelte';
  7. import AppointmentInfo from '$lib/modules/AppointmentInfo.svelte';
  8. import DatePicker from '$lib/modules/DatePicker.svelte';
  9. import DateTimes from '$lib/modules/DateTimes.svelte';
  10. import { onMount } from 'svelte';
  11. let title: string = "Appointment";
  12. let location: string = "Somewhere";
  13. let description: string = "Description ...";
  14. let selectedDate: Date = new Date();
  15. let activateModal: boolean = false;
  16. let dynamicInputs: DynamicJson[] = [];
  17. let appointmentDateTimes: AppointmentDateTimes[] = [
  18. ];
  19. async function getAppointmentInfo(appointmentId: string) {
  20. const response = await fetch(`${api_host}/api/schedule?appointmentId=${appointmentId}`, {
  21. method: "GET",
  22. headers: {
  23. "Content-Type": "application/json"
  24. }
  25. })
  26. const js: Appointment = await response.json();
  27. appointmentDateTimes = js.times.filter(element => element.available === false);
  28. title = js.title;
  29. description = js.description;
  30. location = js.place;
  31. dynamicInputs = js.inputs;
  32. if (response.status === 404) {
  33. goto('/errors/404');
  34. }
  35. if (response.status === 410) {
  36. goto('/errors/410');
  37. }
  38. }
  39. onMount(async () => {
  40. const id = $page.url.searchParams.get('id');
  41. if (!id) {
  42. goto('/errors/404');
  43. } else {
  44. await getAppointmentInfo(id);
  45. }
  46. });
  47. </script>
  48. <style>
  49. .w-80 {
  50. max-width: 600px;
  51. }
  52. .inline-margin {
  53. margin-inline: auto;
  54. }
  55. </style>
  56. <DatePicker bind:appointmentDateTimes bind:selectedDate />
  57. <div class="top-margin w-80 inline-margin">
  58. <AppointmentInfo bind:title bind:description bind:location />
  59. {#key selectedDate}
  60. <DateTimes bind:activateModal bind:selectedDate bind:availableTimes={appointmentDateTimes} />
  61. {/key}
  62. </div>
  63. <AppointmentConfirmDialog bind:dynamicInputs bind:active={activateModal} bind:date={selectedDate} bind:title bind:description bind:location />