Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(proposal): add validation to start time #3991

Merged
merged 5 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/components/ModalSelectDate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -39,6 +40,17 @@ watch(open, () => {
time.value = `${h}:${m}`;
input.value = dateString;
});

watchEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I see now, but when I enter a time in the past the input is no longer functioning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you specify the way you did it? This code should prevent entering past time.
p.s.: for more clever users I added an extra check here and here :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@samuveth samuveth Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of filling the input automatically with the current time, we should let the user enter time in that past and when he clicks "Select" we should show a warning and prevent "Select"

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}`;
}
});
</script>

<template>
Expand Down
6 changes: 5 additions & 1 deletion src/views/SpaceCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ function getFormattedForm() {
.map(choice => choice.text)
.filter(choiceText => choiceText.length > 0);
updateTime();
clonedForm.start = dateStart.value;
const thisMomentTimestamp = parseInt((Date.now() / 1e3).toFixed());
clonedForm.start =
dateStart.value < thisMomentTimestamp
Todmy marked this conversation as resolved.
Show resolved Hide resolved
? thisMomentTimestamp
: dateStart.value;
clonedForm.end = dateEnd.value;
return clonedForm;
}
Expand Down