diff --git a/app/Livewire/Studio/Catalog/Bottle/Index.php b/app/Livewire/Studio/Catalog/Bottle/Index.php
index 698ea3a..f78330c 100644
--- a/app/Livewire/Studio/Catalog/Bottle/Index.php
+++ b/app/Livewire/Studio/Catalog/Bottle/Index.php
@@ -4,6 +4,7 @@
use App\Models\Bottle;
use App\Traits\WithConfirmation;
+use App\Traits\WithShowPrice;
use App\Traits\WithToast;
use Flux\Flux;
use Livewire\Attributes\Title;
@@ -12,7 +13,7 @@
#[Title('Botol')]
class Index extends Component
{
- use WithConfirmation, WithToast;
+ use WithConfirmation, WithShowPrice, WithToast;
public function delete(Bottle $bottle)
{
diff --git a/app/Livewire/Studio/Catalog/Perfume/Index.php b/app/Livewire/Studio/Catalog/Perfume/Index.php
index 2cb84cd..e8b6f94 100644
--- a/app/Livewire/Studio/Catalog/Perfume/Index.php
+++ b/app/Livewire/Studio/Catalog/Perfume/Index.php
@@ -4,6 +4,7 @@
use App\Models\Perfume;
use App\Traits\WithConfirmation;
+use App\Traits\WithShowPrice;
use App\Traits\WithToast;
use Flux\Flux;
use Livewire\Attributes\Title;
@@ -12,7 +13,7 @@
#[Title('Parfum')]
class Index extends Component
{
- use WithConfirmation, WithToast;
+ use WithConfirmation, WithShowPrice, WithToast;
public function delete(Perfume $perfume)
{
diff --git a/app/Livewire/Studio/Catalog/Product/Index.php b/app/Livewire/Studio/Catalog/Product/Index.php
index 07c70d6..a333716 100644
--- a/app/Livewire/Studio/Catalog/Product/Index.php
+++ b/app/Livewire/Studio/Catalog/Product/Index.php
@@ -4,6 +4,7 @@
use App\Models\Product;
use App\Traits\WithConfirmation;
+use App\Traits\WithShowPrice;
use App\Traits\WithToast;
use Flux\Flux;
use Livewire\Attributes\Title;
@@ -12,7 +13,7 @@
#[Title('Produk')]
class Index extends Component
{
- use WithConfirmation, WithToast;
+ use WithConfirmation, WithShowPrice,WithToast;
public function delete(Product $product)
{
diff --git a/app/Traits/WithShowPrice.php b/app/Traits/WithShowPrice.php
new file mode 100644
index 0000000..53d929e
--- /dev/null
+++ b/app/Traits/WithShowPrice.php
@@ -0,0 +1,104 @@
+id())
+ ->where('model', $model)
+ ->where('created_at', '>', now()->subMinutes(30))
+ ->exists();
+
+ if ($recentRequest) {
+ $this->toast('Kamu baru saja mengajukan permintaan, tautan persetujuan masih berlaku selama 30 menit.', 'Peringatan', 'warning');
+ Flux::modal('show-price')->close();
+
+ return;
+ }
+
+ $whatsapp = Whatsapp::first();
+ $owner = User::role('owner')->with('employee')->first();
+
+ if (! $owner) {
+ $this->toast('Owner belum terdaftar, silakan hubungi Admin', 'Gagal', 'danger');
+ Flux::modal('show-price')->close();
+
+ return;
+ }
+
+ $phoneNumber = formatPhoneNumber($owner->employee?->phone_number, '62');
+
+ try {
+ $priceRequest = PriceRequest::create([
+ 'user_id' => auth()->id(),
+ 'model' => $model,
+ 'expires_at' => now()->addMinutes(30),
+ ]);
+
+ $signedUrl = URL::temporarySignedRoute(
+ 'price-request.approve',
+ $priceRequest->expires_at,
+ ['priceRequest' => $priceRequest->hash]
+ );
+
+ $priceRequest->update([
+ 'signature' => hash('sha256', $signedUrl),
+ ]);
+
+ $causerName = auth()->user()->employee?->full_name;
+
+ $response = Http::withHeaders([
+ 'id' => $whatsapp->zawa_id,
+ 'session-id' => $whatsapp->session_id,
+ 'Content-Type' => 'application/json',
+ ])->post(config('services.zawa.url').'/message', [
+ 'phone' => $phoneNumber,
+ 'type' => 'text',
+ 'text' => "Haloo {$owner->employee?->full_name}, saya {$causerName}, "
+ ."saya ingin mengajukan permintaan persetujuan untuk mengakses data harga beli {$label}."
+ ."\n\nSilakan klik tautan berikut untuk menyetujui:\n\n{$signedUrl}",
+ ]);
+
+ if ($response->successful()) {
+ $this->toast('Permintaan persetujuan berhasil dikirim.');
+ } else {
+ $this->toast('Permintaan persetujuan gagal dikirim, silakan coba lagi.', 'Gagal', 'danger');
+ }
+ } catch (\Throwable $th) {
+ Log::error($th->getMessage());
+ $this->toast('Opps, terjadi kesalahan. Silakan coba lagi dan jika masih terjadi, hubungi Administrator.', 'Gagal', 'danger');
+ }
+
+ Flux::modal('show-price')->close();
+ }
+}
diff --git a/resources/views/components/confirmation/show-price.blade.php b/resources/views/components/confirmation/show-price.blade.php
new file mode 100644
index 0000000..61e8e6c
--- /dev/null
+++ b/resources/views/components/confirmation/show-price.blade.php
@@ -0,0 +1,19 @@
+