import React, { ReactNode } from 'react'; import { Link } from 'react-router-dom'; import { Button, Popconfirm, message, Tag } from 'antd'; import { UserProposal, STATUS } from 'types'; import { deletePendingProposal, publishPendingProposal } from 'modules/users/actions'; import './ProfilePending.less'; import { connect } from 'react-redux'; import { AppState } from 'store/reducers'; interface OwnProps { proposal: UserProposal; onPublish: (id: UserProposal['proposalId']) => void; } interface StateProps { user: AppState['auth']['user']; } interface DispatchProps { deletePendingProposal: typeof deletePendingProposal; publishPendingProposal: typeof publishPendingProposal; } type Props = OwnProps & StateProps & DispatchProps; const STATE = { isDeleting: false, isPublishing: false, }; type State = typeof STATE; class ProfilePending extends React.Component { state = STATE; render() { const { status, title, proposalId, rejectReason } = this.props.proposal; const { isDeleting, isPublishing } = this.state; const isDisableActions = isDeleting || isPublishing; const st = { [STATUS.APPROVED]: { color: 'green', tag: 'Approved', blurb:
You may publish this proposal when you are ready.
, }, [STATUS.REJECTED]: { color: 'red', tag: 'Rejected', blurb: ( <>
This proposal was rejected for the following reason:
{rejectReason}
You may edit this proposal and re-submit it for approval.
), }, [STATUS.STAKING]: { color: 'purple', tag: 'Staking', blurb: (
Awaiting staking contribution, you will recieve an email when staking has been confirmed. If you staked this proposal you may check its status under the "funded" tab.
), }, [STATUS.PENDING]: { color: 'orange', tag: 'Pending', blurb: (
You will receive an email when this proposal has completed the review process.
), }, } as { [key in STATUS]: { color: string; tag: string; blurb: ReactNode } }; return (
{title} {st[status].tag}
{st[status].blurb}
{STATUS.APPROVED === status && ( )} {STATUS.REJECTED === status && ( )} this.handleDelete()} >
); } private handlePublish = async () => { const { user, proposal: { proposalId }, onPublish, } = this.props; if (!user) return; this.setState({ isPublishing: true }); try { await this.props.publishPendingProposal(user.userid, proposalId); onPublish(proposalId); } catch (e) { message.error(e.message || e.toString()); this.setState({ isPublishing: false }); } }; private handleDelete = async () => { const { user, proposal: { proposalId }, } = this.props; if (!user) return; this.setState({ isDeleting: true }); try { await this.props.deletePendingProposal(user.userid, proposalId); message.success('Proposal deleted.'); } catch (e) { message.error(e.message || e.toString()); this.setState({ isDeleting: false }); } }; } export default connect( state => ({ user: state.auth.user, }), { deletePendingProposal, publishPendingProposal, }, )(ProfilePending);