improve loading states (#66)

This commit is contained in:
Benjamin Beganović 2024-07-09 04:02:54 +02:00 committed by GitHub
parent e63598271b
commit 18cd647e43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 19 deletions

View File

@ -42,9 +42,20 @@ class PaymentMethod extends Component
HTML;
}
public function handleSelect(string $company_gateway_id, string $gateway_type_id, string $amount)
{
$this->isLoading = true;
$this->dispatch(
event: 'payment-method-selected',
company_gateway_id: $company_gateway_id,
gateway_type_id: $gateway_type_id,
amount: $amount,
);
}
public function mount()
{
$this->variables = $this->getContext()['variables'];
$this->amount = array_sum(array_column($this->getContext()['payable_invoices'], 'amount'));
@ -54,8 +65,7 @@ class PaymentMethod extends Component
if (count($this->methods) == 1) {
$this->dispatch('singlePaymentMethodFound', company_gateway_id: $this->methods[0]['company_gateway_id'], gateway_type_id: $this->methods[0]['gateway_type_id'], amount: $this->amount);
}
else {
} else {
$this->isLoading = false;
$this->dispatch('loadingCompleted');
}

View File

@ -103,6 +103,8 @@ class RequiredFields extends Component
public function handleSubmit(array $data)
{
$this->is_loading = true;
$rff = new RFFService(
fields: $this->fields,
database: $this->getContext()['db'],

View File

@ -1,26 +1,28 @@
<div class="flex flex-col p-4 rounded-lg border bg-card text-card-foreground shadow-sm overflow-hidden px-4 py-5 bg-white sm:gap-4 sm:px-6"
x-data="{ isLoading: @entangle('isLoading') }">
<svg x-show="isLoading" wire:loading class="animate-spin h-5 w-5 text-primary" xmlns="http://www.w3.org/2000/svg"
fill="none" viewBox="0 0 24 24">
<p class="font-semibold tracking-tight group flex items-center gap-2 text-lg">{{ ctrans('texts.payment_methods') }}
</p>
<svg id="spinner" wire:loading class="animate-spin h-5 w-5 text-primary"
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
</path>
</svg>
<p class="font-semibold tracking-tight group flex items-center gap-2 text-lg">{{ ctrans('texts.payment_methods') }}
</p>
@unless($isLoading)
<div class="my-3 flex flex-col space-y-3">
@foreach($methods as $index => $method)
<button wire:loading.remove
class="flex px-4 py-3 border rounded-lg lg:-mb-1 hover:shadow-sm transition duration-300"
@click="$wire.dispatch('payment-method-selected', { company_gateway_id: {{ $method['company_gateway_id'] }}, gateway_type_id: {{ $method['gateway_type_id'] }}, amount: {{ $amount }} })">
wire:click="handleSelect('{{ $method['company_gateway_id'] }}', '{{ $method['gateway_type_id'] }}', '{{ $amount }}')"
<span>{{ $method['label'] }}</span>
</button>
@endforeach
</div>
@endunless
@script
<script>