From 4f21b6e3d827c283dca57e161f3412bd7ab2faca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 29 Feb 2024 17:36:32 +0100 Subject: [PATCH] Add authentication classes and update steps in Purchase.php --- app/Livewire/BillingPortal/Purchase.php | 47 ++++++++++++++++++------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/app/Livewire/BillingPortal/Purchase.php b/app/Livewire/BillingPortal/Purchase.php index 63049cae6f..ecb924bee2 100644 --- a/app/Livewire/BillingPortal/Purchase.php +++ b/app/Livewire/BillingPortal/Purchase.php @@ -13,6 +13,8 @@ namespace App\Livewire\BillingPortal; use App\Libraries\MultiDB; +use App\Livewire\BillingPortal\Authentication\Login; +use App\Livewire\BillingPortal\Authentication\Register; use App\Livewire\BillingPortal\Authentication\RegisterOrLogin; use App\Livewire\BillingPortal\Cart\Cart; use App\Livewire\BillingPortal\Payments\Methods; @@ -65,17 +67,13 @@ class Purchase extends Component 'id' => 'rff', 'dependencies' => [Login::class, RegisterOrLogin::class, Register::class], ], + Submit::class => [ + 'id' => 'submit', + 'dependencies' => [Methods::class], + ], ]; - - public static array $steps = [ - Setup::class, - RegisterOrLogin::class, - Cart::class, - Methods::class, - RFF::class, - Submit::class, - ]; + public array $steps = []; public array $context = []; @@ -99,12 +97,10 @@ class Purchase extends Component #[On('purchase.next')] public function handleNext(): void { - - if ($this->step < count($this->steps) - 1) { + if (count($this->steps) >= 1 && $this->step < count($this->steps) - 1) { $this->step++; + $this->id = Str::uuid(); } - - $this->id = Str::uuid(); } #[On('purchase.forward')] @@ -133,8 +129,33 @@ class Purchase extends Component return "summary-{$this->id}"; } + public static function defaultSteps() { + return [ + Setup::class, + Cart::class, + RegisterOrLogin::class, + Methods::class, + Submit::class, + ]; + } + public function mount() { + $classes = collect(self::$dependencies)->mapWithKeys(fn($dependency, $class) => [$dependency['id'] => $class])->toArray(); + + if ($this->subscription->steps) { + $steps = collect(explode(',', $this->subscription->steps)) + ->map(fn($step) => $classes[$step]) + ->toArray(); + + $this->steps = [ + Setup::class, + ...$steps, + ]; + } else { + $this->steps = self::defaultSteps(); + } + $this->id = Str::uuid(); MultiDB::setDb($this->db);