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 | null => { if (!id) return null; // Check if section id is a custom section (is a valid 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; } // Otherwise, section must be a cloned section const section = find(sectionMap(Section), (_element, key) => id.includes(key)); if (section) return React.cloneElement(section, { path: `sections.${id}` }); return null; }; export default sectionMap;