- Implemented API for updating company Verifactu profile. - Created entities for company Verifactu profile and defaults. - Developed hooks for querying and updating the company Verifactu profile. - Added UI components for displaying and editing company Verifactu settings. - Introduced validation and error handling for profile updates. - Created utility functions for building form data and handling feedback states. - Added tests for utility functions and error handling.
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import type { IModuleClient, ModuleSettingsEntryContribution } from "@erp/core/client";
|
|
|
|
import type { SettingsSectionCatalogItem } from "./settings-section-catalog";
|
|
|
|
export interface SettingsNavigationEntry extends ModuleSettingsEntryContribution {
|
|
moduleName: string;
|
|
}
|
|
|
|
export interface SettingsNavigationSection extends SettingsSectionCatalogItem {
|
|
entries: SettingsNavigationEntry[];
|
|
}
|
|
|
|
const buildSectionMap = (sections: SettingsSectionCatalogItem[]) => {
|
|
return new Map(sections.map((section) => [section.id, section]));
|
|
};
|
|
|
|
export const buildSettingsNavigation = ({
|
|
modules,
|
|
sections,
|
|
}: {
|
|
modules: IModuleClient[];
|
|
sections: SettingsSectionCatalogItem[];
|
|
}): SettingsNavigationSection[] => {
|
|
const sectionMap = buildSectionMap(sections);
|
|
const entriesBySection = new Map<string, SettingsNavigationEntry[]>();
|
|
|
|
for (const module of modules) {
|
|
if (!module.settings) {
|
|
continue;
|
|
}
|
|
|
|
for (const entry of module.settings.entries) {
|
|
const section = sectionMap.get(entry.sectionId);
|
|
|
|
if (!section) {
|
|
throw new Error(
|
|
`[Settings] El módulo "${module.name}" declara la sección inexistente "${entry.sectionId}".`
|
|
);
|
|
}
|
|
|
|
const sectionEntries = entriesBySection.get(entry.sectionId) ?? [];
|
|
|
|
sectionEntries.push({
|
|
...entry,
|
|
moduleName: module.name,
|
|
});
|
|
|
|
entriesBySection.set(entry.sectionId, sectionEntries);
|
|
}
|
|
}
|
|
|
|
return sections
|
|
.map((section) => ({
|
|
...section,
|
|
entries: entriesBySection.get(section.id) ?? [],
|
|
}))
|
|
.filter((section) => section.entries.length > 0);
|
|
};
|