From 863a5594f5c2467cbc4bb2964d2080ca0b5658cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 14 Mar 2024 16:18:46 +0100 Subject: [PATCH] Add contact information handling to RFF component --- app/Livewire/BillingPortal/RFF.php | 40 +++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/app/Livewire/BillingPortal/RFF.php b/app/Livewire/BillingPortal/RFF.php index b6b374edb278..c5bdbbf71312 100644 --- a/app/Livewire/BillingPortal/RFF.php +++ b/app/Livewire/BillingPortal/RFF.php @@ -21,6 +21,12 @@ class RFF extends Component { public array $context; + public string $contact_first_name; + + public string $contact_last_name; + + public string $contact_email; + #[On('passed-required-fields-check')] public function continue(): void { @@ -29,11 +35,43 @@ class RFF extends Component $this->dispatch('purchase.next'); } + public function handleSubmit() + { + $data = $this->validate([ + 'contact_first_name' => 'required', + 'contact_last_name' => 'required', + 'contact_email' => 'required|email:rfc', + ]); + + $contact = auth()->guard('contact'); + + $contact->user()->update([ + 'first_name' => $data['contact_first_name'], + 'last_name' => $data['contact_last_name'], + 'email' => $data['contact_email'], + ]); + + $this->dispatch('purchase.context', property: 'contact', value: auth()->guard('contact')->user()); + + $this->dispatch('purchase.next'); + } + + public function mount(): void + { + $this->contact_first_name = $this->context['contact']['first_name']; + $this->contact_last_name = $this->context['contact']['last_name']; + $this->contact_email = $this->context['contact']['email']; + } + public function render() { - $gateway = CompanyGateway::findOrFail($this->context['form']['company_gateway_id']); + $gateway = CompanyGateway::find($this->context['form']['company_gateway_id']); $countries = Cache::get('countries'); + if ($gateway === null) { + return view('billing-portal.v3.rff-basic'); + } + return view('billing-portal.v3.rff', [ 'gateway' => $gateway->driver( auth()->guard('contact')->user()->client