Refactor for invoices summary
This commit is contained in:
parent
d955f0b13d
commit
f3be27085a
|
|
@ -294,6 +294,8 @@ class InvoicePay extends Component
|
|||
'payable_invoices' => $payable_invoices,
|
||||
]);
|
||||
|
||||
$this->dispatch(self::CONTEXT_READY);
|
||||
|
||||
}
|
||||
|
||||
public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
|
|
|
|||
|
|
@ -28,42 +28,49 @@ class InvoiceSummary extends Component
|
|||
|
||||
public $gateway_fee;
|
||||
|
||||
public $isReady = false;
|
||||
|
||||
#[On(self::CONTEXT_READY)]
|
||||
public function onContextReady(): void
|
||||
{
|
||||
$this->isReady = true;
|
||||
$this->loadContextData();
|
||||
}
|
||||
|
||||
public function mount()
|
||||
{
|
||||
|
||||
$_context = $this->getContext();
|
||||
|
||||
$contact = $_context['contact'] ?? auth()->guard('contact')->user();
|
||||
$this->invoices = $_context['payable_invoices'];
|
||||
$this->amount = Number::formatMoney($_context['amount'], $contact->client);
|
||||
$this->gateway_fee = isset($_context['gateway_fee']) ? Number::formatMoney($_context['gateway_fee'], $contact->client) : false;
|
||||
if (!empty($_context)) {
|
||||
$this->isReady = true;
|
||||
$this->loadContextData();
|
||||
}
|
||||
}
|
||||
|
||||
private function loadContextData(): void
|
||||
{
|
||||
$_context = $this->getContext();
|
||||
|
||||
if (empty($_context)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$contact = $_context['contact'] ?? auth()->guard('contact')->user();
|
||||
$this->invoices = $_context['payable_invoices'] ?? [];
|
||||
$this->amount = isset($_context['amount']) ? Number::formatMoney($_context['amount'], $contact->client) : '';
|
||||
$this->gateway_fee = isset($_context['gateway_fee']) ? Number::formatMoney($_context['gateway_fee'], $contact->client) : false;
|
||||
}
|
||||
|
||||
#[On(self::CONTEXT_UPDATE)]
|
||||
public function onContextUpdate(): void
|
||||
{
|
||||
|
||||
$_context = $this->getContext();
|
||||
|
||||
// refactor logic for updating the price for eg if it changes with under/over pay
|
||||
$contact = $_context['contact'] ?? auth()->guard('contact')->user();
|
||||
$this->invoices = $_context['payable_invoices'];
|
||||
$this->amount = Number::formatMoney($_context['amount'], $contact->client);
|
||||
$this->gateway_fee = isset($_context['gateway_fee']) ? Number::formatMoney($_context['gateway_fee'], $contact->client) : false;
|
||||
|
||||
$this->loadContextData();
|
||||
}
|
||||
|
||||
#[On('payment-view-rendered')]
|
||||
public function handlePaymentViewRendered()
|
||||
public function handlePaymentViewRendered(): void
|
||||
{
|
||||
|
||||
$_context = $this->getContext();
|
||||
|
||||
$contact = $_context['contact'] ?? auth()->guard('contact')->user();
|
||||
$this->amount = Number::formatMoney($_context['amount'], $contact->client);
|
||||
$this->gateway_fee = isset($_context['gateway_fee']) ? Number::formatMoney($_context['gateway_fee'], $contact->client) : false;
|
||||
|
||||
$this->loadContextData();
|
||||
}
|
||||
|
||||
public function downloadDocument($invoice_hashed_id)
|
||||
|
|
@ -91,10 +98,13 @@ class InvoiceSummary extends Component
|
|||
|
||||
public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
{
|
||||
$contact = $this->getContext()['contact'] ?? auth()->guard('contact')->user();
|
||||
$_context = $this->getContext();
|
||||
|
||||
$contact = $_context['contact'] ?? auth()->guard('contact')->user();
|
||||
|
||||
return render('flow2.invoices-summary', [
|
||||
'client' => $contact->client,
|
||||
'client' => $contact->client ?? null,
|
||||
'isReady' => $this->isReady,
|
||||
]);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use Illuminate\Support\Str;
|
|||
trait WithSecureContext
|
||||
{
|
||||
public const CONTEXT_UPDATE = 'secureContext.updated';
|
||||
public const CONTEXT_READY = 'flow2.context.ready';
|
||||
|
||||
/**
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
|
|
@ -24,19 +25,9 @@ trait WithSecureContext
|
|||
*/
|
||||
public function getContext(): mixed
|
||||
{
|
||||
|
||||
$context = \Illuminate\Support\Facades\Cache::get(session()->getId()) ?? false;
|
||||
|
||||
if (!$context) {
|
||||
|
||||
usleep(300000); //@monitor - inject delay to catch delays in cache updating
|
||||
|
||||
$context = \Illuminate\Support\Facades\Cache::get(session()->getId()) ?? [];
|
||||
|
||||
}
|
||||
|
||||
return $context;
|
||||
|
||||
}
|
||||
|
||||
public function setContext(string $property, $value): array
|
||||
|
|
|
|||
|
|
@ -1,4 +1,22 @@
|
|||
<div class="w-full">
|
||||
@if(!$isReady)
|
||||
<div class="rounded-lg border bg-card bg-white text-card-foreground shadow-sm overflow-hidden">
|
||||
<div class="pt-6 px-6 flex flex-row items-start bg-muted/50">
|
||||
<div class="grid gap-0.5">
|
||||
<h3 class="font-semibold tracking-tight text-lg">{{ ctrans('texts.invoices') }}</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-6 flex items-center justify-center min-h-32">
|
||||
<div class="flex flex-col items-center gap-2">
|
||||
<svg class="animate-spin h-8 w-8 text-blue" 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="text-sm text-muted-foreground">{{ ctrans('texts.loading') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
<div class="rounded-lg border bg-card bg-white text-card-foreground shadow-sm overflow-hidden" x-chunk="An order details card with order details, shipping information, customer information and payment information.">
|
||||
<div class="pt-6 px-6 flex flex-row items-start bg-muted/50">
|
||||
<div class="grid gap-0.5">
|
||||
|
|
@ -105,4 +123,5 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
Loading…
Reference in New Issue