From 495b50a9e92b5f5150aef7151158ca015c0ba019 Mon Sep 17 00:00:00 2001 From: Daniel Ternyak Date: Thu, 14 Mar 2019 23:24:10 -0500 Subject: [PATCH] Misc Fixes (#381) * Fix Logging typo * only allow consecutive milestone date estimates * fix typo * handle empty target * validate max proposal brief size --- backend/grant/proposal/models.py | 3 +- .../components/CreateFlow/Milestones.tsx | 32 ++++++++++++++----- frontend/client/modules/create/utils.ts | 9 ++++-- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/backend/grant/proposal/models.py b/backend/grant/proposal/models.py index 4cd9de39..1224ed5a 100644 --- a/backend/grant/proposal/models.py +++ b/backend/grant/proposal/models.py @@ -384,7 +384,7 @@ class Proposal(db.Model): self.brief = brief self.category = category self.content = content - self.target = target + self.target = target if target != '' else None self.payout_address = payout_address self.deadline_duration = deadline_duration Proposal.simple_validate(vars(self)) @@ -590,6 +590,7 @@ class Proposal(db.Model): @hybrid_property def funded(self): + target = Decimal(self.target) # apply matching multiplier funded = Decimal(self.contributed) * Decimal(1 + self.contribution_matching) diff --git a/frontend/client/components/CreateFlow/Milestones.tsx b/frontend/client/components/CreateFlow/Milestones.tsx index 4222589d..15b830eb 100644 --- a/frontend/client/components/CreateFlow/Milestones.tsx +++ b/frontend/client/components/CreateFlow/Milestones.tsx @@ -78,6 +78,11 @@ export default class CreateFlowMilestones extends React.Component milestone={milestone} index={idx} error={errors.milestones && errors.milestones[idx]} + previousMilestoneDateEstimate={ + milestones[idx - 1] && milestones[idx - 1].dateEstimated + ? moment(milestones[idx - 1].dateEstimated * 1000) + : undefined + } onChange={this.handleMilestoneChange} onRemove={this.removeMilestone} /> @@ -96,6 +101,7 @@ export default class CreateFlowMilestones extends React.Component interface MilestoneFieldsProps { index: number; milestone: CreateMilestone; + previousMilestoneDateEstimate: moment.Moment | undefined; error: Falsy | string; onChange(index: number, milestone: CreateMilestone): void; onRemove(index: number): void; @@ -107,6 +113,7 @@ const MilestoneFields = ({ error, onChange, onRemove, + previousMilestoneDateEstimate, }: MilestoneFieldsProps) => (
@@ -154,14 +161,23 @@ const MilestoneFields = ({ allowClear={false} onChange={time => onChange(index, { ...milestone, dateEstimated: time.unix() })} disabled={milestone.immediatePayout} - disabledDate={current => - current - ? current < - moment() - .subtract(1, 'month') - .endOf('month') - : false - } + disabledDate={current => { + if (!previousMilestoneDateEstimate) { + return current + ? current < + moment() + .subtract(1, 'month') + .endOf('month') + : false; + } else { + return current + ? current < + moment() + .subtract(1, 'month') + .endOf('month') || current < previousMilestoneDateEstimate + : false; + } + }} /> 140) { + errors.brief = 'Brief can only be 140 characters maximum'; + } + // Amount to raise const targetFloat = target ? parseFloat(target) : 0; if (target && !Number.isNaN(targetFloat)) { @@ -169,7 +174,7 @@ export function getCreateWarnings(form: Partial): string[] { warnings.push(` You still have pending team invitations. If you publish before they are accepted, your team will be locked in and they won’t be able to - accept join. + join. `); }