refactor: remove WhatsApp settings and related components
This commit is contained in:
parent
86325dabde
commit
345d949f67
@ -5,7 +5,6 @@
|
|||||||
use App\Livewire\Forms\Studio\Setting\AccountForm;
|
use App\Livewire\Forms\Studio\Setting\AccountForm;
|
||||||
use App\Livewire\Forms\Studio\Setting\PasswordForm;
|
use App\Livewire\Forms\Studio\Setting\PasswordForm;
|
||||||
use App\Livewire\Forms\Studio\Setting\ProfileForm;
|
use App\Livewire\Forms\Studio\Setting\ProfileForm;
|
||||||
use App\Models\User;
|
|
||||||
use App\Traits\Notification\WithSubscribeNotification;
|
use App\Traits\Notification\WithSubscribeNotification;
|
||||||
use App\Traits\WithAuthorization;
|
use App\Traits\WithAuthorization;
|
||||||
use App\Traits\WithToast;
|
use App\Traits\WithToast;
|
||||||
|
|||||||
@ -1,99 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Livewire\Studio\Setting;
|
|
||||||
|
|
||||||
use App\Models\Whatsapp as WhatsappModel;
|
|
||||||
use App\Traits\Notification\WithSubscribeNotification;
|
|
||||||
use App\Traits\WithToast;
|
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Livewire\Attributes\Title;
|
|
||||||
use Livewire\Component;
|
|
||||||
|
|
||||||
#[Title('Whatsapp')]
|
|
||||||
class Whatsapp extends Component
|
|
||||||
{
|
|
||||||
use WithSubscribeNotification, WithToast;
|
|
||||||
|
|
||||||
public array $whatsapp = [];
|
|
||||||
|
|
||||||
public function mount(): void
|
|
||||||
{
|
|
||||||
$whatsapp = WhatsappModel::first();
|
|
||||||
|
|
||||||
$this->whatsapp = [
|
|
||||||
'id' => $whatsapp?->id,
|
|
||||||
'zawa_id' => $whatsapp?->zawa_id,
|
|
||||||
'session_id' => $whatsapp?->session_id,
|
|
||||||
'qr_code' => $whatsapp?->qr_code,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createSession(): void
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$response = Http::post(config('services.zawa.url').'/authorize');
|
|
||||||
|
|
||||||
if ($response->successful()) {
|
|
||||||
$data = $response->json();
|
|
||||||
|
|
||||||
WhatsappModel::updateOrCreate(
|
|
||||||
['zawa_id' => $data['id']],
|
|
||||||
[
|
|
||||||
'session_id' => $data['sessionId'],
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->whatsapp['zawa_id'] = $data['id'];
|
|
||||||
$this->whatsapp['session_id'] = $data['sessionId'];
|
|
||||||
|
|
||||||
$this->toast('Berhasil membuat sesi WhatsApp');
|
|
||||||
} else {
|
|
||||||
$this->toast('Gagal membuat sesi WhatsApp', 'Gagal', 'danger');
|
|
||||||
}
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
Log::error($e);
|
|
||||||
$this->toast('Gagal membuat sesi WhatsApp, silakan coba lagi.', 'Gagal', 'danger');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function generateQrCode(): void
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$response = Http::withHeaders([
|
|
||||||
'id' => $this->whatsapp['zawa_id'],
|
|
||||||
'session-id' => $this->whatsapp['session_id'],
|
|
||||||
])->get(config('services.zawa.url').'/qrcode');
|
|
||||||
|
|
||||||
if ($response->successful()) {
|
|
||||||
$data = $response->json();
|
|
||||||
|
|
||||||
$qrBase64 = 'data:image/png;base64,'.$data['qrcode'];
|
|
||||||
|
|
||||||
WhatsappModel::updateOrCreate(
|
|
||||||
['zawa_id' => $this->whatsapp['zawa_id']],
|
|
||||||
[
|
|
||||||
'session_id' => $this->whatsapp['session_id'],
|
|
||||||
'qr_code' => $qrBase64,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->whatsapp['qr_code'] = $qrBase64;
|
|
||||||
|
|
||||||
$this->toast('Berhasil generate QR Code WhatsApp');
|
|
||||||
} else {
|
|
||||||
$this->toast('Gagal generate QR Code, silakan coba lagi.', 'Gagal', 'danger');
|
|
||||||
}
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
Log::error($e);
|
|
||||||
$this->toast('Terjadi kesalahan saat generate QR Code,silakan hubungi Administrator.', 'Gagal', 'danger');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function render()
|
|
||||||
{
|
|
||||||
return view('livewire.studio.setting.whatsapp', [
|
|
||||||
'pageTitle' => 'Whatsapp',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Whatsapp extends Model
|
|
||||||
{
|
|
||||||
protected $guarded = ['id'];
|
|
||||||
}
|
|
||||||
@ -227,13 +227,6 @@ public function boot(): void
|
|||||||
'match' => 'studio.setting.application',
|
'match' => 'studio.setting.application',
|
||||||
'can' => 'view application settings',
|
'can' => 'view application settings',
|
||||||
],
|
],
|
||||||
// [
|
|
||||||
// 'label' => 'Whatsapp',
|
|
||||||
// 'icon' => 'chat-bubble-oval-left-ellipsis',
|
|
||||||
// 'route' => 'studio.setting.whatsapp',
|
|
||||||
// 'match' => 'studio.setting.whatsapp',
|
|
||||||
// 'can' => 'view whatsapp settings',
|
|
||||||
// ],
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
|||||||
@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::create('whatsapps', function (Blueprint $table) {
|
|
||||||
$table->id();
|
|
||||||
$table->string('zawa_id', 100);
|
|
||||||
$table->string('session_id', 100);
|
|
||||||
$table->text('qr_code')->nullable();
|
|
||||||
$table->timestamp('created_at')->useCurrent();
|
|
||||||
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::dropIfExists('whatsapps');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -142,8 +142,6 @@ public function run(): void
|
|||||||
|
|
||||||
'view application settings',
|
'view application settings',
|
||||||
|
|
||||||
// 'view whatsapp settings',
|
|
||||||
|
|
||||||
'view general settings',
|
'view general settings',
|
||||||
'update general settings',
|
'update general settings',
|
||||||
|
|
||||||
@ -261,8 +259,6 @@ public function run(): void
|
|||||||
|
|
||||||
'view application settings',
|
'view application settings',
|
||||||
|
|
||||||
// 'view whatsapp settings',
|
|
||||||
|
|
||||||
'view general settings',
|
'view general settings',
|
||||||
'update general settings',
|
'update general settings',
|
||||||
|
|
||||||
@ -372,8 +368,6 @@ public function run(): void
|
|||||||
|
|
||||||
'view application settings',
|
'view application settings',
|
||||||
|
|
||||||
// 'view whatsapp settings',
|
|
||||||
|
|
||||||
'view general settings',
|
'view general settings',
|
||||||
'update general settings',
|
'update general settings',
|
||||||
|
|
||||||
|
|||||||
@ -1,52 +0,0 @@
|
|||||||
<flux:main>
|
|
||||||
<div class="flex justify-between items-center">
|
|
||||||
<div>
|
|
||||||
<flux:heading size="xl">{{ $pageTitle }}</flux:heading>
|
|
||||||
<flux:text>
|
|
||||||
Integrasikan WhatsApp untuk pengiriman invoice, kode verifikasi, serta
|
|
||||||
broadcast voucher atau informasi kepada pelanggan secara cepat dan efikien.
|
|
||||||
</flux:text>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mt-6 space-y-4">
|
|
||||||
<flux:callout icon="{{ $whatsapp['zawa_id'] ? 'check-circle' : 'link' }}"
|
|
||||||
color="{{ $whatsapp['zawa_id'] ? 'emerald' : 'gray' }}">
|
|
||||||
<flux:heading>Langkah 1: Buat Sesi WA</flux:heading>
|
|
||||||
<flux:callout.text>
|
|
||||||
Klik tombol untuk membuat sesi WhatsApp dan mendapatkan <code>sessionId</code>.
|
|
||||||
</flux:callout.text>
|
|
||||||
|
|
||||||
<x-slot name="actions">
|
|
||||||
@if (!$whatsapp['zawa_id'])
|
|
||||||
<flux:button wire:click="createSession">Buat Sesi</flux:button>
|
|
||||||
@else
|
|
||||||
<span class="text-sm text-emerald-600 font-medium">✅ Sesi sudah dibuat</span>
|
|
||||||
@endif
|
|
||||||
</x-slot>
|
|
||||||
</flux:callout>
|
|
||||||
|
|
||||||
<flux:callout icon="{{ $whatsapp['qr_code'] ? 'check-circle' : 'qr-code' }}"
|
|
||||||
color="{{ $whatsapp['qr_code'] ? 'emerald' : 'gray' }}"
|
|
||||||
class="{{ $whatsapp['zawa_id'] ? '' : 'opacity-50 pointer-events-none' }}">
|
|
||||||
<flux:heading>Langkah 2: Generate QR Code</flux:heading>
|
|
||||||
<flux:callout.text>
|
|
||||||
Gunakan <code>sessionId</code> untuk men-generate QR code yang akan discan di WhatsApp.
|
|
||||||
</flux:callout.text>
|
|
||||||
|
|
||||||
<x-slot name="actions">
|
|
||||||
@if (!$whatsapp['qr_code'] && $whatsapp['zawa_id'])
|
|
||||||
<flux:button wire:click="generateQrCode">Generate QR Code</flux:button>
|
|
||||||
@endif
|
|
||||||
</x-slot>
|
|
||||||
|
|
||||||
@if ($whatsapp['qr_code'])
|
|
||||||
<div class="mt-4 flex flex-col">
|
|
||||||
<img src="{{ $whatsapp['qr_code'] }}" alt="QR Code WhatsApp" class="w-56 h-56 rounded-lg shadow" />
|
|
||||||
<p class="mt-2 text-sm text-emerald-600 font-medium">Scan QR ini di WhatsApp</p>
|
|
||||||
</div>
|
|
||||||
@endif
|
|
||||||
</flux:callout>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</flux:main>
|
|
||||||
@ -54,7 +54,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
Route::prefix('dashboard')->name('studio.dashboard.')->group(function () {
|
Route::prefix('dashboard')->name('studio.dashboard.')->group(function () {
|
||||||
Route::get('/overview', OverviewComponent::class)->name('overview')->middleware('can:view studio overview');
|
Route::get('/overview', OverviewComponent::class)->name('overview')->mviewiddleware('can:view studio overview');
|
||||||
Route::get('/analysis', AnalysisComponent::class)->name('analysis')->middleware('can:view analysis');
|
Route::get('/analysis', AnalysisComponent::class)->name('analysis')->middleware('can:view analysis');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user