Skip to content

Commit

Permalink
➕ Frontend validation for schedule creation/modification
Browse files Browse the repository at this point in the history
  • Loading branch information
devmount committed Sep 13, 2024
1 parent c87c879 commit 5ec9924
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
26 changes: 25 additions & 1 deletion frontend/src/components/ScheduleCreation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { Dayjs } from 'dayjs';
import { useI18n } from 'vue-i18n';
import { useUserStore } from '@/stores/user-store';
import { dayjsKey, callKey, isoWeekdaysKey } from '@/keys';
import { dayjsKey, callKey, isoWeekdaysKey, hasProfanityKey } from '@/keys';
import AppointmentCreatedModal from '@/components/AppointmentCreatedModal.vue';
import PrimaryButton from '@/tbpro/elements/PrimaryButton.vue';
Expand Down Expand Up @@ -46,6 +46,7 @@ const { t } = useI18n();
const dj = inject(dayjsKey);
const call = inject(callKey);
const isoWeekdays = inject(isoWeekdaysKey);
const hasProfanity = inject(hasProfanityKey);
const dateFormat = DateFormatStrings.QalendarFullDay;
const firstStep = ScheduleCreationState.Availability;
Expand Down Expand Up @@ -253,6 +254,20 @@ const revertForm = (resetData = true) => {
}
};
// Form validation
const scheduleValidationError = (schedule: Schedule): string|null => {
// Schedule name is empty
if (schedule.name === '') {
return t('validation.fieldIsRequired', { field: t('ftue.scheduleName') });
}
// Schedule name contains profanity
if (hasProfanity(schedule.name)) {
return t('validation.fieldContainsProfanity', { field: t('ftue.scheduleName') });
}
// All good
return null;
};
// handle actual schedule creation/update
const savingInProgress = ref(false);
const saveSchedule = async (withConfirmation = true) => {
Expand All @@ -275,6 +290,15 @@ const saveSchedule = async (withConfirmation = true) => {
delete obj.time_updated;
delete obj.id;
// validate schedule data
const validationError = scheduleValidationError(obj);
if (validationError) {
scheduleCreationError.value = validationError;
savingInProgress.value = false;
window.scrollTo(0, 0);
return;
}
// save schedule data
const response = props.schedule
? await scheduleStore.updateSchedule(call, props.schedule.id, obj)
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@
"minutes": "{value} Minuten",
"none": "{value}"
},
"validation": {
"fieldContainsProfanity": "Bitte verwende keine beleidigenden Ausdrücke (entdeckt in {field}).",
"fieldIsRequired": "{field} darf nicht leer sein."
},
"waitingList": {
"adminInviteNotice": "Hinweis: Der Senden-Button wird bereits akzeptierte Personen nicht erneut einladen, sie können aber dennoch ausgewählt werden. Verwende die Filter für eine bessere Übersicht!",
"confirmHeading": "Du bist auf der Warteliste",
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@
"minutes": "{value} minutes",
"none": "{value}"
},
"validation": {
"fieldContainsProfanity": "Please don't use offensive language (detected in {field}).",
"fieldIsRequired": "{field} cannot be empty."
},
"waitingList": {
"adminInviteNotice": "Notice: The Send button will not re-invite people already accepted, but you can still select them. Use the filters for clarity!",
"confirmHeading": "You’re on the waitlist",
Expand Down

0 comments on commit 5ec9924

Please sign in to comment.