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(fe): Added contact types and recursive function #350

Merged
merged 3 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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