1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Make RFF proxy for RequiredClientInfo

This commit is contained in:
Benjamin Beganović 2024-02-22 14:07:57 +01:00
parent 938ffbe66b
commit 6346e7a92f
2 changed files with 26 additions and 68 deletions

View File

@ -12,54 +12,32 @@
namespace App\Livewire\BillingPortal;
use App\Models\ClientContact;
use App\Models\CompanyGateway;
use Illuminate\Support\Facades\Cache;
use Livewire\Attributes\On;
use Livewire\Component;
class RFF extends Component
{
public array $context;
public ClientContact $contact;
public ?string $contact_first_name;
public ?string $contact_last_name;
public ?string $contact_email;
public function handleRff()
#[On('passed-required-fields-check')]
public function continue(): void
{
$validated = $this->validate([
'contact_first_name' => ['required'],
'contact_last_name' => ['required'],
// 'contact_email' => ['sometimes', 'email'],
]);
$this->contact = auth()->guard('contact')->user();
$this->contact->first_name = $validated['contact_first_name'];
$this->contact->last_name = $validated['contact_last_name'];
$this->contact->save();
$this->contact_first_name = $this->contact->first_name;
$this->contact_last_name = $this->contact->last_name;
$this->contact_email = $this->contact->email;
$this->dispatch('purchase.context', property: 'contact.first_name', value: $this->contact->first_name);
$this->dispatch('purchase.context', property: 'contact.last_name', value: $this->contact->last_name);
$this->dispatch('purchase.next');
}
public function mount()
{
/** @var \App\Models\ClientContact $contact */
$contact = auth()->guard('contact')->user();
if ($contact->showRff() === false) {
$this->dispatch('purchase.next');
}
}
public function render()
{
return view('billing-portal.v3.rff');
$gateway = CompanyGateway::findOrFail($this->context['form']['company_gateway_id']);
$countries = Cache::get('countries');
return view('billing-portal.v3.rff', [
'gateway' => $gateway->driver(
auth()->guard('contact')->user()->client
),
'countries' => $countries,
'company' => $gateway->company,
]);
}
}

View File

@ -9,34 +9,14 @@
</div>
@endif
<form wire:submit="handleRff">
@csrf
@if(strlen(auth()->guard('contact')->user()->first_name) === 0)
<div class="col-auto mt-3">
<label for="first_name" class="input-label">{{ ctrans('texts.first_name') }}</label>
<input id="first_name" class="input w-full" wire:model="contact_first_name" />
</div>
@endif
@if(strlen(auth()->guard('contact')->user()->last_name) === 0)
<div class="col-auto mt-3 @if(auth()->guard('contact')->user()->last_name) !== 0) hidden @endif">
<label for="last_name" class="input-label">{{ ctrans('texts.last_name') }}</label>
<input id="last_name" class="input w-full" wire:model="contact_last_name" />
</div>
@endif
@if(strlen(auth()->guard('contact')->user()->email) === 0)
<div class="col-auto mt-3 @if(auth()->guard('contact')->user()->email) !== 0) hidden @endif">
<label for="email" class="input-label">{{ ctrans('texts.email') }}</label>
<input id="email" class="input w-full" wire:model="contact_email" />
</div>
@endif
<button
type="submit"
class="button button-block bg-primary text-white mt-4">
{{ ctrans('texts.next') }}
</button>
</form>
</div>
<div>
@livewire('required-client-info', [
'fields' => method_exists($gateway, 'getClientRequiredFields') ? $gateway->getClientRequiredFields() : [],
'contact' => auth()->guard('contact')->user(),
'countries' => $countries,
'company' => $company,
'company_gateway_id' => $gateway->company_gateway ? $gateway->company_gateway->id : $gateway->id,
'form_only' => true
])
</div>
</div>