refactor(register): memisahkan tanggung jawab menjadi masing" fungsi dan memberikan return type
This commit is contained in:
parent
40681b4347
commit
bbab732bd2
@ -8,6 +8,7 @@
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Traits\WithToast;
|
use App\Traits\WithToast;
|
||||||
use App\Traits\WithUpdatedData;
|
use App\Traits\WithUpdatedData;
|
||||||
|
use Illuminate\Contracts\View\View;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Livewire\Attributes\Layout;
|
use Livewire\Attributes\Layout;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
@ -35,16 +36,16 @@ public function mount()
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateStep(int $value)
|
public function updateStep(int $value): void
|
||||||
{
|
{
|
||||||
if ($this->currentStep === 1) {
|
if ($this->shouldValidateBeforeChangingStep()) {
|
||||||
$this->form->validateStep1();
|
$this->form->validateStep1();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->currentStep = $value;
|
$this->currentStep = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function nextStep()
|
public function nextStep(): void
|
||||||
{
|
{
|
||||||
match ($this->currentStep) {
|
match ($this->currentStep) {
|
||||||
1 => $this->form->validateStep1(),
|
1 => $this->form->validateStep1(),
|
||||||
@ -57,14 +58,44 @@ public function nextStep()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prevStep()
|
public function prevStep(): void
|
||||||
{
|
{
|
||||||
if ($this->currentStep > 1) {
|
if ($this->currentStep > 1) {
|
||||||
$this->currentStep--;
|
$this->currentStep--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updated(string $propertyName, $value)
|
public function updated(string $propertyName, $value): void
|
||||||
|
{
|
||||||
|
$this->validateUpdatedField($propertyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function register(): void
|
||||||
|
{
|
||||||
|
$this->form->auth();
|
||||||
|
|
||||||
|
$this->sendRegistrationSuccessToast();
|
||||||
|
$this->notifyPrivilegedUsersAboutNewMember();
|
||||||
|
$this->redirectAfterRegistration();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render(): View
|
||||||
|
{
|
||||||
|
return view('livewire.auth.register');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether validation is required before changing step.
|
||||||
|
*/
|
||||||
|
protected function shouldValidateBeforeChangingStep(): bool
|
||||||
|
{
|
||||||
|
return $this->currentStep === 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate updated field based on current form step rules.
|
||||||
|
*/
|
||||||
|
protected function validateUpdatedField(string $propertyName): void
|
||||||
{
|
{
|
||||||
$field = Str::replace('form.', '', $propertyName);
|
$field = Str::replace('form.', '', $propertyName);
|
||||||
|
|
||||||
@ -77,27 +108,36 @@ public function updated(string $propertyName, $value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register()
|
/**
|
||||||
|
* Show success toast after registration.
|
||||||
|
*/
|
||||||
|
protected function sendRegistrationSuccessToast(): void
|
||||||
{
|
{
|
||||||
$this->form->auth();
|
|
||||||
|
|
||||||
$this->toast('Selamat, akun Anda berhasil didaftarkan. Silakan periksa email Anda untuk melakukan verifikasi.');
|
$this->toast('Selamat, akun Anda berhasil didaftarkan. Silakan periksa email Anda untuk melakukan verifikasi.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatch notification to privileged users when a new member registers.
|
||||||
|
*/
|
||||||
|
protected function notifyPrivilegedUsersAboutNewMember(): void
|
||||||
|
{
|
||||||
$userIds = User::role(['Developer', 'Owner'])->pluck('id')->toArray();
|
$userIds = User::role(['Developer', 'Owner'])->pluck('id')->toArray();
|
||||||
|
|
||||||
StorePushNotification::dispatch(
|
StorePushNotification::dispatch(
|
||||||
PushNotification::whereIn('user_id', $userIds)->get(),
|
PushNotification::whereIn('user_id', $userIds)->get(),
|
||||||
[
|
[
|
||||||
'title' => '🎉Member Baru Bergabung!',
|
'title' => '🎉Member Baru Bergabung!',
|
||||||
'body' => 'Ada member baru saja. Yuk lihat profil lengkapnya di aplikasi! 🌟',
|
'body' => 'Ada member baru saja bergabung. Cek profil lengkapnya di aplikasi! 🌟',
|
||||||
'url' => route('studio.loyalty.customer.index'),
|
'url' => route('studio.loyalty.customer.index'),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirect user after successful registration.
|
||||||
|
*/
|
||||||
|
protected function redirectAfterRegistration(): void
|
||||||
|
{
|
||||||
$this->redirectIntended('/member/overview', navigate: true);
|
$this->redirectIntended('/member/overview', navigate: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render()
|
|
||||||
{
|
|
||||||
return view('livewire.auth.register');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user