import React from 'react'; // Utils import { MESSAGES } from '../../../../utils/message'; import { TemplateCategory, TemplateRecord, TemplateType } from '../customTemplateSection'; // Components import Typography from '../../../GenericUIBlocks/Typography'; import GeneralSelect from '../../../GenericUIBlocks/GeneralSelect'; import Input from '../../../GenericUIBlocks/Input'; // Icons import DesignIcon from '../../../../assets/images/templates/template-default-design'; import dummyTemplateIcon from '../../../../assets/images/templates/template-default-design'; // styles import './styles.scss'; const templateTextStyles: React.CSSProperties = { color: `#000`, fontSize: `12px`, fontStyle: `normal`, fontWeight: `500`, lineHeight: `normal`, marginBottom: `16px`, }; type CustomTemplateSectionProps = { selectedCategory: TemplateCategory | null, templateCategories: TemplateCategory[], currentTemplateType: TemplateType | undefined, templateTypes: TemplateType[] | null | undefined, search: any, searchApplied: boolean, loader: boolean, platformName: any, myTemplates: TemplateRecord[], teamTemplates: TemplateRecord[], olcTemplates: TemplateRecord[], setSearch: any, handleSearch: any, removeSearchInput: any, searchKeyDown: any, setCurrentTemplateType: any, setSelectedCategory: any, handleLoadTemplateModel: any, handleDialogChange: any, }; const SideBarSelction = (props: CustomTemplateSectionProps) => { const { selectedCategory, templateCategories, currentTemplateType, templateTypes, search, searchApplied, loader, platformName, myTemplates, teamTemplates, olcTemplates, setSearch, handleSearch, removeSearchInput, searchKeyDown, setCurrentTemplateType, setSelectedCategory, handleLoadTemplateModel, handleDialogChange, } = props; const uniqueCurrentTemplates = Array.from( new Map(olcTemplates.map((item) => [item.id, item])).values() ); return (
{currentTemplateType?.id === '3' && templateCategories?.length > 1 && (
)}
setSearch(e.target.value.trimStart())} placeholder="Search by template name" inputIcon={true} onClick={handleSearch} searchApplied={searchApplied} removeSearchInput={removeSearchInput} />
{loader ? (
{MESSAGES.TEMPLATE.LOADING_TEMPLATE}
) : currentTemplateType?.id === '1' ? ( <>
handleDialogChange('design-own')} > {MESSAGES.TEMPLATE.DESIGN_NEW}
{myTemplates.length ? ( myTemplates.map((template: any, i: number) => (
handleLoadTemplateModel(template)} > {template.title} { currentTarget.onerror = null; // prevents looping //@ts-ignore currentTarget.src = dummyTemplateIcon; currentTarget.classList.add('dummy-image'); }} />
)) ) : (
{MESSAGES.TEMPLATE.NO_MY_TEMPLATES}
)} ) : currentTemplateType?.id === '2' ? ( <> {teamTemplates.length ? ( teamTemplates?.map((template: any, i: number) => (
handleLoadTemplateModel(template)} > {template.title} { currentTarget.onerror = null; // prevents looping //@ts-ignore currentTarget.src = dummyTemplateIcon; currentTarget.classList.add('dummy-image'); }} />
)) ) : (
{MESSAGES.TEMPLATE.NO_TEAM_TEMPLATES}
)} ) : currentTemplateType?.id === '3' ? ( <> {uniqueCurrentTemplates.length ? ( uniqueCurrentTemplates?.map((template, i) => (
handleLoadTemplateModel(template)} > {template.title} { currentTarget.onerror = null; // prevents looping //@ts-ignore currentTarget.src = dummyTemplateIcon; currentTarget.classList.add('dummy-image'); }} />
)) ) : (
{platformName ? `No ${platformName} Templates to show` : MESSAGES.TEMPLATE.NO_OLC_TEMPLATES}
)} ) : null}
); } export default SideBarSelction;