From 3dfe5db4fd76441dbf98fe87512f1edd2d51a081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 9 Feb 2024 19:20:33 +0100 Subject: [PATCH 1/2] Refactor SubscriptionPlanSwitch class and add handleRff method --- app/Livewire/SubscriptionPlanSwitch.php | 34 ++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/app/Livewire/SubscriptionPlanSwitch.php b/app/Livewire/SubscriptionPlanSwitch.php index a4518efe8453..df39bade4180 100644 --- a/app/Livewire/SubscriptionPlanSwitch.php +++ b/app/Livewire/SubscriptionPlanSwitch.php @@ -44,7 +44,7 @@ class SubscriptionPlanSwitch extends Component /** * @var ClientContact */ - public $contact; + public ClientContact $contact; /** * @var array @@ -66,6 +66,7 @@ class SubscriptionPlanSwitch extends Component 'invoice' => null, 'company_gateway_id' => null, 'payment_method_id' => null, + 'show_rff' => false, ]; /** @@ -75,6 +76,12 @@ class SubscriptionPlanSwitch extends Component public $company; + public ?string $first_name; + + public ?string $last_name; + + public ?string $email; + public function mount() { MultiDB::setDb($this->company->db); @@ -84,6 +91,31 @@ class SubscriptionPlanSwitch extends Component $this->methods = $this->contact->client->service()->getPaymentMethods($this->amount); $this->hash = Str::uuid()->toString(); + + $this->state['show_rff'] = auth()->guard('contact')->user()->showRff(); + + $this->first_name = $this->contact->first_name; + + $this->last_name = $this->contact->last_name; + + $this->email = $this->contact->email; + } + + public function handleRff() + { + $this->validate([ + 'first_name' => ['required'], + 'last_name' => ['required'], + 'email' => ['required', 'email'], + ]); + + $this->contact->update([ + 'first_name' => $this->first_name, + 'last_name' => $this->last_name, + 'email' => $this->email, + ]); + + $this->state['show_rff'] = false; } public function handleBeforePaymentEvents(): void From 56c2bdda2029024d23b24b597a6a68d42ba16c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 9 Feb 2024 19:20:38 +0100 Subject: [PATCH 2/2] Refactor subscription plan switch component and add form validation --- .../subscription-plan-switch.blade.php | 47 +++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php b/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php index c1be68fc7043..91520780ad8c 100644 --- a/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php @@ -1,9 +1,47 @@
- + @if($errors->any()) +
+ @foreach($errors->all() as $error) +

{{ $error }}

+ @endforeach +
+ @endif + + @if($state['show_rff']) +
+ @if(strlen(auth()->guard('contact')->user()->first_name) === 0) +
+ + +
+ @endif - @if($amount > 0) + @if(strlen(auth()->guard('contact')->user()->last_name) === 0) +
+ + +
+ @endif + + @if(strlen(auth()->guard('contact')->user()->email) === 0) +
+ + +
+ @endif + +
+ +
+
+ @endif + + + @if($amount > 0 && $state['show_rff'] == false)
@@ -33,6 +71,9 @@ + + + @@ -62,7 +103,7 @@ @endif
- @elseif($amount <= 0) + @elseif($amount <= 0 && $state['show_rff'] == false)