import { FC, useEffect, useState } from 'react'; import { FaEdit, FaPen, FaPlus, FaTrophy } from 'react-icons/fa'; import { LocalizeText, ProductTypeEnum, SanitizeHtml } from '../../../../../api'; import { Text } from '../../../../../common'; import { useCatalog } from '../../../../../hooks'; import { useCatalogAdmin } from '../../../CatalogAdminContext'; import { CatalogAddOnBadgeWidgetView } from '../widgets/CatalogAddOnBadgeWidgetView'; import { CatalogItemGridWidgetView } from '../widgets/CatalogItemGridWidgetView'; import { CatalogPurchaseWidgetView } from '../widgets/CatalogPurchaseWidgetView'; import { CatalogTotalPriceWidget } from '../widgets/CatalogTotalPriceWidget'; import { CatalogViewProductWidgetView } from '../widgets/CatalogViewProductWidgetView'; import { CatalogLayoutProps } from './CatalogLayout.types'; export const CatalogLayoutTrophiesView: FC = props => { const { page = null } = props; const [ trophyText, setTrophyText ] = useState(''); const { currentOffer = null, setPurchaseOptions = null } = useCatalog(); const catalogAdmin = useCatalogAdmin(); const adminMode = catalogAdmin?.adminMode ?? false; useEffect(() => { if(!currentOffer) return; setPurchaseOptions(prevValue => { const newValue = { ...prevValue }; newValue.extraData = trophyText; return newValue; }); }, [ currentOffer, trophyText, setPurchaseOptions ]); const canPurchase = currentOffer && trophyText.trim().length > 0; return (
{ /* Admin: quick actions */ } { adminMode && !catalogAdmin.editingPageData &&
} { /* Selected trophy card */ } { currentOffer ?
{ /* Preview */ }
{ (currentOffer.product.productType !== ProductTypeEnum.BADGE) ? <> : }
{ /* Info */ }
{ currentOffer.localizationName } { adminMode && catalogAdmin.setEditingOffer(currentOffer) } /> }
{ adminMode &&
ID: { currentOffer.product.productClassId } Offer: { currentOffer.offerId }
} { !canPurchase && { LocalizeText('catalog.trophies.write.hint') } }
:
{ !!page.localization.getImage(1) && }
{ LocalizeText('catalog.trophies.title') }
} { /* Trophy inscription */ }
{ LocalizeText('catalog.trophies.inscription') } 180 ? 'text-danger font-bold' : 'text-muted' }` }>{ trophyText.length }/200