diff --git a/package.json b/package.json index 7c40954..8dd6bc8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "collabender", - "version": "0.7.6", + "version": "0.8.2", "description": "App with Routing built-in (recommended)", "engines": { "node": ">=20.0.0" diff --git a/src/components/appointment-modal/add-appointment-modal.tsx b/src/components/appointment-modal/add-appointment-modal.tsx index 953bbcb..25dccce 100644 --- a/src/components/appointment-modal/add-appointment-modal.tsx +++ b/src/components/appointment-modal/add-appointment-modal.tsx @@ -1,24 +1,59 @@ -import { $, type Signal, component$, useOn } from '@builder.io/qwik' +import { + $, + type Signal, + component$, + useOn, + useSignal, + useVisibleTask$, +} from '@builder.io/qwik' import { Form } from '@builder.io/qwik-city' import { APP_CATEGORIES } from '~/config' import { useAddAppointment } from '~/global' +export function getDayFromUrl() { + const url = new URL(window.location.href) + const day = url.searchParams.get('day') + + return day ? day : new Date().toISOString().split('T')[0] +} + export const AddAppointmentModal = component$( ({ isAddAppointmentModalOpen, - }: { isAddAppointmentModalOpen: Signal - }) => { const action = useAddAppointment() - // Default date for the date input comes form ?day on the url or today - const url = new URL(window.location.href) - const day = url.searchParams.get('day') + const defaultOptionForDate = useSignal() + + // eslint-disable-next-line qwik/no-use-visible-task + useVisibleTask$(() => { + defaultOptionForDate.value = getDayFromUrl() + }) + + const fullDayRef = useSignal() + // eslint-disable-next-line qwik/no-use-visible-task + useVisibleTask$(({ track }) => { + track(() => + fullDayRef.value?.addEventListener('change', () => { + const timeStart = document.getElementById( + 'time_start' + ) as HTMLInputElement + const timeEnd = document.getElementById( + 'time_end' + ) as HTMLInputElement - const defaultOptionForDate = day - ? day - : new Date().toISOString().split('T')[0] + if (fullDayRef.value?.checked) { + // make the inputs disabled + timeStart.disabled = true + timeEnd.disabled = true + } else { + timeStart.disabled = false + timeEnd.disabled = false + } + }) + ) + }) useOn( 'click', @@ -64,7 +99,7 @@ export const AddAppointmentModal = component$( @@ -101,11 +136,11 @@ export const AddAppointmentModal = component$( Starts at
@@ -116,11 +151,11 @@ export const AddAppointmentModal = component$( Ends at
@@ -131,6 +166,7 @@ export const AddAppointmentModal = component$( Is it a full day event? - editModalData: any + editModalData: IAppointment }) => { - const action = useAddAppointment() + const action = useEditAppointment() + const fullDayRef = useSignal() + // eslint-disable-next-line qwik/no-use-visible-task + useVisibleTask$(({ track }) => { + const timeStart = document.getElementById( + 'time_start' + ) as HTMLInputElement + const timeEnd = document.getElementById('time_end') as HTMLInputElement + + if (fullDayRef.value?.checked) { + // make the inputs disabled + timeStart.disabled = true + timeEnd.disabled = true + } else { + timeStart.disabled = false + timeEnd.disabled = false + } + + track(() => + fullDayRef.value?.addEventListener('change', () => { + if (fullDayRef.value?.checked) { + // make the inputs disabled + timeStart.disabled = true + timeEnd.disabled = true + } else { + timeStart.disabled = false + timeEnd.disabled = false + } + }) + ) + }) useOn( 'click', @@ -32,6 +70,9 @@ export const EditAppointmentModal = component$( $(() => { isEditAppointmentModalOpen.value = false document.body.style.overflow = 'auto' + // make a fake push window to the same url we are in + // TODO: had to make it reload the page to get the last changes + window.location.reload() }) ) @@ -81,7 +122,7 @@ export const EditAppointmentModal = component$( id="date" type="date" class="w-full border border-grayBrandMedium rounded-md px-4 py-2" - value={editModalData.date } + value={editModalData.date} /> @@ -95,11 +136,11 @@ export const EditAppointmentModal = component$( Starts at
@@ -110,11 +151,11 @@ export const EditAppointmentModal = component$( Ends at
@@ -125,10 +166,11 @@ export const EditAppointmentModal = component$( Is it a full day event? @@ -156,14 +198,22 @@ export const EditAppointmentModal = component$( + +