Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change how we do default plan #2256

Merged
merged 4 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions www/css/account.css
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ body.theme-b {

.billing-container {
width: 100%;
position: relative;
}

@media (min-width: 1400px) {
Expand Down Expand Up @@ -1872,3 +1873,12 @@ TEMP FIX FOR UPGRADE
color: white;
font-weight: 600;
}

.subscription-total {
position: absolute;
bottom: 0;
margin-bottom: 20px;
}
.subscription-total li {
padding: 1rem 0;
}
45 changes: 32 additions & 13 deletions www/templates/account/includes/signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@
</div>
<div class="wpt-plan-set annual-plans">
<?php

$renewalDate = $newDate = date('Y-m-d', strtotime(' + 1 years'));

foreach ($annual_plans as $key => $plan) :
$selected = ($key === 1) ? 'checked' : '';
$plan_block = <<<HTML
<div class="form-wrapper-radio">
<input type="radio" id="annual-{$plan['id']}" name="plan" value="{$plan['id']}" required {$selected}/>
<input type="radio" id="annual-{$plan['id']}" name="plan" value="{$plan['id']}" data-cost="{$plan['annual_price']}" data-cycle="{$renewalDate}" required />
<label class="wpt-plan card" for="annual-{$plan['id']}">
<h5>{$plan['name']}</h5>
<div><strong>\${$plan['annual_price']}</strong>/Year</div>
Expand All @@ -235,17 +235,19 @@
endforeach; ?>
</div>
<div class="wpt-plan-set monthly-plans">
<?php foreach ($monthly_plans as $key => $plan) :
<?php
$renewalDateMonthly = $newDate = date('Y-m-d', strtotime('+ 1 month'));
foreach ($monthly_plans as $key => $plan) :
$plan_block = <<<HTML
<div class="form-wrapper-radio">
<input type="radio" id="monthly-{$plan['id']}" name="plan" value="{$plan['id']}" required />
<label class="card wpt-plan" for="monthly-{$plan['id']}">
<h5>{$plan['name']}</h5>
<div><strong>\${$plan['price']}</strong>/Month</div>
<span aria-hidden="true" class="pill-button yellow">Select</span>
</label>
</div>
HTML;
<div class="form-wrapper-radio">
<input type="radio" id="monthly-{$plan['id']}" name="plan" value="{$plan['id']}" data-cost="{$plan['price']}" data-cycle="{$renewalDateMonthly}" required />
<label class="card wpt-plan" for="monthly-{$plan['id']}">
<h5>{$plan['name']}</h5>
<div><strong>\${$plan['price']}</strong>/Month</div>
<span aria-hidden="true" class="pill-button yellow">Select</span>
</label>
</div>
HTML;
echo $plan_block;
endforeach; ?>
</div>
Expand Down Expand Up @@ -299,6 +301,11 @@
</div>
</div>
</div> <!-- /.billing-info-section -->

<ul class="subscription-total">
<li><strong>Total due today:</strong> <span id="data-plan-total"> </span></li>
<li><strong>Next payment due:</strong> <span id="data-plan-renewal"> </span></li>
</ul>
</div> <!-- /.billing-container -->

<div class="card plan-details-container">
Expand Down Expand Up @@ -329,6 +336,18 @@
<script src="https://js.braintreegateway.com/web/dropin/1.33.0/js/dropin.min.js"></script>

<script>
const radios = document.querySelectorAll('input[name="plan"]')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add a listener for each radio button? Wondering if a single listener at a parent element might be easier?

maybe that's too much and we can worry about it later

for (const radio of radios) {
radio.onclick = (e) => {
document.getElementById('data-plan-total').innerText = "$"+e.target.dataset.cost;
document.getElementById('data-plan-renewal').innerText = e.target.dataset.cycle;
}
}
// check default
document.getElementsByName("plan")[1]['checked'] = true;
document.getElementById('data-plan-total').innerText = "$"+document.getElementsByName("plan")[1].dataset.cost
document.getElementById('data-plan-renewal').innerText = document.getElementsByName("plan")[1].dataset.cycle

braintree.dropin.create({
authorization: "<?= $bt_client_token ?>",
container: '#braintree-container',
Expand Down