Don't allow to create more than one child campaign per user

This commit is contained in:
Kasia Jarmołkowicz 2018-05-30 22:25:16 +02:00 committed by Eric Schultz
parent aaddc721bf
commit 6b94b10979
2 changed files with 32 additions and 21 deletions

View file

@ -111,6 +111,10 @@ class CampaignsController < ApplicationController
session[:donor_signup_url] = request.env["REQUEST_URI"]
@nonprofit = Nonprofit.find_by_id(params[:npo_id])
@parent_campaign = Campaign.find_by_id(params[:campaign_id])
@child_campaign = Campaign.where(
profile_id: current_user.profile.id,
parent_campaign_id: @parent_campaign.id
).first if @parent_campaign
@profile = current_user.profile if current_user
end

View file

@ -116,29 +116,36 @@
</li>
<li>
<p class='strong u-marginBottom--15'>Start your campaign</p>
<span class='annot'>5 minutes</span>
<div class='u-paddingLeft--20 u-maxWidth--500'>
<p>Use our simple wizard to create your campaign for
<strong>
<!--= show_if selected_result -->
<!--= put selected_result.name -->.
</strong>
<strong>
<!--= hide_if selected_result -->
your favorite nonprofit.
</strong>
</p>
<p><small>If you need any further help setting up your campaign, check out <a target='_blank' href='/help/peer-to-peer-campaigns-essentials-package-feature'>this handy article</a>.</small></p>
<div class='u-centered u-padding--15'>
<button class='button orange'>
<!--= show_if (all is_logged_in is_confirmed selected_result) -->
<!--= on 'click' (open_modal selected_result.modal_id) -->
Start Campaign
</button>
<% if !@child_campaign %>
<p class='strong u-marginBottom--15'>Start your campaign</p>
<span class='annot'>5 minutes</span>
<div class='u-paddingLeft--20 u-maxWidth--500'>
<p>Use our simple wizard to create your campaign for
<strong>
<!--= show_if selected_result -->
<!--= put selected_result.name -->.
</strong>
<strong>
<!--= hide_if selected_result -->
your favorite nonprofit.
</strong>
</p>
<p><small>If you need any further help setting up your campaign, check out <a target='_blank' href='/help/peer-to-peer-campaigns-essentials-package-feature'>this handy article</a>.</small></p>
<div class='u-centered u-padding--15'>
<button class='button orange'>
<!--= show_if (all is_logged_in is_confirmed selected_result) -->
<!--= on 'click' (open_modal selected_result.modal_id) -->
Start Campaign
</button>
</div>
</div>
</div>
<% else %>
<p>
Seems like you already have a campaign for that cause! <%= link_to "Click here to see it", @child_campaign.url %>.
</p>
<% end %>
</li>
</ul>
</div>
</main>