feat(overview): munculkan form untuk jadi member si overview

This commit is contained in:
Yoga Pangestu 2025-11-13 10:59:00 +07:00
parent d775e57675
commit 48271c2bf2
3 changed files with 119 additions and 51 deletions

View File

@ -12,6 +12,8 @@ class CustomerForm extends Form
{ {
public ?Customer $customer = null; public ?Customer $customer = null;
public ?string $user_id = null;
public string $name = ''; public string $name = '';
public ?string $phone_number = null; public ?string $phone_number = null;
@ -50,6 +52,7 @@ public function store()
$this->validate(); $this->validate();
Customer::create([ Customer::create([
'user_id' => $this->user_id,
'name' => $this->name, 'name' => $this->name,
'phone_number' => $this->phone_number, 'phone_number' => $this->phone_number,
'gender' => $this->gender, 'gender' => $this->gender,

View File

@ -2,6 +2,11 @@
namespace App\Livewire\Member; namespace App\Livewire\Member;
use App\Livewire\Forms\Studio\Loyalty\CustomerForm;
use App\Models\Membership;
use App\Models\Tier;
use App\Traits\WithToast;
use Illuminate\Support\Facades\DB;
use Livewire\Attributes\Layout; use Livewire\Attributes\Layout;
use Livewire\Attributes\Title; use Livewire\Attributes\Title;
use Livewire\Component; use Livewire\Component;
@ -10,11 +15,21 @@
#[Layout('components.layouts.member')] #[Layout('components.layouts.member')]
class Overview extends Component class Overview extends Component
{ {
use WithToast;
public CustomerForm $form;
public bool $hasMemberData = false;
public bool $isVerified = false; public bool $isVerified = false;
public function mount() public function mount()
{ {
$this->hasMemberData = auth()->user()->customer()->exists();
$this->isVerified = auth()->user()->hasVerifiedEmail(); $this->isVerified = auth()->user()->hasVerifiedEmail();
$this->form->user_id = request()->routeIs('member.overview') ? auth()->id() : null;
} }
public function checkEmailVerification() public function checkEmailVerification()
@ -24,6 +39,25 @@ public function checkEmailVerification()
$this->isVerified = auth()->user()->hasVerifiedEmail(); $this->isVerified = auth()->user()->hasVerifiedEmail();
} }
public function save()
{
DB::transaction(function () {
$this->form->store();
$this->hasMemberData = true;
if (! auth()->user()->membership()->exists()) {
Membership::create([
'user_id' => auth()->id(),
'tier_id' => Tier::orderBy('min_points')->first()->id,
'tier_points' => 10,
]);
}
});
$this->toast('Selamat, Anda telah menjadi member sekarang.');
}
public function render() public function render()
{ {
return view('livewire.member.overview'); return view('livewire.member.overview');

View File

@ -2,6 +2,7 @@
<flux:heading size="xl" level="1">Haloo, {{ auth()->user()?->customer?->name }}</flux:heading> <flux:heading size="xl" level="1">Haloo, {{ auth()->user()?->customer?->name }}</flux:heading>
<flux:text class="mb-6 mt-2 text-base">Selamat datang di Studio Yadi Parfum.</flux:text> <flux:text class="mb-6 mt-2 text-base">Selamat datang di Studio Yadi Parfum.</flux:text>
@if ($hasMemberData)
<div class="mt-6 grid grid-cols-1 md:grid-cols-2 gap-4"> <div class="mt-6 grid grid-cols-1 md:grid-cols-2 gap-4">
<flux:callout icon="user-group" color="blue"> <flux:callout icon="user-group" color="blue">
<flux:callout.heading> <flux:callout.heading>
@ -65,6 +66,36 @@
<flux:button>Lihat</flux:button> <flux:button>Lihat</flux:button>
</x-slot> </x-slot>
</flux:callout> </flux:callout>
</div> </div>
@else
<flux:heading class="mb-4">Anda belum terdaftar menjadi member, silakan isi formulir di bawah ini.
</flux:heading>
<flux:card>
<flux:input type="hidden" name="form.user_id"></flux:input>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<flux:field>
<flux:label>Nama <span class="text-red-500 ms-1">*</span></flux:label>
<flux:input placeholder="John Doe" wire:model.live.debounce.500ms="form.name" autofocus
autocomplete="off" />
<flux:error name="form.name" />
</flux:field>
<flux:input label="Nomor Telepon" placeholder="0821 xxxx xxxx" mask="9999 9999 99999"
wire:model.live.debounce.500ms="form.phone_number" autocomplete="off" />
<flux:field>
<flux:label>Jenis Kelamin <span class="text-red-500 ms-1">*</span></flux:label>
<flux:radio.group wire:model.live="form.gender" variant="buttons" class="w-full *:flex-1">
@foreach (\App\Enums\Gender::cases() as $gender)
<flux:radio value="{{ $gender->value }}">
{{ $gender->label() }}
</flux:radio>
@endforeach
</flux:radio.group>
<flux:error name="form.gender" />
</flux:field>
</div>
<flux:button wire:click="save" class="mt-4">Simpan</flux:button>
</flux:card>
@endif
</flux:main> </flux:main>