fi(user): memperbaiki kode untuk employee
- membuat fitur reset password - menambahkan foreign id di relasi articles - menambahkan permission
This commit is contained in:
parent
dc7617a269
commit
17cc28c041
@ -7,6 +7,7 @@
|
||||
use App\Traits\WithConfirmation;
|
||||
use App\Traits\WithToast;
|
||||
use Flux\Flux;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Livewire\Attributes\Title;
|
||||
use Livewire\Component;
|
||||
|
||||
@ -87,11 +88,22 @@ public function delete(User $user)
|
||||
{
|
||||
$user->delete();
|
||||
|
||||
$this->loadEmployees();
|
||||
|
||||
$this->toast('Pegawai berhasil dihapus.');
|
||||
|
||||
Flux::modals()->close();
|
||||
}
|
||||
|
||||
public function resetPassword(User $user)
|
||||
{
|
||||
$user->update(['password' => Hash::make(config('myconfig.password_default'))]);
|
||||
|
||||
$this->toast('Kata sandi pegawai berhasil direset.');
|
||||
|
||||
Flux::modals()->close();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.studio.master.user.index', [
|
||||
|
||||
@ -43,6 +43,7 @@ public static function generateEmployeeCode(): string
|
||||
|
||||
$lastEmployee = self::where('code', 'like', "$prefix$year%")
|
||||
->orderBy('code', 'desc')
|
||||
->withTrashed()
|
||||
->first();
|
||||
|
||||
if ($lastEmployee) {
|
||||
|
||||
@ -89,7 +89,7 @@ public function outlets(): BelongsToMany
|
||||
|
||||
public function articles(): HasMany
|
||||
{
|
||||
return $this->hasMany(Article::class);
|
||||
return $this->hasMany(Article::class, 'author_id');
|
||||
}
|
||||
|
||||
public function payrolls(): HasMany
|
||||
|
||||
@ -42,6 +42,7 @@ public function run(): void
|
||||
'create user',
|
||||
'update user',
|
||||
'delete user',
|
||||
'reset password user',
|
||||
|
||||
'view formula',
|
||||
'create formula',
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
<flux:modal name="reset-password" class="w-[22rem]">
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
<flux:heading size="lg">{{ $confirmingTitle }}</flux:heading>
|
||||
<flux:text class="mt-2">{{ $confirmingMessage }}</flux:text>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<flux:spacer />
|
||||
<flux:modal.close>
|
||||
<flux:button variant="ghost">Batal</flux:button>
|
||||
</flux:modal.close>
|
||||
<flux:button type="submit" variant="danger" wire:click="resetPassword('{{ $confirmingId }}')">
|
||||
{{ $confirmingButtonText }}
|
||||
</flux:button>
|
||||
</div>
|
||||
</div>
|
||||
</flux:modal>
|
||||
@ -158,6 +158,16 @@ class="text-gray-700 dark:text-gray-300">{{ $employee['user']['resign_date'] }}<
|
||||
@if (auth()->id() !== $employee['user']['id'])
|
||||
<flux:separator></flux:separator>
|
||||
<div class="flex gap-2 pt-2">
|
||||
@can('reset password user')
|
||||
<flux:modal.trigger name="reset-password">
|
||||
<flux:tooltip content="Reset Kata Sandi">
|
||||
<flux:button variant="primary" color="blue" icon="lock-open" size="sm"
|
||||
wire:click="$dispatch('fn:confirmAction', { id: '{{ $employee['user']['hash'] }}', title: 'Reset Kata Sandi', message: 'Anda yakin ingin mereset kata sandi pegawai ini menjadi {{ config('myconfig.password_default') }}?' ,confirmButtonText: 'Ya, Reset' })">
|
||||
</flux:button>
|
||||
</flux:tooltip>
|
||||
</flux:modal.trigger>
|
||||
@endcan
|
||||
|
||||
@can('update user')
|
||||
<flux:tooltip content="Ubah">
|
||||
<flux:button href="{{ route('studio.master.user.edit', $employee['user']['hash']) }}"
|
||||
@ -170,7 +180,7 @@ class="text-gray-700 dark:text-gray-300">{{ $employee['user']['resign_date'] }}<
|
||||
<flux:modal.trigger name="delete">
|
||||
<flux:tooltip content="Hapus">
|
||||
<flux:button variant="danger" icon="trash" size="sm"
|
||||
wire:click="$dispatch('fn:confirmDelete', {id: '{{ $employee['user']['hash'] }}'})">
|
||||
wire:click="$dispatch('fn:confirmAction', {id: '{{ $employee['user']['hash'] }}'})">
|
||||
</flux:button>
|
||||
</flux:tooltip>
|
||||
</flux:modal.trigger>
|
||||
@ -184,4 +194,5 @@ class="text-gray-700 dark:text-gray-300">{{ $employee['user']['resign_date'] }}<
|
||||
</div>
|
||||
|
||||
@include('components.confirmation.delete')
|
||||
@include('components.confirmation.reset-password')
|
||||
</flux:main>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user