Skip to content

Commit d863ba7

Browse files
committed
Refactor: Replace old Toast 'Notice'
2 parents f3e68d0 + bf187bc commit d863ba7

14 files changed

Lines changed: 124 additions & 209 deletions

File tree

app/Livewire/Board/BoardComponent.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
use Illuminate\Database\Eloquent\Relations\HasMany;
1212
use Illuminate\Support\Collection;
1313
use Livewire\Component;
14-
use Support\Helpers\Concerns\NoticeType;
15-
use Support\Helpers\Concerns\UseNotice;
14+
use Support\Toastify\Enums\ToastType;
15+
use Support\Toastify\Toast;
1616

1717
class BoardComponent extends Component
1818
{
19-
use UseNotice;
19+
use Toast;
2020

2121
public Board $board;
2222

@@ -62,7 +62,7 @@ public function delete(): void
6262
{
6363
$this->board->delete();
6464

65-
$this->flashNotice(NoticeType::Success, 'Board was successfully deleted.');
65+
$this->toast('Board was successfully deleted.', type: ToastType::Success);
6666

6767
redirect()->route('home');
6868
}
@@ -71,7 +71,7 @@ public function archive(): void
7171
{
7272
$this->board->update(['archived' => true]);
7373

74-
$this->flashNotice(NoticeType::Success, 'Board was successfully archived.');
74+
$this->toast('Board was successfully archived.', type: ToastType::Success);
7575

7676
redirect()->route('home');
7777
}

app/Livewire/Card/CardComponent.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
use Domain\Timelog\Actions\CreateTimelogAction;
1111
use Illuminate\Contracts\View\View;
1212
use Livewire\Component;
13-
use Support\Helpers\Concerns\UseNotice;
13+
use Support\Toastify\Enums\ToastType;
14+
use Support\Toastify\Toast;
1415

1516
class CardComponent extends Component
1617
{
17-
use UseNotice;
18+
use Toast;
1819

1920
public Card $card;
2021

@@ -37,7 +38,7 @@ public function start(): void
3738

3839
$this->refreshCard($currentCard);
3940
$this->dispatch('task.started');
40-
$this->success('Task started successfully.');
41+
$this->toast('Task started successfully.', type: ToastType::Success);
4142
$this->toggleFavicon(true);
4243
}
4344

@@ -51,7 +52,7 @@ public function stop(): void
5152

5253
$this->refreshCard($currentCard);
5354
$this->dispatch('task.stoped');
54-
$this->success('Task Stoped successfully.');
55+
$this->toast('Task Stoped successfully.', type: ToastType::Success);
5556
$this->toggleFavicon(false);
5657
}
5758

@@ -60,7 +61,7 @@ public function archive(): void
6061
$this->card->update(['archived' => true]);
6162

6263
$this->dispatch("bucket-{$this->card->bucket_id}-updated");
63-
$this->success('Task Archived successfully.');
64+
$this->toast('Task Archived successfully.', type: ToastType::Success);
6465
}
6566

6667
private function toggleFavicon(bool $value): void
@@ -75,7 +76,7 @@ public function delete(): void
7576
$this->card->delete();
7677

7778
$this->dispatch("bucket-$bucketId-updated");
78-
$this->success('Task Deleted successfully.');
79+
$this->toast('Task Deleted successfully.', type: ToastType::Success);
7980
}
8081

8182
public function render(): View

app/Livewire/Pomodoro.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace App\Livewire;
66

7+
use Illuminate\Contracts\View\View;
78
use Illuminate\Support\Carbon;
89
use Illuminate\Support\Facades\Session;
910
use Livewire\Attributes\On;
@@ -86,7 +87,7 @@ public function onStoped(): void
8687
$this->dispatch('pomodoro.stoped');
8788
}
8889

89-
public function render()
90+
public function render(): View
9091
{
9192
return view('livewire.pomodoro');
9293
}

app/Livewire/Utils/Notice.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

resources/assets/css/app.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
@plugin "@tailwindcss/typography";
77
@plugin "@tailwindcss/forms";
88

