feat: additional work sections

This commit is contained in:
Alexander KIRILOV
2022-10-27 15:43:15 +02:00
parent 9b1f3eda05
commit 7bc4a998fe
13 changed files with 184 additions and 38 deletions

View File

@ -1,3 +1,4 @@
import { find } from 'lodash';
import get from 'lodash/get';
import React from 'react';
import { validate } from 'uuid';
@ -44,11 +45,21 @@ const sectionMap = (Section: React.FC<SectionProps>): Record<string, JSX.Element
});
export const getSectionById = (id: string, Section: React.FC<SectionProps>): JSX.Element => {
// Check if section id is a custom section (an uuid)
if (validate(id)) {
return <Section key={id} path={`sections.${id}`} />;
}
return get(sectionMap(Section), id);
// Check if section id is a predefined seciton in config
const predefinedSection = get(sectionMap(Section), id);
if(predefinedSection) {
return predefinedSection;
}
// Other ways section should be a cloned section
const section = find(sectionMap(Section), (element, key) => id.includes(key));
return React.cloneElement(section!, { path: `sections.${id}` });
};
export default sectionMap;