Skip to content

Commit

Permalink
Refactored toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
kreaweb.be committed Apr 13, 2024
1 parent bac18a0 commit a966731
Show file tree
Hide file tree
Showing 41 changed files with 179 additions and 261 deletions.
38 changes: 19 additions & 19 deletions app/Livewire/Backups/Manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Livewire\Component;
use Usernotnull\Toast\Concerns\WireToast;
use TallStackUi\Traits\Interactions;

class Manage extends Component
{
// ------------------------------------------------------------------------------
// -----------------------------------------------------------------------
// To make this BACKUP controller work, you need to :
// ------------------------------------------------------------------------------
// -----------------------------------------------------------------------
// 1. add and configure this to your .env :
//
// BACKUP_DISK="backups"
Expand All @@ -31,15 +31,15 @@ class Manage extends Component
// MAIL_ENCRYPTION=null
// MAIL_FROM_ADDRESS="[email protected]"
// MAIL_FROM_NAME="${APP_NAME}"
// ------------------------------------------------------------------------------
// -----------------------------------------------------------------------
// 2. add this to your config/filesystem.php :
//
// env('BACKUP_DISK', 'backups') => [
// 'driver' => 'local',
// 'root' => storage_path('app/' . env('BACKUP_DISK', 'backups')),
// 'throw' => false,
// ],
// ------------------------------------------------------------------------------
// -----------------------------------------------------------------------
// 3. configure this in your config/backup.php :
//
// // backup --> destination --> disks :
Expand All @@ -51,23 +51,24 @@ class Manage extends Component
// 'disks' => [
// env('BACKUP_DISK', 'backups'),
// ]
// ------------------------------------------------------------------------------
use WireToast;
// -----------------------------------------------------------------------
use Interactions;

public $backups;

public $backup_to_delete = '';

public $deleteConfirmed = false;

public function confirmDeletion(string $file_name)
// -----------------------------------------------------------------------
public function confirmDeletion(string $file_name): void
{
$this->backup_to_delete = $file_name;

$this->deleteConfirmed = true;
}

public function mount()
public function mount(): void
{
$this->backups = collect();

Expand Down Expand Up @@ -104,14 +105,14 @@ public function create()

Log::info("Backup (Manually) -- Backup started \r\n" . $output);

toast()->info(__('backup.created'), __('backup.backup'))->push();
$this->toast()->success(__('backup.backup'), __('backup.created'))->flash()->send();
} catch (Exception $e) {
Log::info("Backup (Manually) -- Backup failed \r\n" . $e->getMessage());

toast()->danger($e->getMessage(), __('backup.backup'))->push();
$this->toast()->error(__('backup.backup'), $e->getMessage())->flash()->send();
}

$this->mount();
$this->redirect('/backups');
}

public function download(string $file_name)
Expand All @@ -120,11 +121,11 @@ public function download(string $file_name)
$file = config('backup.backup.name') . '/' . $file_name;

if ($disk->exists($file)) {
toast()->info(__('backup.downloaded'), __('backup.backup'))->push();
$this->toast()->success(__('backup.backup'), __('backup.downloading'))->send();

return Storage::download(env('BACKUP_DISK', 'backups') . '/' . $file);
} else {
toast()->warning(__('backup.not_found'), __('backup.backup'))->push();
$this->toast()->error(__('backup.backup'), __('backup.not_found'))->send();
}
}

Expand All @@ -135,14 +136,12 @@ public function deleteBackup()
if ($disk->exists(config('backup.backup.name') . '/' . $this->backup_to_delete)) {
$disk->delete(config('backup.backup.name') . '/' . $this->backup_to_delete);

toast()->success($this->backup_to_delete . '<br/>' . __('backup.deleted'), __('backup.backup'))->doNotSanitize()->push();
$this->toast()->success(__('backup.backup'), $this->backup_to_delete . ' ' . __('backup.deleted'))->flash()->send();
} else {
toast()->warning(__('backup.not_found'), __('backup.backup'))->push();
$this->toast()->error(__('backup.backup'), __('backup.not_found'))->flash()->send();
}

$this->deleteConfirmed = false;

$this->mount();
$this->redirect('/backups');
}

protected function humanFilesize(mixed $bytes, int $decimals = 2)
Expand All @@ -153,6 +152,7 @@ protected function humanFilesize(mixed $bytes, int $decimals = 2)
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . @$sz[$factor];
}

// -----------------------------------------------------------------------
public function render()
{
return view('livewire.backups.manage');
Expand Down
18 changes: 11 additions & 7 deletions app/Livewire/Gedcom/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
use App\Livewire\Traits\TrimStringsAndConvertEmptyStringsToNull;
use Livewire\Component;
use Livewire\WithFileUploads;
use Usernotnull\Toast\Concerns\WireToast;
use TallStackUi\Traits\Interactions;

class Import extends Component
{
use Interactions;
use TrimStringsAndConvertEmptyStringsToNull;
use WireToast;
use WithFileUploads;

// -----------------------------------------------------------------------
public $user = null;

public $name = null;
Expand All @@ -21,6 +22,7 @@ class Import extends Component

public $file = null;

// -----------------------------------------------------------------------
public function rules()
{
return $rules = [
Expand All @@ -44,7 +46,7 @@ public function validationAttributes()
];
}

public function mount()
public function mount(): void
{
$this->user = Auth()->user();
}
Expand All @@ -58,24 +60,26 @@ public function createTeam()

}

toast()->success(__('app.created') . '.', __('app.save'))->pushOnNextPage();
$this->redirect('/search/');
$this->toast()->success(__('app.create'), __('app.created'))->flash()->send();

return $this->redirect('/search');
}
}

