import { Add } from '@mui/icons-material'; import { Button } from '@mui/material'; import { ListItem, Section as SectionRecord, SectionType } from '@reactive-resume/schema'; import clsx from 'clsx'; import get from 'lodash/get'; import { useTranslation } from 'next-i18next'; import { validate } from 'uuid'; import Heading from '@/components/shared/Heading'; import List from '@/components/shared/List'; import { useAppDispatch, useAppSelector } from '@/store/hooks'; import { ModalName, setModalState } from '@/store/modal/modalSlice'; import { duplicateItem, duplicateSection } from '@/store/resume/resumeSlice'; import SectionSettings from './SectionSettings'; type Props = { path: `sections.${string}`; type?: SectionType; name?: string; titleKey?: string; subtitleKey?: string; isEditable?: boolean; isHideable?: boolean; isDeletable?: boolean; addMore?: boolean; isDuplicated?: boolean; }; const Section: React.FC = ({ path, name = 'Section Name', type = 'basic', titleKey = 'title', subtitleKey = 'subtitle', isEditable = false, isHideable = false, isDeletable = false, addMore = false, isDuplicated = false, }) => { const { t } = useTranslation(); const dispatch = useAppDispatch(); const heading = useAppSelector((state) => get(state.resume.present, `${path}.name`, name)); const visibility = useAppSelector((state) => get(state.resume.present, `${path}.visible`, true)); const handleAdd = () => { const id = path.split('.')[1]; let modal: ModalName = validate(id) ? 'builder.sections.custom' : `builder.${path}`; if (type) { modal = `builder.sections.${type}`; } dispatch(setModalState({ modal, state: { open: true, payload: { path } } })); }; const handleEdit = (item: ListItem) => { const id = path.split('.')[1]; let modal: ModalName = validate(id) ? 'builder.sections.custom' : `builder.${path}`; const payload = validate(id) ? { path, item } : { item }; if (isDuplicated) { modal = `builder.sections.${type}`; payload.path = path; } dispatch(setModalState({ modal, state: { open: true, payload } })); }; const handleDuplicate = (item: ListItem) => dispatch(duplicateItem({ path: `${path}.items`, value: item })); const handleDuplicateSection = () => { const newSection: SectionRecord = { name: `${heading}`, type: type, visible: true, columns: 2, items: [], isDuplicated: true }; dispatch(duplicateSection({ value: newSection, type })); }; return ( <>
{addMore ? (
) : ( <> )} ); }; export default Section;