Skip to content

Commit

Permalink
Merge pull request #113 from devaslanphp/dev
Browse files Browse the repository at this point in the history
Resolve Sonar duplicated lines
  • Loading branch information
heloufir authored Sep 27, 2022
2 parents fd0cdde + b17d8b5 commit 1eba9da
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 122 deletions.
47 changes: 47 additions & 0 deletions app/Core/CrudDialogHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Core;

use Exception;
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;

trait CrudDialogHelper
{

public bool $deleteConfirmationOpened = false;

/**
* Delete confirmation function
*
* @param string $title
* @param string $body
* @param string $deleteEvent
* @param string $cancelEvent
* @return void
* @throws Exception
*/
public function deleteConfirmation(string $title, string $body, string $deleteEvent, string $cancelEvent): void
{
$this->deleteConfirmationOpened = true;
Notification::make()
->warning()
->title($title)
->body($body)
->actions([
Action::make('confirm')
->label(__('Confirm'))
->color('danger')
->button()
->close()
->emit($deleteEvent),
Action::make('cancel')
->label(__('Cancel'))
->close()
->emit($cancelEvent)
])
->persistent()
->send();
}

}
28 changes: 8 additions & 20 deletions app/Http/Livewire/Administration/CompaniesDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Livewire\Administration;

use App\Core\CrudDialogHelper;
use App\Models\CompanyUser;
use App\Models\Icon;
use App\Models\Company;
Expand All @@ -28,9 +29,9 @@
class CompaniesDialog extends Component implements HasForms
{
use WithFileUploads, InteractsWithForms;
use CrudDialogHelper;

public Company $company;
public bool $deleteConfirmationOpened = false;

protected $listeners = ['doDeleteCompany', 'cancelDeleteCompany'];

Expand Down Expand Up @@ -197,24 +198,11 @@ public function cancelDeleteCompany(): void
*/
public function deleteCompany(): void
{
$this->deleteConfirmationOpened = true;
Notification::make()
->warning()
->title(__('Company deletion'))
->body(__('Are you sure you want to delete this company?'))
->actions([
Action::make('confirm')
->label(__('Confirm'))
->color('danger')
->button()
->close()
->emit('doDeleteCompany'),
Action::make('cancel')
->label(__('Cancel'))
->close()
->emit('cancelDeleteCompany')
])
->persistent()
->send();
$this->deleteConfirmation(
__('Company deletion'),
__('Are you sure you want to delete this company?'),
'doDeleteCompany',
'cancelDeleteCompany'
);
}
}
28 changes: 8 additions & 20 deletions app/Http/Livewire/Administration/TicketPrioritiesDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Livewire\Administration;

use App\Core\CrudDialogHelper;
use App\Models\Icon;
use App\Models\TicketPriority;
use Closure;
Expand All @@ -21,9 +22,9 @@
class TicketPrioritiesDialog extends Component implements HasForms
{
use InteractsWithForms;
use CrudDialogHelper;

public TicketPriority $priority;
public bool $deleteConfirmationOpened = false;

protected $listeners = ['doDeletePriority', 'cancelDeletePriority'];

Expand Down Expand Up @@ -181,24 +182,11 @@ public function cancelDeletePriority(): void
*/
public function deletePriority(): void
{
$this->deleteConfirmationOpened = true;
Notification::make()
->warning()
->title(__('Priority deletion'))
->body(__('Are you sure you want to delete this priority?'))
->actions([
Action::make('confirm')
->label(__('Confirm'))
->color('danger')
->button()
->close()
->emit('doDeletePriority'),
Action::make('cancel')
->label(__('Cancel'))
->close()
->emit('cancelDeletePriority')
])
->persistent()
->send();
$this->deleteConfirmation(
__('Priority deletion'),
__('Are you sure you want to delete this priority?'),
'doDeletePriority',
'cancelDeletePriority'
);
}
}
28 changes: 8 additions & 20 deletions app/Http/Livewire/Administration/TicketStatusesDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Livewire\Administration;

use App\Core\CrudDialogHelper;
use App\Models\TicketStatus;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\ColorPicker;
Expand All @@ -17,9 +18,9 @@
class TicketStatusesDialog extends Component implements HasForms
{
use InteractsWithForms;
use CrudDialogHelper;

public TicketStatus $status;
public bool $deleteConfirmationOpened = false;

protected $listeners = ['doDeleteStatus', 'cancelDeleteStatus'];

Expand Down Expand Up @@ -155,24 +156,11 @@ public function cancelDeleteStatus(): void
*/
public function deleteStatus(): void
{
$this->deleteConfirmationOpened = true;
Notification::make()
->warning()
->title(__('Status deletion'))
->body(__('Are you sure you want to delete this status?'))
->actions([
Action::make('confirm')
->label(__('Confirm'))
->color('danger')
->button()
->close()
->emit('doDeleteStatus'),
Action::make('cancel')
->label(__('Cancel'))
->close()
->emit('cancelDeleteStatus')
])
->persistent()
->send();
$this->deleteConfirmation(
__('Status deletion'),
__('Are you sure you want to delete this status?'),
'doDeleteStatus',
'cancelDeleteStatus'
);
}
}
29 changes: 8 additions & 21 deletions app/Http/Livewire/Administration/TicketTypesDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Livewire\Administration;

