Skip to content

Commit

Permalink
feat(fe): Added contact types and recursive function (#350)
Browse files Browse the repository at this point in the history
* feat(fe):

- Added Contact Types from backend
- Added recursive function to search/update JSON keys and values at any level of a JSON

* feat(fe):

- Made the code more DRY
  • Loading branch information
mamartinezmejia authored Feb 16, 2023
1 parent 1234513 commit 31badc0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
6 changes: 2 additions & 4 deletions frontend/components.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-vue-components
// generated by unplugin-vue-components
// We suggest you to commit this file into source control
// Read more: https://github.com/vuejs/core/pull/3399
import '@vue/runtime-core'

Expand Down
58 changes: 29 additions & 29 deletions frontend/src/pages/applynewclient/formsections/FormSections.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const { data: provinceCodes } = useCountryIdAutoComplete();
const { data: activeClientTypeCodes } = useFetch('/api/clients/activeClientTypeCodes', { method:'get', initialData:[] });
const { data: countryCodes } = useFetch('/api/clients/activeCountryCodes?page=0&size=250', { method:'get', initialData:[] });
const { data: contactTypeCodes } = useFetch('/api/clients/activeContactTypeCodes', { method:'get', initialData:[] });
const computedBusinessTypeSectionSchema = computed(() => {
const schemaCopy = businessTypeSectionSchema
Expand Down Expand Up @@ -75,38 +76,37 @@ const computedInformationSchemaType = computed(() => {
});
const computedLocationSectionSchema = computed(() => {
const subFields = {};
locationSectionSchema.content.forEach((p) => {
if (p.subfields) subFields[p.fieldProps.modelName] = p.subfields;
});
Object.keys(subFields).forEach((subKey) => {
const subfields = subFields[subKey];
const newsubfields = subfields.map((p) =>
p.fieldProps.modelName == "country"
? { ...p, options: countryCodes.value.map(conversionFn) }
: p
)
.map((p) =>
p.fieldProps.modelName == "province"
? { ...p, options: provinceCodes.value.map(conversionFn) }
: p
);
subFields[subKey] = newsubfields;
});
const updatedOptions = (field: any, modelName: string, options: any) => {
if (field.fieldProps && field.fieldProps.modelName == modelName) {
return { ...field, options: options.value.map(conversionFn) }
}
else {
return field;
}
};
const newSchema = locationSectionSchema.content.map((p) =>
p.fieldProps.modelName in subFields
? { ...p, subfields: subFields[p.fieldProps.modelName] }
: p
);
const deepSearch = (target) => {
if (typeof target === 'object') {
for (let key in target) {
if (typeof target[key] === 'object') {
if (key === 'subfields') {
const newsubfields = target[key]
.map((p) => updatedOptions(p, "country", countryCodes))
.map((p) => updatedOptions(p, "province", provinceCodes))
.map((p) => updatedOptions(p, "contactType", contactTypeCodes));
target[key] = newsubfields;
}
deepSearch(target[key]);
}
}
}
return target;
}
return {
...locationSectionSchema,
content: newSchema,
};
const newSchema = deepSearch(locationSectionSchema);
return { ...locationSectionSchema, newSchema};
});
</script>

Expand Down

0 comments on commit 31badc0

Please sign in to comment.