Refactor for switch plans

This commit is contained in:
David Bomba 2022-09-02 10:38:27 +10:00
parent 59ac21662d
commit a43f30adbc
3 changed files with 31 additions and 8 deletions

View File

@ -56,6 +56,7 @@ class SubscriptionPlanSwitch extends Component
*/
public $total;
public $hide_button = false;
/**
* @var array
*/
@ -139,12 +140,20 @@ class SubscriptionPlanSwitch extends Component
public function handlePaymentNotRequired()
{
return $this->target->service()->createChangePlanCredit([
$this->hide_button = true;
$response = $this->target->service()->createChangePlanCredit([
'recurring_invoice' => $this->recurring_invoice,
'subscription' => $this->subscription,
'target' => $this->target,
'hash' => $this->hash,
]);
$this->hide_button = true;
$this->dispatchBrowserEvent('redirectRoute', ['route' => $response]);
// return redirect($response);
}
public function render()

View File

@ -477,10 +477,14 @@ class SubscriptionService
nlog($response);
if($credit)
return $this->handleRedirect('/client/credits/'.$credit->hashed_id);
else
return $this->handleRedirect('/client/credits');
if($credit){
// return $this->handleRedirect('/client/credits/'.$credit->hashed_id);
return '/client/credits/'.$credit->hashed_id;
}
else{
// return $this->handleRedirect('/client/credits');
return '/client/credits';
}
}

View File

@ -1,3 +1,4 @@
<div>
<div class="grid grid-cols-12 gap-8 mt-8">
<div class="col-span-12 md:col-span-5 md:col-start-4 px-4 py-5">
<!-- Total price -->
@ -62,6 +63,7 @@
</div>
</div>
@elseif($amount <= 0)
<div class="relative flex justify-center text-sm leading-5">
<h1 class="text-2xl font-bold tracking-wide bg-gray-100 px-6 py-0">
{{ ctrans('texts.total') }}: {{ \App\Utils\Number::formatMoney($amount, $subscription->company) }}
@ -69,12 +71,20 @@
</div>
<div class="relative flex justify-center text-sm leading-5 mt-10">
<button wire:click="handlePaymentNotRequired" class="px-3 py-2 border rounded mr-4 hover:border-blue-600">
{{ ctrans('texts.click_to_continue') }}
<button wire:click="handlePaymentNotRequired" class="px-3 py-2 border rounded mr-4 hover:border-blue-600" wire:loading.attr="disabled" @if($hide_button) disabled @endif>
@if($hide_button) {{ ctrans('texts.loading') }} @else {{ ctrans('texts.click_to_continue') }} @endif
</button>
</div>
@endif
</div>
</div>
<script defer>
window.addEventListener('redirectRoute', event => {
window.location.href = event.detail.route;
})
</script>
</div>