public function resetTeam()
public function resetTeam(): void
{
$this->mount();
}

public function isDirty()
public function isDirty(): bool
{
return
$this->name != null or
$this->description != null or
$this->file != null;
}

// -----------------------------------------------------------------------
public function render()
{
return view('livewire.gedcom.import');
Expand Down
25 changes: 11 additions & 14 deletions app/Livewire/People/Add/Child.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
use Intervention\Image\ImageManager;
use Livewire\Component;
use Livewire\WithFileUploads;
use Usernotnull\Toast\Concerns\WireToast;
use TallStackUi\Traits\Interactions;

class Child extends Component
{
use Interactions;
use TrimStringsAndConvertEmptyStringsToNull;
use WireToast;
use WithFileUploads;

// -----------------------------------------------------------------------
Expand All @@ -24,7 +24,7 @@ class Child extends Component
public ChildForm $childForm;

// -----------------------------------------------------------------------
public function mount()
public function mount(): void
{
$this->childForm->firstname = null;
$this->childForm->surname = null;
Expand All @@ -47,13 +47,15 @@ public function saveChild()
Person::findOrFail($validated['person_id'])->update([
'father_id' => $this->person->id,
]);

$this->toast()->success(__('app.save'), $this->person->name . ' ' . __('app.saved') . '.')->flash()->send();
} else {
Person::findOrFail($validated['person_id'])->update([
'mother_id' => $this->person->id,
]);
}

toast()->success(__('app.saved') . '.', __('app.saved'))->pushOnNextPage();
$this->toast()->success(__('app.save'), $this->person->name . ' ' . __('app.saved') . '.')->flash()->send();
}
} else {
if ($this->person->sex === 'm') {
$new_person = Person::create([
Expand Down Expand Up @@ -106,23 +108,18 @@ public function saveChild()
$this->childForm->image = null;
$this->childForm->iteration++;
} else {
toast()->danger(__('app.image_not_saved') . '.', __('app.save'))->pushOnNextPage();
$this->toast()->error(__('app.save'), __('app.image_not_saved') . '.')->flash()->send();
}
}

toast()->success(__('app.created') . '.', __('app.create'))->pushOnNextPage();
$this->toast()->success(__('app.create'), $new_person->name . ' ' . __('app.created') . '.')->flash()->send();
}

$this->redirect('/people/' . $this->person->id);
return $this->redirect('/people/' . $this->person->id);
}
}

public function resetChild()
{
$this->mount();
}

public function isDirty()
public function isDirty(): bool
{
return
$this->childForm->firstname or
Expand Down
38 changes: 15 additions & 23 deletions app/Livewire/People/Add/Partner.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
use App\Models\Couple;
use App\Models\Person;
use Livewire\Component;
use Usernotnull\Toast\Concerns\WireToast;
use TallStackUi\Traits\Interactions;

class Partner extends Component
{
use Interactions;
use TrimStringsAndConvertEmptyStringsToNull;
use WireToast;

// -----------------------------------------------------------------------
public $person;

public PartnerForm $partnerForm;

// -----------------------------------------------------------------------
public function mount()
public function mount(): void
{
$this->partnerForm->person2_id = null;

Expand All @@ -36,11 +36,10 @@ public function savePartner()
if ($this->isDirty()) {
$validated = $this->partnerForm->validate();

if ($this->noOverlap($validated['date_start'], $validated['date_end'])) {
$this->resetPartner();
toast()->danger('RELATIONSHIP OVERLAP !!')->push();
if ($this->hasOverlap($validated['date_start'], $validated['date_end'])) {
$this->toast()->error(__('app.create'), 'RELATIONSHIP OVERLAP !!')->send();
} else {
Couple::create([
$couple = Couple::create([
'person1_id' => $this->person->id,
'person2_id' => $validated['person2_id'],
'date_start' => $validated['date_start'] ? $validated['date_start'] : null,
Expand All @@ -50,26 +49,23 @@ public function savePartner()
'team_id' => auth()->user()->current_team_id,
]);

toast()->success(__('app.created') . '.', __('app.create'))->pushOnNextPage();
$this->redirect('/people/' . $this->person->id);
$this->toast()->success(__('app.create'), __('app.created'))->flash()->send();

return $this->redirect('/people/' . $this->person->id);
}
}
}

private function noOverlap($start, $end)
private function hasOverlap($start, $end): bool
{
$is_overlap = false;

if (! empty($start) or ! empty($end)) {
foreach ($this->person->couples as $couple) {
if (! empty($start) and ! empty($couple->date_start) and ! empty($couple->date_end)) {
if ($start >= $couple->date_start and $start <= $couple->date_end) {
if (! empty($couple->date_start) and ! empty($couple->date_end)) {
if (! empty($start) and $start >= $couple->date_start and $start <= $couple->date_end) {
$is_overlap = true;
}
}

if (! empty($end) and ! empty($couple->date_start) and ! empty($couple->date_end)) {
if ($end >= $couple->date_start and $end <= $couple->date_end) {
} elseif (! empty($end) and $end >= $couple->date_start and $end <= $couple->date_end) {
$is_overlap = true;
}
}
Expand All @@ -79,12 +75,7 @@ private function noOverlap($start, $end)
return $is_overlap;
}

public function resetPartner()
{
$this->mount();
}

public function isDirty()
public function isDirty(): bool
{
return
$this->partnerForm->person2_id != null or
Expand All @@ -94,6 +85,7 @@ public function isDirty()
$this->partnerForm->has_ended != false;
}

// ------------------------------------------------------------------------------
public function render()
{
$persons = Person::PartnerOffset($this->person->birth_date, $this->person->birth_year)
Expand Down
Loading

0 comments on commit a966731

Please sign in to comment.