use App\Core\CrudDialogHelper;
use App\Models\Icon;
use App\Models\TicketType;
use Closure;
Expand All @@ -10,7 +11,6 @@
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
Expand All @@ -20,9 +20,9 @@
class TicketTypesDialog extends Component implements HasForms
{
use InteractsWithForms;
use CrudDialogHelper;

public TicketType $type;
public bool $deleteConfirmationOpened = false;

protected $listeners = ['doDeleteType', 'cancelDeleteType'];

Expand Down Expand Up @@ -171,24 +171,11 @@ public function cancelDeleteType(): void
*/
public function deleteType(): void
{
$this->deleteConfirmationOpened = true;
Notification::make()
->warning()
->title(__('Type deletion'))
->body(__('Are you sure you want to delete this type?'))
->actions([
Action::make('confirm')
->label(__('Confirm'))
->color('danger')
->button()
->close()
->emit('doDeleteType'),
Action::make('cancel')
->label(__('Cancel'))
->close()
->emit('cancelDeleteType')
])
->persistent()
->send();
$this->deleteConfirmation(
__('Type deletion'),
__('Are you sure you want to delete this type?'),
'doDeleteType',
'cancelDeleteType'
);
}
}
28 changes: 8 additions & 20 deletions app/Http/Livewire/Administration/UsersDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Livewire\Administration;

use App\Core\CrudDialogHelper;
use App\Models\CompanyUser;
use App\Models\User;
use App\Notifications\UserCreatedNotification;
Expand All @@ -23,9 +24,9 @@
class UsersDialog extends Component implements HasForms
{
use InteractsWithForms;
use CrudDialogHelper;

public User $user;
public bool $deleteConfirmationOpened = false;

protected $listeners = ['doDeleteUser', 'cancelDeleteUser'];

Expand Down Expand Up @@ -260,24 +261,11 @@ public function cancelDeleteUser(): void
*/
public function deleteUser(): void
{
$this->deleteConfirmationOpened = true;
Notification::make()
->warning()
->title(__('User deletion'))
->body(__('Are you sure you want to delete this user?'))
->actions([
Action::make('confirm')
->label(__('Confirm'))
->color('danger')
->button()
->close()
->emit('doDeleteUser'),
Action::make('cancel')
->label(__('Cancel'))
->close()
->emit('cancelDeleteUser')
])
->persistent()
->send();
$this->deleteConfirmation(
__('User deletion'),
__('Are you sure you want to delete this user?'),
'doDeleteUser',
'cancelDeleteUser'
);
}
}
28 changes: 8 additions & 20 deletions app/Http/Livewire/ProjectsDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Livewire;

use App\Core\CrudDialogHelper;
use App\Models\Project;
use App\Models\User;
use App\Notifications\ProjectCreatedNotification;
Expand All @@ -18,9 +19,9 @@
class ProjectsDialog extends Component implements HasForms
{
use InteractsWithForms;
use CrudDialogHelper;

public Project $project;
public bool $deleteConfirmationOpened = false;

protected $listeners = ['doDeleteProject', 'cancelDeleteProject'];

Expand Down Expand Up @@ -148,24 +149,11 @@ public function cancelDeleteProject(): void
*/
public function deleteProject(): void
{
$this->deleteConfirmationOpened = true;
Notification::make()
->warning()
->title(__('Project deletion'))
->body(__('Are you sure you want to delete this project?'))
->actions([
Action::make('confirm')
->label(__('Confirm'))
->color('danger')
->button()
->close()
->emit('doDeleteProject'),
Action::make('cancel')
->label(__('Cancel'))
->close()
->emit('cancelDeleteProject')
])
->persistent()
->send();
$this->deleteConfirmation(
__('Project deletion'),
__('Are you sure you want to delete this project?'),
'doDeleteProject',
'cancelDeleteProject'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class="rounded-lg flex flex-row justify-center items-center text-center gap-2
@if($company->id && auth()->user()->can('Delete companies'))
<button type="button"
wire:loading.attr="disabled" {!! $deleteConfirmationOpened ? 'disabled' : '' !!}
wire:click="deletePriority"
wire:click="deleteCompany"
class="rounded-lg flex flex-row justify-center items-center text-center text-white bg-red-700
disabled:bg-red-400 bg-opacity-90 hover:bg-opacity-100 shadow hover:shadow-lg
disabled:hover:shadow px-10 py-3 text-sm mt-5"
Expand Down

0 comments on commit 1eba9da

Please sign in to comment.