From 8e5e7ad5eab89864816f13acc10789f9fa1d052d Mon Sep 17 00:00:00 2001 From: Dmytro Tolok Date: Tue, 13 Jun 2023 17:36:56 +0200 Subject: [PATCH 1/4] feat(proposal): add validation to start time --- src/components/ModalSelectDate.vue | 14 +++++++++++++- src/views/SpaceCreate.vue | 6 +++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/ModalSelectDate.vue b/src/components/ModalSelectDate.vue index 2650b185357..19537534fff 100644 --- a/src/components/ModalSelectDate.vue +++ b/src/components/ModalSelectDate.vue @@ -28,7 +28,8 @@ function handleSubmit() { if (step.value === 0) return (step.value = 1); const dateString = `${input.value} ${time.value}:00`; const timestamp = new Date(dateString).getTime() / 1000; - emit('input', timestamp); + const now = parseInt((Date.now() / 1e3).toFixed()); + emit('input', timestamp > now ? timestamp : now); emit('close'); } @@ -39,6 +40,17 @@ watch(open, () => { time.value = `${h}:${m}`; input.value = dateString; }); + +watchEffect(() => { + const startDateString = `${input.value} ${time.value}:00`; + const startTimestamp = new Date(startDateString).getTime(); + + if (startTimestamp < Date.now()) { + const { dateString, h, m } = formatDate(Date.now() / 1000); + input.value = dateString; + time.value = `${h}:${m}`; + } +});