Skip to content

Commit

Permalink
fix(FSADT1-1347): fixing validation missing value
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj committed Jul 15, 2024
1 parent f5b892a commit 0d13a6c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
4 changes: 4 additions & 0 deletions frontend/src/dto/ApplyClientNumberDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export const indexedEmptyContact = (index: number): Contact =>
firstName: "",
lastName: "",
phoneNumber: "",
secondaryPhoneNumber: "",
faxNumber: "",
email: "",
index,
}),
Expand Down Expand Up @@ -125,6 +127,8 @@ export const emptyContact: Contact = {
firstName: "",
lastName: "",
phoneNumber: "",
secondaryPhoneNumber: "",
faxNumber: "",
email: "",
index: 0,
};
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/helpers/validators/StaffFormValidations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fieldValidations["location.addresses.*.notes"] = [

// Step 3: Contacts

fieldValidations["location.contacts.*.locationNames"] = [
fieldValidations["location.contacts.*.locationNames.text"] = [
isNotEmptyArray("You must select at least one location"),
];
fieldValidations["location.contacts.*.contactType.text"] = [
Expand All @@ -230,6 +230,7 @@ fieldValidations["location.contacts.*.firstName"] = [
isMaxSizeMsg("first name", 30),
hasOnlyNamingCharacters("first name"),
];

fieldValidations["location.contacts.*.lastName"] = [
isMinSize("Please enter the last name")(1),
isMaxSizeMsg("last name", 30),
Expand All @@ -243,9 +244,13 @@ fieldValidations["location.contacts.*.emailAddress"] = [
];

fieldValidations["location.contacts.*.phoneNumber"] = [...phoneValidations];

fieldValidations["location.contacts.*.secondaryPhoneNumber"] = [...phoneValidations];

fieldValidations["location.contacts.*.faxNumber"] = [...phoneValidations];

// General information

export const addValidation = (key: string, validation: (value: string) => string): void => {
if (!fieldValidations[key]) fieldValidations[key] = [];
fieldValidations[key].push(validation);
Expand All @@ -255,7 +260,7 @@ const defaultGetValidations = getValidations;

export const validate = (
...args: Parameters<typeof globalValidate>
): ReturnType<typeof globalValidate> => {
): ReturnType<typeof globalValidate> => {
const getValidations = args[3] || defaultGetValidations;
args[3] = getValidations;
return globalValidate.apply(this, args);
Expand Down
27 changes: 3 additions & 24 deletions frontend/src/pages/FormStaffPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,9 @@ const formData = ref<FormDataDto>({ ...newFormDataDto() });
const locations = computed(() =>
formData.value.location.addresses.map((address: any) => address.locationName)
);
const associatedLocations = computed(() =>
formData.value.location.contacts
.map((contact: Contact) => contact.locationNames)
.map((locationNames: CodeDescrType[]) =>
locationNames.map((locationName: CodeDescrType) => locationName.text)
)
.reduce(
(accumulator: string[], current: string[]) => accumulator.concat(current),
[]
)
);
addValidation(
"location.contacts.*.locationNames.*.text",
isContainedIn(locations)
isContainedIn(locations, "Location name must be one of the locations")
);
// Tab system
Expand Down Expand Up @@ -204,20 +193,10 @@ const onCancel = () => {
};
const onNext = () => {
formData.value.location.addresses.forEach((address: Address,index: number) => console.log('Address #'+index,address.index));
formData.value.location.contacts.forEach((contact: Contact,index: number) => console.log('Contact #'+index,contact.index));
//This fixes the index
formData.value.location.addresses.forEach((address: Address,index: number) => address.index = index);
formData.value.location.contacts.forEach((contact: Contact,index: number) => contact.index = index);
formData.value.location.addresses.forEach((address: Address,index: number) => console.log('Address #'+index,address.index));
formData.value.location.contacts.forEach((contact: Contact,index: number) => console.log('Contact #'+index,contact.index));
notificationBus.emit(undefined);
if (currentTab.value + 1 < progressData.length) {
if (checkStepValidity(currentTab.value)) {
Expand Down Expand Up @@ -266,7 +245,7 @@ const updateClientType = (value: CodeNameType | undefined) => {
locationNames: [defaultLocation],
contactType: { value: "BL", text: "Billing" },
};
formData.value.location.contacts[0] = applicantContact;
formData.value.location.contacts[0] = applicantContact;
break;
}
default:
Expand Down

0 comments on commit 0d13a6c

Please sign in to comment.