Add Cart component and handle context in Purchase class

This commit is contained in:
Benjamin Beganović 2024-02-12 18:55:03 +01:00
parent 5bac6253f9
commit 1290c19339
2 changed files with 32 additions and 15 deletions

View File

@ -13,6 +13,7 @@
namespace App\Livewire\BillingPortal; namespace App\Livewire\BillingPortal;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use App\Livewire\BillingPortal\Cart\Cart;
use App\Models\Subscription; use App\Models\Subscription;
use Livewire\Attributes\Computed; use Livewire\Attributes\Computed;
use Livewire\Attributes\On; use Livewire\Attributes\On;
@ -26,6 +27,8 @@ class Purchase extends Component
public array $request_data; public array $request_data;
public string $hash;
public ?string $campaign; public ?string $campaign;
// //
@ -34,6 +37,7 @@ class Purchase extends Component
public array $steps = [ public array $steps = [
Setup::class, Setup::class,
Cart::class,
Authentication::class, Authentication::class,
Example::class, Example::class,
]; ];
@ -41,9 +45,14 @@ class Purchase extends Component
public array $context = []; public array $context = [];
#[On('purchase.context')] #[On('purchase.context')]
public function handleContext(string $property, $value): void public function handleContext(string $property, $value): self
{ {
$this->context[$property] = $value; $this->context[$property] = $value;
// The following may not be needed, as we can pass arround $context.
// cache()->set($this->hash, $this->context);
return $this;
} }
#[On('purchase.next')] #[On('purchase.next')]
@ -70,11 +79,11 @@ class Purchase extends Component
{ {
MultiDB::setDb($this->db); MultiDB::setDb($this->db);
$this->context = [ $this
'quantity' => 1, ->handleContext('hash', $this->hash)
'request_data' => $this->request_data, ->handleContext('quantity', 1)
'campaign' => $this->campaign, ->handleContext('request_data', $this->request_data)
]; ->handleContext('campaign', $this->campaign);
} }
public function render() public function render()

View File

@ -1,10 +1,14 @@
<div class="grid grid-cols-12"> <div class="grid grid-cols-12 bg-gray-50">
<div class="col-span-12 xl:col-span-6 bg-white flex flex-col items-center lg:h-screen"> <div
<div class="w-full p-10 lg:mt-24 md:max-w-md"> class="col-span-12 xl:col-span-6 bg-white flex flex-col items-center lg:h-screen"
>
<div class="w-full p-10 lg:mt-24 md:max-w-xl">
<img <img
class="h-8" class="h-8"
src="{{ $subscription->company->present()->logo }}" src="{{ $subscription->company->present()->logo }}"
alt="{{ $subscription->company->present()->name }}" /> alt="{{ $subscription->company->present()->name }}"
/>
<div class="my-10" id="container"> <div class="my-10" id="container">
@livewire($this->component, ['context' => $context, 'subscription' => $this->subscription], key($this->component)) @livewire($this->component, ['context' => $context, 'subscription' => $this->subscription], key($this->component))
@ -12,9 +16,13 @@
</div> </div>
</div> </div>
<div class="col-span-12 xl:col-span-6 bg-gray-50 flex flex-col items-center"> <div class="col-span-12 xl:col-span-6 flex flex-col items-center">
<div class="w-full p-10 lg:mt-24 md:max-w-3xl"> <div class="sticky top-0">
<h1 class="text-3xl">{{ $subscription->name }}</h1> <div class="w-full p-10 lg:mt-24 md:max-w-xl">
<div class="my-6 space-y-10">
<livewire:billing-portal.summary :subscription="$subscription" :context="$context" />
</div>
</div>
</div> </div>
</div> </div>
</div> </div>