import find from 'lodash/find'; import get from 'lodash/get'; import React from 'react'; import { validate } from 'uuid'; export type SectionProps = { path: string; titlePath?: string | string[]; subtitlePath?: string | string[]; headlinePath?: string | string[]; keywordsPath?: string; }; const sectionMap = (Section: React.FC): Record => ({ work:
, education: (
), awards:
, certifications: (
), publications:
, skills:
, languages:
, interests:
, projects: (
), volunteer:
, references:
, }); export const getSectionById = (id: string, Section: React.FC): JSX.Element => { // Check if section id is a custom section (an uuid) if (validate(id)) { return
; } // 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;