From cc1f1b1f8d0e40d078d44c6a1df60007f3c22a9b Mon Sep 17 00:00:00 2001 From: Maria Martinez <77364706+mamartinezmejia@users.noreply.github.com> Date: Tue, 12 Dec 2023 16:25:53 -0800 Subject: [PATCH 1/2] FSADT1-1051: Toast message changes and code reviews (#674) * FSADT1-1051 * Made code reviews and fixed an existing issue * no message --- .../helpers/validators/GlobalValidators.ts | 22 ++++++++++++------- frontend/src/pages/FormBCSCPage.vue | 3 ++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/frontend/src/helpers/validators/GlobalValidators.ts b/frontend/src/helpers/validators/GlobalValidators.ts index 4c8b493aaa..ba2f617850 100644 --- a/frontend/src/helpers/validators/GlobalValidators.ts +++ b/frontend/src/helpers/validators/GlobalValidators.ts @@ -288,14 +288,14 @@ export const isWithinRange = /** * Checks if the value is a possibly valid day for the specified month. * Note: February 29 will always be considered valid, since this validation does not consider the year. - * + * * @param validMonth a valid month * @param message the error message to be returned if the validation fails. */ export const isValidDayOfMonth = ( validMonth: string, - message = "Value is not a valid day in the selected month", + message = "Value is not a valid day in the selected month" ) => (value: string): string => { const arbitraryLeapYear = 2000; @@ -310,7 +310,7 @@ export const isValidDayOfMonth = /** * Checks if the value is a valid day for the specified year and month. * i.e. it tells if the date formed by the provided year, month and day exists. - * + * * @param validYear a valid year * @param validMonth a valid month * @param message the error message to be returned if the validation fails. @@ -319,7 +319,7 @@ export const isValidDayOfMonthYear = ( validYear: string, validMonth: string, - message = "Value is not a valid day in the selected month and year", + message = "Value is not a valid day in the selected month and year" ) => (value: string): string => { const dateString = `${validYear}-${validMonth}-${value}`; @@ -334,7 +334,7 @@ export const isMinimumYearsAgo = ( years: number, message: string | ((years: number) => string) = (years) => - `Value must be at least ${years} years ago`, + `Value must be at least ${years} years ago` ) => (value: string): string => { const maximumDate = subYears(startOfToday(), years); @@ -349,7 +349,10 @@ export const isMinimumYearsAgo = }; export const isGreaterThan = - (compareTo: number, message: string = `Value must be greater than ${compareTo}`) => + ( + compareTo: number, + message: string = `Value must be greater than ${compareTo}` + ) => (value: string): string => { if (Number(value) > compareTo) { return ""; @@ -358,7 +361,10 @@ export const isGreaterThan = }; export const isLessThan = - (compareTo: number, message: string = `Value must be less than ${compareTo}`) => + ( + compareTo: number, + message: string = `Value must be less than ${compareTo}` + ) => (value: string): string => { if (Number(value) < compareTo) { return ""; @@ -366,7 +372,7 @@ export const isLessThan = return message; }; -export const isDateInThePast = (message: "Value must be in the past") => (value: string) => { +export const isDateInThePast = (message: string) => (value: string) => { const dateValue = parseISO(value); if (!isBefore(dateValue, startOfToday())) { return message; diff --git a/frontend/src/pages/FormBCSCPage.vue b/frontend/src/pages/FormBCSCPage.vue index 74af534b98..a545fbe6b4 100644 --- a/frontend/src/pages/FormBCSCPage.vue +++ b/frontend/src/pages/FormBCSCPage.vue @@ -207,7 +207,8 @@ const handleRemove = (index: number) => { ? `${formData.location.contacts[index].firstName} ${formData.location.contacts[index].lastName}` : "Contact #" + index; bus.emit({ - message: selectedContact, + name: selectedContact, + message: `“${selectedContact}” additional contact was deleted`, kind: "Contact deleted", toastTitle: "The additional contact was deleted", handler: removeContact(index), From 34e53e274a65f1467412a97fb0a42663747f7ad6 Mon Sep 17 00:00:00 2001 From: Maria Martinez <77364706+mamartinezmejia@users.noreply.github.com> Date: Wed, 13 Dec 2023 10:21:54 -0800 Subject: [PATCH 2/2] FSADT1-1053: Improve validation when values are empty (#675) * FSADT1-1053 * Made code reviews --- .../validators/BCeIDFormValidations.ts | 1 - .../helpers/validators/GlobalValidators.ts | 2 +- .../validators/SubmissionValidators.ts | 56 +++++++++++-------- .../BusinessInformationWizardStep.vue | 2 +- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/frontend/src/helpers/validators/BCeIDFormValidations.ts b/frontend/src/helpers/validators/BCeIDFormValidations.ts index d671e88d44..bf50387427 100644 --- a/frontend/src/helpers/validators/BCeIDFormValidations.ts +++ b/frontend/src/helpers/validators/BCeIDFormValidations.ts @@ -15,7 +15,6 @@ import { isGreaterThan, } from "@/helpers/validators/GlobalValidators"; - // Step 1: Business Information formFieldValidations["businessInformation.businessName"] = [ isNotEmpty("Business Name cannot be empty"), diff --git a/frontend/src/helpers/validators/GlobalValidators.ts b/frontend/src/helpers/validators/GlobalValidators.ts index ba2f617850..9b087ced4b 100644 --- a/frontend/src/helpers/validators/GlobalValidators.ts +++ b/frontend/src/helpers/validators/GlobalValidators.ts @@ -240,7 +240,7 @@ export const isUniqueDescriptive = (): { if ( values.some( (entry: string) => entry.toLowerCase() === value.toLowerCase() - ) + ) && value.trim() !== "" ) { return message; } diff --git a/frontend/src/helpers/validators/SubmissionValidators.ts b/frontend/src/helpers/validators/SubmissionValidators.ts index f64e53ef84..d440622702 100644 --- a/frontend/src/helpers/validators/SubmissionValidators.ts +++ b/frontend/src/helpers/validators/SubmissionValidators.ts @@ -18,28 +18,32 @@ * * @see {@link SubmissionValidators.spec.ts} */ -import { useEventBus } from '@vueuse/core' -import type { ValidationMessageType } from '@/dto/CommonTypesDto' +import { useEventBus } from "@vueuse/core"; +import type { ValidationMessageType } from "@/dto/CommonTypesDto"; /** * Event bus for submission error notifications. */ -const errorBus = useEventBus('submission-error-notification') +const errorBus = useEventBus( + "submission-error-notification" +); /** * Event bus for revalidating the submission. */ -const revalidateBus = useEventBus('revalidate-bus') +const revalidateBus = useEventBus("revalidate-bus"); /** * Event bus for error notifications bar. */ -const notificationBus = useEventBus("error-notification"); +const notificationBus = useEventBus( + "error-notification" +); /** * Array of submission validators. */ -let submissionValidators : ValidationMessageType[] = [] +let submissionValidators: ValidationMessageType[] = []; /** * Register a listener for submission errors on the error bus. @@ -47,11 +51,11 @@ let submissionValidators : ValidationMessageType[] = [] */ errorBus.on((errors) => { submissionValidators = errors.map((error: ValidationMessageType) => { - notificationBus.emit(error) - return { ...error, originalValue: '' } - }) - revalidateBus.emit() -}) + notificationBus.emit(error); + return { ...error, originalValue: "" }; + }); + revalidateBus.emit(); +}); /** * Update the submission validators array with the provided fieldId and value. @@ -60,13 +64,15 @@ errorBus.on((errors) => { * @param value - The new value for the validator's originalValue property. */ const updateValidators = (fieldId: string, value: string): void => { - submissionValidators = submissionValidators.map((validator : ValidationMessageType) => { - if (validator.fieldId === fieldId) { - return { ...validator, originalValue: value } + submissionValidators = submissionValidators.map( + (validator: ValidationMessageType) => { + if (validator.fieldId === fieldId) { + return { ...validator, originalValue: value }; + } + return validator; } - return validator - }) -} + ); +}; /** * Create a submission validation function for the specified fieldName. @@ -78,14 +84,16 @@ export const submissionValidation = ( fieldName: string ): ((value: string) => string) => { return (value: string) => { - const foundError = submissionValidators.find((validator: ValidationMessageType) => validator.fieldId === fieldName) + const foundError = submissionValidators.find( + (validator: ValidationMessageType) => validator.fieldId === fieldName + ); if ( foundError && - (foundError.originalValue === value || foundError.originalValue === '') + (foundError.originalValue === value || foundError.originalValue === "") ) { - updateValidators(fieldName, value) - return foundError.errorMsg + updateValidators(fieldName, value); + return foundError.errorMsg; } - return '' - } -} + return ""; + }; +}; diff --git a/frontend/src/pages/bceidform/BusinessInformationWizardStep.vue b/frontend/src/pages/bceidform/BusinessInformationWizardStep.vue index 92883455db..e74c5a56b7 100644 --- a/frontend/src/pages/bceidform/BusinessInformationWizardStep.vue +++ b/frontend/src/pages/bceidform/BusinessInformationWizardStep.vue @@ -10,7 +10,7 @@ import { useFetchTo } from "@/composables/useFetch"; import { BusinessSearchResult, ClientTypeEnum, - ProgressNotification + ProgressNotification, } from "@/dto/CommonTypesDto"; import { BusinessTypeEnum } from "@/dto/CommonTypesDto"; import type {