9+
@source inline("bg-success bg-danger");
10+
911
@custom-variant dark (&:where([data-mode=dark], [data-mode=dark] *));
1012

1113
:root {
@@ -16,6 +18,8 @@
1618
--color-gray-300: #f7f7f7;
1719
--color-text: theme('colors.neutral.900');
1820
--color-blue: theme('colors.blue.600');
21+
--color-success: theme('colors.green.600');
22+
--color-danger: theme('colors.red.500');
1923
}
2024

2125
:root[data-mode=dark] {
@@ -24,6 +28,8 @@
2428
--color-gray-300: #0e3957;
2529
--color-text: theme('colors.white');
2630
--color-blue: theme('colors.blue.600');
31+
--color-success: theme('colors.green.600');
32+
--color-danger: theme('colors.red.500');
2733
}
2834

2935
@theme {
@@ -37,6 +43,8 @@
3743
--color-gray-300: var(--color-gray-300);
3844
--color-text: var(--color-text);
3945
--color-blue: var(--color-blue);
46+
--color-success: var(--color-success);
47+
--color-danger: var(--color-danger);
4048
}
4149

4250
@layer base {

resources/assets/js/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import 'preline/dist/dropdown';
44
import '@wotz/livewire-sortablejs';
5+
import '~/toastify.js';
56

67
document.addEventListener('livewire:initialized', () => {
78
window.addEventListener('refresh.preline.dropdown', () => {

resources/assets/js/toastify.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import Toastify from 'toastify-js';
2+
3+
document.addEventListener('livewire:initialized', () => {
4+
const tostifyCustomClose = globalThis.tostifyCustomClose = (el) => {
5+
const parent = el.closest('.toastify');
6+
const close = parent.querySelector('.toast-close');
7+
8+
close.click();
9+
}
10+
11+
window.addEventListener('toast', (event) => {
12+
const toastData = event.detail[0];
13+
14+
const toastMarkup = `
15+
<div class="max-w-xs bg-${toastData.className || 'primary'} text-sm text-white rounded-xl shadow-lg" role="alert" tabindex="-1" aria-labelledby="hs-toast-solid-color-teal-label">
16+
<div id="hs-toast-solid-color-red-label" class="flex p-4 gap-4">
17+
${toastData.text}
18+
<div class="ms-auto ${toastData.close ? '' : 'hidden'}">
19+
<button onclick="tostifyCustomClose(this)" type="button" class="inline-flex shrink-0 justify-center items-center size-5 rounded-lg cursor-pointer text-white hover:text-white hover:opacity-80 focus:outline-hidden focus:opacity-100" aria-label="Close">
20+
<span class="sr-only">Close</span>
21+
<svg class="shrink-0 size-4" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
22+
<path d="M18 6 6 18"></path>
23+
<path d="m6 6 12 12"></path>
24+
</svg>
25+
</button>
26+
</div>
27+
</div>
28+
</div>
29+
`;
30+
31+
Toastify({
32+
style: {},
33+
text: toastMarkup,
34+
gravity: toastData.gravity || 'top',
35+
position: toastData.position || 'right',
36+
//className: 'hs-toastify-on:opacity-100 opacity-0 fixed -top-10 end-10 z-90 transition-all duration-300 w-72 bg-white text-sm text-gray-700 border border-gray-200 rounded-xl shadow-lg [&>.toast-close]:hidden dark:bg-neutral-800 dark:border-neutral-700 dark:text-neutral-400',
37+
stopOnFocus: true,
38+
duration: toastData.duration || 3000,
39+
close: toastData.close,
40+
escapeMarkup: false,
41+
}).showToast();
42+
});
43+
});
44+

resources/views/livewire/utils/notice.blade.php

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/Support/Helpers/Concerns/UseNotice.php

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Support\Toastify\Enums;
6+
7+
enum ToastGravity: string
8+
{
9+
case Bottom = 'bottom';
10+
case Top = 'top';
11+
}

0 commit comments

Comments
 (0)