From 73dfdb83a70ff9e6e3d1d97ab710a0542026eb8a Mon Sep 17 00:00:00 2001 From: ayntk-ai <122374094+ayntk-ai@users.noreply.github.com> Date: Sat, 31 Aug 2024 12:55:17 +0200 Subject: [PATCH] fix rendering bug, more props --- .../components/modal-confirmation.blade.php | 84 +++++++++++-------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/resources/views/components/modal-confirmation.blade.php b/resources/views/components/modal-confirmation.blade.php index 2b86fe475..acf641203 100644 --- a/resources/views/components/modal-confirmation.blade.php +++ b/resources/views/components/modal-confirmation.blade.php @@ -5,13 +5,14 @@ 'buttonFullWidth' => false, 'customButton' => null, 'disabled' => false, -'action' => 'delete', +'submitAction' => 'delete', 'content' => null, 'checkboxes' => [], -'checkboxActions' => [], 'actions' => [], 'confirmWithText' => true, 'confirmText' => 'Confirm Deletion', +'confirmationLabel' => 'Please confirm the execution of the actions by entering the Name below', +'shortConfirmationLabel' => 'Name', 'confirmWithPassword' => true, 'step1ButtonText' => 'Continue Deletion', 'step2ButtonText' => 'Delete Permanently', @@ -23,38 +24,47 @@ step: {{ !empty($checkboxes) ? 1 : ($confirmWithPassword ? 2 : 3) }}, initialStep: {{ !empty($checkboxes) ? 1 : ($confirmWithPassword ? 2 : 3) }}, finalStep: {{ $confirmWithPassword ? 3 : (!empty($checkboxes) || $confirmWithText ? 2 : 1) }}, - selectedActions: @js(collect($checkboxes)->where('model', true)->pluck('id')->toArray()), deleteText: '', password: '', - checkboxActions: @js($checkboxActions), actions: @js($actions), confirmText: @js($confirmText), userConfirmText: '', confirmWithText: @js($confirmWithText), confirmWithPassword: @js($confirmWithPassword), copied: false, - action: @js($action), - getActionText(action) { - return this.checkboxActions[action] || action; - }, + submitAction: @js($submitAction), + passwordError: '', + selectedActions: [], resetModal() { this.step = this.initialStep; - this.selectedActions = @js(collect($checkboxes)->where('model', true)->pluck('id')->toArray()); this.deleteText = ''; this.password = ''; this.userConfirmText = ''; + this.passwordError = ''; }, step1ButtonText: @js($step1ButtonText), step2ButtonText: @js($step2ButtonText), step3ButtonText: @js($step3ButtonText), - executeAction() { - if (this.confirmWithPassword) { - $wire.call(this.action, this.password); - } else { - $wire.call(this.action); + validatePassword() { + this.passwordError = ''; + if (this.confirmWithPassword && !this.password) { + this.passwordError = 'Password is required.'; + return false; + } + return true; + }, + submitForm() { + if (this.validatePassword()) { + $wire.call(this.submitAction, this.password, this.selectedActions) + .then(result => { + if (result === true) { + this.modalOpen = false; + this.resetModal(); + } else if (typeof result === 'string') { + this.passwordError = result; + } + }); } - this.modalOpen = false; - this.resetModal(); }, copyConfirmText() { navigator.clipboard.writeText(this.confirmText); @@ -62,8 +72,9 @@ setTimeout(() => { this.copied = false; }, 2000); - } -}" @keydown.escape.window="modalOpen = false; resetModal()" :class="{ 'z-40': modalOpen }" class="relative w-auto h-auto"> + }, + +}" @keydown.escape.window="modalOpen = false; resetModal()" :class="{ 'z-40': modalOpen }" class="relative w-auto h-auto" @password-error.window="passwordError = $event.detail"> @if ($customButton) @if ($buttonFullWidth) @@ -144,31 +155,29 @@

Warning

This operation is not reversible. Please proceed with caution.

-
The following actions will be performed:
+
The following actions will be performed:
@if($confirmWithText)

Confirm Actions

-

Please confirm the execution of the actions by entering the Resource Name below

+

{{ $confirmationLabel }}

@@ -188,7 +197,7 @@
@@ -206,7 +215,8 @@ - + +

@endif @@ -225,7 +235,7 @@ @@ -237,7 +247,7 @@