import React from 'react'; import { connect } from 'react-redux'; import BN from 'bn.js'; import { Input, Form, Icon, Select, Alert, Popconfirm, message, Radio } from 'antd'; import { SelectValue } from 'antd/lib/select'; import { RadioChangeEvent } from 'antd/lib/radio'; import { PROPOSAL_CATEGORY, CATEGORY_UI } from 'api/constants'; import { ProposalDraft, RFP } from 'types'; import { getCreateErrors } from 'modules/create/utils'; import { typedKeys } from 'utils/ts'; import { Link } from 'react-router-dom'; import { unlinkProposalRFP } from 'modules/create/actions'; import { AppState } from 'store/reducers'; interface OwnProps { proposalId: number; initialState?: Partial; updateForm(form: Partial): void; } interface StateProps { isUnlinkingProposalRFP: AppState['create']['isUnlinkingProposalRFP']; unlinkProposalRFPError: AppState['create']['unlinkProposalRFPError']; } interface DispatchProps { unlinkProposalRFP: typeof unlinkProposalRFP; } type Props = OwnProps & StateProps & DispatchProps; interface State extends Partial { title: string; brief: string; category?: PROPOSAL_CATEGORY; target: string; rfp?: RFP; } class CreateFlowBasics extends React.Component { constructor(props: Props) { super(props); this.state = { title: '', brief: '', category: undefined, target: '', ...(props.initialState || {}), }; } componentDidUpdate(prevProps: Props) { const { unlinkProposalRFPError, isUnlinkingProposalRFP } = this.props; if ( unlinkProposalRFPError && unlinkProposalRFPError !== prevProps.unlinkProposalRFPError ) { console.error('Failed to unlink request:', unlinkProposalRFPError); message.error('Failed to unlink request'); } else if (!isUnlinkingProposalRFP && prevProps.isUnlinkingProposalRFP) { this.setState({ rfp: undefined }); message.success('Unlinked proposal from request'); } } render() { const { isUnlinkingProposalRFP } = this.props; const { title, brief, category, target, rfp, rfpOptIn } = this.state; const errors = getCreateErrors(this.state, true); const rfpOptInRequired = rfp && (rfp.matching || (rfp.bounty && new BN(rfp.bounty).gtn(0))); return (
{rfp && ( This proposal is for the open request{' '} {rfp.title} . If you didn’t mean to do this, or want to unlink it,{' '} click here {' '} to do so. } showIcon /> )} {rfpOptInRequired && (
This RFP offers either a bounty or matching. This will require ZFGrants to fulfill{' '} KYC {' '} due dilligence. In the event your proposal is successful, you will need to provide identifying information to ZFGrants. Yes, I am willing to provide KYC information No, I do not wish to provide KYC information and understand I will not receive any matching or bounty funds from ZFGrants
} /> )} ); } private handleInputChange = ( event: React.ChangeEvent, ) => { const { value, name } = event.currentTarget; this.setState({ [name]: value } as any, () => { this.props.updateForm(this.state); }); }; private handleCategoryChange = (value: SelectValue) => { this.setState({ category: value as PROPOSAL_CATEGORY }, () => { this.props.updateForm(this.state); }); }; private handleRfpOptIn = (e: RadioChangeEvent) => { this.setState({ rfpOptIn: e.target.value }, () => { this.props.updateForm(this.state); }); }; private unlinkRfp = () => { this.props.unlinkProposalRFP(this.props.proposalId); }; } export default connect( state => ({ isUnlinkingProposalRFP: state.create.isUnlinkingProposalRFP, unlinkProposalRFPError: state.create.unlinkProposalRFPError, }), { unlinkProposalRFP }, )(CreateFlowBasics);