import React, { useState } from 'react'; import { Button, Modal, Alert } from 'antd'; import { PlusCircleOutlined } from '@ant-design/icons'; import Styles from './web.pc.module.less'; import Upsert from '../upsert'; import { OakAttrNotNullException, OakException } from 'oak-domain/lib/types'; import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid'; function WpProduct(props) { return null; } export default function render(props) { const { wpAccountId, wpProducts, oakFullpath, oakExecutable, canCreate, systemId } = props.data; const { t, addItem, execute, clean } = props.methods; const getNotNullMessage = (entity, attr) => { return t('notnull', { value: t(`${entity}:attr.${attr}`) }); }; const errMsg = oakExecutable instanceof OakException && (oakExecutable instanceof OakAttrNotNullException ? getNotNullMessage(oakExecutable.getEntity(), oakExecutable.getAttributes()[0]) : t(oakExecutable.message)); const [upsertId, setUpsertId] = useState(''); const U = ( { clean(); setUpsertId(''); }} closeIcon={null} onOk={async () => { await execute(); setUpsertId(''); }} okButtonProps={{ disabled: oakExecutable !== true, }} okText={t('common::confirm')} cancelText={(t('common::action.cancel'))}>
{errMsg && }
); if (wpProducts && wpProducts.length) { return (
{U}
{wpProducts.filter(ele => ele.$$createAt$$ > 1).map((ele, idx) =>
{ Modal.confirm({ title: t('confirmDelete'), content: t('areYouSure'), onOk: async () => execute(undefined, undefined, undefined, [ { entity: 'wpProduct', operation: { id: await generateNewIdAsync(), action: 'remove', data: {}, filter: { id: ele.id, }, } } ]), }); }} onUpdate={() => setUpsertId(ele.id)}/>
)}
{canCreate && }
); } return (
{U}
{canCreate ? { const id = addItem({}); setUpsertId(id); }}/> : t('noData')}
); }