feat: implement power management button with confirmation modal for server control, enhancing user interaction and experience

This commit is contained in:
2025-12-04 07:39:40 -05:00
parent 3316f89780
commit 23046353fb

View File

@@ -9,18 +9,107 @@
</div>
<span class="font-medium">{{ $status->name }}</span>
</div>
<div
class="size-5 rounded-md p-0.5
@if($status->status == 'running') text-success bg-success/20
@elseif($status->status == 'stopped') text-inactive bg-inactive/20
@else text-warning bg-warning/20 @endif">
<div x-data="{ showPowerOffModal: false }">
<button
type="button"
@click="
@if($status->status == 'running')
<x-ri-checkbox-circle-fill />
@elseif($status->status == 'stopped')
<x-ri-forbid-fill />
showPowerOffModal = true
@else
<x-ri-error-warning-fill />
$wire.do('start')
@endif
"
class="relative size-12 rounded-full cursor-pointer transition-all duration-300 ease-in-out hover:scale-110 focus:outline-none focus:ring-2 focus:ring-offset-2
@if($status->status == 'running')
bg-success hover:bg-success/90 focus:ring-success animate-pulse
@elseif($status->status == 'stopped')
bg-red-500 hover:bg-red-600 focus:ring-red-500
@else
bg-warning hover:bg-warning/90 focus:ring-warning
@endif"
title="@if($status->status == 'running') Power Off @else Power On @endif"
>
<i class="absolute inset-0 flex items-center justify-center text-white text-xl transition-transform duration-300">
<x-ri-shut-down-line class="size-6" />
</i>
</button>
{{-- Power Off Confirmation Modal --}}
<div
x-show="showPowerOffModal"
x-cloak
class="fixed inset-0 z-50 overflow-y-auto"
aria-labelledby="modal-title"
role="dialog"
aria-modal="true"
style="display: none;"
>
<div class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
{{-- Background overlay --}}
<div
x-show="showPowerOffModal"
x-transition:enter="ease-out duration-300"
x-transition:enter-start="opacity-0"
x-transition:enter-end="opacity-100"
x-transition:leave="ease-in duration-200"
x-transition:leave-start="opacity-100"
x-transition:leave-end="opacity-0"
class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"
@click="showPowerOffModal = false"
aria-hidden="true"
></div>
{{-- Center modal --}}
<span class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">&#8203;</span>
{{-- Modal panel --}}
<div
x-show="showPowerOffModal"
x-transition:enter="ease-out duration-300"
x-transition:enter-start="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
x-transition:enter-end="opacity-100 translate-y-0 sm:scale-100"
x-transition:leave="ease-in duration-200"
x-transition:leave-start="opacity-100 translate-y-0 sm:scale-100"
x-transition:leave-end="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
class="inline-block align-bottom bg-background-secondary rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full border border-neutral"
>
<div class="bg-background-secondary px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
<div class="sm:flex sm:items-start">
<div class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 dark:bg-red-900/20 sm:mx-0 sm:h-10 sm:w-10">
<x-ri-alert-line class="h-6 w-6 text-red-600 dark:text-red-500" />
</div>
<div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
<h3 class="text-lg leading-6 font-medium text-base" id="modal-title">
Confirm Power Off
</h3>
<div class="mt-2">
<p class="text-sm text-base/70">
Are you sure you want to power off <strong>{{ $status->name }}</strong>? This will immediately shut down the server.
</p>
</div>
</div>
</div>
</div>
<div class="bg-background-secondary px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse gap-2">
<button
type="button"
wire:click="do('stop')"
@click="showPowerOffModal = false"
class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-red-600 text-base font-medium text-white hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 sm:ml-3 sm:w-auto sm:text-sm"
>
Power Off
</button>
<button
type="button"
@click="showPowerOffModal = false"
class="mt-3 w-full inline-flex justify-center rounded-md border border-neutral shadow-sm px-4 py-2 bg-background text-base font-medium text-base hover:bg-background-secondary focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-secondary sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm"
>
Cancel
</button>
</div>
</div>
</div>
</div>
</div>
</div>