new confirm delete dialog

This commit is contained in:
ayntk-ai
2024-08-27 12:43:59 +02:00
parent 5b54dc8792
commit 2a581147aa
2 changed files with 86 additions and 95 deletions

View File

@@ -1,62 +1,41 @@
@props([
'title' => 'Are you sure?',
'isErrorButton' => false,
'buttonTitle' => 'REWRITE THIS BUTTON TITLE PLEASSSSEEEE',
'buttonTitle' => 'Confirm Action',
'buttonFullWidth' => false,
'customButton' => null,
'disabled' => false,
'action' => 'delete',
'content' => null,
])
<div x-data="{ modalOpen: false }" @keydown.escape.window="modalOpen = false" :class="{ 'z-40': modalOpen }"
<div x-data="{ modalOpen: false, step: 1, deleteText: '', selectedActions: [], getActionText(action) {
const actionTexts = {
'delete_volumes': 'Delete associated volumes',
'delete_connected_networks': 'Delete connected networks',
'delete_configurations': 'Delete configuration files',
'delete_images': 'Delete associated unused images'
};
return actionTexts[action] || action;
} }" @keydown.escape.window="modalOpen = false; step = 1" :class="{ 'z-40': modalOpen }"
class="relative w-auto h-auto">
@if ($customButton)
@if ($buttonFullWidth)
<x-forms.button @click="modalOpen=true" class="w-full">
<x-forms.button @click="modalOpen=true" class="{{ $buttonFullWidth ? 'w-full' : '' }}">
{{ $customButton }}
</x-forms.button>
@else
<x-forms.button @click="modalOpen=true">
{{ $customButton }}
</x-forms.button>
@endif
@else
@if ($content)
<div @click="modalOpen=true">
{{ $content }}
</div>
@else
@if ($disabled)
@if ($buttonFullWidth)
<x-forms.button class="w-full" isError disabled wire:target>
<x-forms.button
@click="modalOpen=true"
class="{{ $buttonFullWidth ? 'w-full' : '' }} {{ $isErrorButton ? 'bg-red-500 hover:bg-red-600 text-white' : '' }}"
:disabled="$disabled"
wire:target
>
{{ $buttonTitle }}
</x-forms.button>
@else
<x-forms.button isError disabled wire:target>
{{ $buttonTitle }}
</x-forms.button>
@endif
@elseif ($isErrorButton)
@if ($buttonFullWidth)
<x-forms.button class="w-full" isError @click="modalOpen=true">
{{ $buttonTitle }}
</x-forms.button>
@else
<x-forms.button isError @click="modalOpen=true">
{{ $buttonTitle }}
</x-forms.button>
@endif
@else
@if ($buttonFullWidth)
<x-forms.button @click="modalOpen=true" class="flex w-full gap-2" wire:target>
{{ $buttonTitle }}
</x-forms.button>
@else
<x-forms.button @click="modalOpen=true" class="flex gap-2" wire:target>
{{ $buttonTitle }}
</x-forms.button>
@endif
@endif
@endif
@endif
<template x-teleport="body">
@@ -64,7 +43,7 @@
class="fixed top-0 lg:pt-10 left-0 z-[99] flex items-start justify-center w-screen h-screen" x-cloak>
<div x-show="modalOpen" x-transition:enter="ease-out duration-100" x-transition:enter-start="opacity-0"
x-transition:enter-end="opacity-100" x-transition:leave="ease-in duration-100"
x-transition:leave-start="opacity-100" x-transition:leave-end="opacity-0" @click="modalOpen=false"
x-transition:leave-start="opacity-100" x-transition:leave-end="opacity-0" @click="modalOpen=false; step=1"
class="absolute inset-0 w-full h-full bg-black bg-opacity-20 backdrop-blur-sm"></div>
<div x-show="modalOpen" x-trap.inert.noscroll="modalOpen" x-transition:enter="ease-out duration-100"
x-transition:enter-start="opacity-0 -translate-y-2 sm:scale-95"
@@ -75,54 +54,10 @@
class="relative w-full py-6 border rounded min-w-full lg:min-w-[36rem] max-w-fit bg-neutral-100 border-neutral-400 dark:bg-base px-7 dark:border-coolgray-300">
<div class="flex items-center justify-between pb-3">
<h3 class="text-2xl font-bold">{{ $title }}</h3>
{{-- <button @click="modalOpen=false"
class="absolute top-0 right-0 flex items-center justify-center w-8 h-8 mt-5 mr-5 rounded-full dark:text-white hover:bg-coolgray-300">
<svg class="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</button> --}}
</div>
<div class="relative w-auto pb-8">
{{ $slot }}
</div>
<div class="flex flex-row justify-end space-x-2">
<x-forms.button @click="modalOpen=false"
class="w-24 dark:bg-coolgray-200 dark:hover:bg-coolgray-300">Cancel
</x-forms.button>
<div class="flex-1"></div>
@if ($attributes->whereStartsWith('wire:click')->first())
@if ($isErrorButton)
<x-forms.button @click="modalOpen=false" class="w-24" isError type="button"
wire:click.prevent="{{ $attributes->get('wire:click') }}">Continue
</x-forms.button>
@else
<x-forms.button @click="modalOpen=false" class="w-24" isHighlighted type="button"
wire:click.prevent="{{ $attributes->get('wire:click') }}">Continue
</x-forms.button>
@endif
@elseif ($attributes->whereStartsWith('@click')->first())
@if ($isErrorButton)
<x-forms.button class="w-24" isError type="button"
@click="modalOpen=false;{{ $attributes->get('@click') }}">Continue
</x-forms.button>
@else
<x-forms.button class="w-24" isHighlighted type="button"
@click="modalOpen=false;{{ $attributes->get('@click') }}">Continue
</x-forms.button>
@endif
@elseif ($action)
@if ($isErrorButton)
<x-forms.button @click="modalOpen=false" class="w-24" isError type="button"
wire:click.prevent="{{ $action }}">Continue
</x-forms.button>
@else
<x-forms.button @click="modalOpen=false" class="w-24" isHighlighted type="button"
wire:click.prevent="{{ $action }}">Continue
</x-forms.button>
@endif
@endif
</div>
</div>
</div>
</template>

View File

@@ -5,13 +5,69 @@
<div class="pb-4">This will stop your containers, delete all related data, etc. Beware! There is no coming
back!
</div>
<x-modal-confirmation isErrorButton buttonTitle="Delete" confirm={{ $confirm }}>
<div class="px-2">This resource will be deleted. It is not reversible. <strong class="text-error">Please think
again.</strong><br><br></div>
<h4>Actions</h4>
<div x-data="{ step: 1, deleteText: '', selectedActions: [], getActionText(action) {
const actionTexts = {
'delete_volumes': 'Delete associated volumes',
'delete_connected_networks': 'Delete connected networks',
'delete_configurations': 'Delete configuration files',
'delete_images': 'Delete associated unused images'
};
return actionTexts[action] || action;
} }">
<!-- Step 1: Select actions -->
<div x-show="step === 1">
<div class="px-2 mb-4">Select the actions you want to perform:</div>
<x-forms.checkbox id="delete_volumes" wire:model="delete_volumes" label="Permanently delete associated volumes?"></x-forms.checkbox>
<x-forms.checkbox id="delete_connected_networks" wire:model="delete_connected_networks" label="Permanently delete connected networks, predefined networks are not deleted?"></x-forms.checkbox>
<x-forms.checkbox id="delete_configurations" wire:model="delete_configurations" label="Permanently delete configuration files from the server?"></x-forms.checkbox>
<x-forms.checkbox id="delete_images" wire:model="delete_images" label="Permanently delete associated unused images?"></x-forms.checkbox>
<div class="flex justify-between mt-4">
<x-forms.button @click="$dispatch('close-modal')">Cancel</x-forms.button>
<x-forms.button
x-show="step === 1"
@click="step = 2; selectedActions = [$wire.delete_volumes ? 'delete_volumes' : null, $wire.delete_connected_networks ? 'delete_connected_networks' : null, $wire.delete_configurations ? 'delete_configurations' : null, $wire.delete_images ? 'delete_images' : null].filter(Boolean)"
x-bind:disabled="!($wire.delete_volumes || $wire.delete_connected_networks || $wire.delete_configurations || $wire.delete_images)"
class="w-24 bg-red-600 text-white hover:bg-red-700"
type="button"
>
Continue
</x-forms.button>
</div>
</div>
<!-- Step 2: Confirm deletion -->
<div x-show="step === 2">
<div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-4" role="alert">
<p class="font-bold">Warning</p>
<p>This operation is not reversible. Please proceed with caution.</p>
</div>
<div class="px-2 mb-4">The following actions will be performed:</div>
<ul class="mb-4 space-y-2">
<template x-for="action in selectedActions" :key="action">
<li class="flex items-center text-red-500">
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
<span x-text="getActionText(action)" class="font-bold"></span>
</li>
</template>
</ul>
<div class="text-black dark:text-white mb-4">Please type <span class="text-red-500 font-bold">DELETE</span> to confirm this destructive action:</div>
<input type="text" x-model="deleteText" class="w-full p-2 border border-violet-500 rounded mb-4 bg-violet-100 text-black focus:outline-none focus:ring-2 focus:ring-coolify-500">
<div class="flex justify-between">
<x-forms.button @click="step = 1">Back</x-forms.button>
<x-forms.button
isError
type="button"
@click="$wire.delete(selectedActions)"
x-bind:disabled="deleteText !== 'DELETE'"
>
Permanently Delete
</x-forms.button>
</div>
</div>
</div>
</x-modal-confirmation>
</div>