// #region [Imports] =================================================================================================== import { useEffect, useState } from 'react'; import { useHistory } from 'react-router-dom'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import { Card, Button, Empty, List, Typography, Space, Popconfirm, Tag, Row, Col } from 'antd'; import { DeleteOutlined, EyeOutlined, CrownOutlined, ThunderboltOutlined } from '@ant-design/icons'; // Components import AIIcon from '../../components/AIIcon'; // Types import { IStore } from '../../types/store'; import { ISavedAITemplate } from '../../types/couponTemplates'; // Actions import { CouponTemplatesActions } from '../../store/actions/couponTemplates'; // Helpers import { getPathPrefix } from '../../helpers/utils'; // #endregion [Imports] // #region [Variables] ================================================================================================= declare var acfwAdminApp: any; const { Text, Title, Paragraph } = Typography; const { readSavedAITemplates, deleteSavedAITemplate, loadSavedAITemplate } = CouponTemplatesActions; // #endregion [Variables] // #region [Interfaces]================================================================================================= interface IActions { readSavedAITemplates: typeof readSavedAITemplates; deleteSavedAITemplate: typeof deleteSavedAITemplate; loadSavedAITemplate: typeof loadSavedAITemplate; } interface IProps { savedTemplates: ISavedAITemplate[]; actions: IActions; } // #endregion [Interfaces] // #region [Component] ================================================================================================= const AITemplates = (props: IProps) => { const { savedTemplates, actions } = props; const [loading, setLoading] = useState(false); const history = useHistory(); const pathPrefix = getPathPrefix(); const isPremiumActive = acfwAdminApp.is_acfwp_active; const premiumLink = acfwAdminApp.coupon_templates_page.link; const { labels } = acfwAdminApp.coupon_templates_page; useEffect(() => { if (isPremiumActive) { setLoading(true); actions.readSavedAITemplates({ successCB: () => setLoading(false), failCB: () => setLoading(false) }); } }, [isPremiumActive, actions]); const handleUseTemplate = (id: string) => { actions.loadSavedAITemplate({ id, successCB: (response) => { // Navigate to template form history.push(`${pathPrefix}admin.php?page=acfw-coupon-templates&id=${id}`); }, failCB: undefined, }); }; const handleDeleteTemplate = (id: string) => { actions.deleteSavedAITemplate({ id, processingCB: undefined, successCB: undefined, failCB: undefined, }); }; // Premium Upsell if (!isPremiumActive) { return (
{labels.ai_upsell_title} {labels.ai_upsell_description}
  • {labels.ai_upsell_feature_save}
  • {labels.ai_upsell_feature_reuse}
  • {labels.ai_upsell_feature_organize}
  • {labels.ai_upsell_feature_premium}

); } // Empty State if (!loading && savedTemplates.length === 0) { return ( {labels.no_ai_templates}
{labels.no_ai_templates_desc} } >
); } // Templates List return (
( } onClick={() => handleUseTemplate(template.id)} key="use"> {labels.use_template} , handleDeleteTemplate(template.id)} okText={labels.delete_template} cancelText={labels.cancel} okButtonProps={{ danger: true }} key="delete" > , ]} > {template.title} }> {labels.ai_generated} } description={
{template.prompt && ( {template.prompt} )} Created: {new Date(template.created_at).toLocaleDateString()}
} />
)} />
); }; const mapStateToProps = (state: IStore) => ({ savedTemplates: state.couponTemplates?.savedAITemplates ?? [], }); const mapDispatchToProps = (dispatch: any) => ({ actions: bindActionCreators({ readSavedAITemplates, deleteSavedAITemplate, loadSavedAITemplate }, dispatch), }); export default connect(mapStateToProps, mapDispatchToProps)(AITemplates); // #endregion [Component]