Skip to content

Commit 0538e53

Browse files
committed
Refactor IncidentUpdateStatus badge component
1 parent 51c7c1f commit 0538e53

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

resources/views/components/incident-update-status.blade.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
shades: [200, 900],
66
),
77
]),
8-
]) }}>
8+
])->merge(['title' => $title]) }}>
99
<div class="absolute -left-[calc(28px+10px+13px)] top-4 flex h-7 w-7 items-center justify-center rounded-full bg-custom-200 dark:text-zinc-900">
10-
@svg($icon, 'h-5 w-5')
10+
@if ($icon)
11+
@svg($icon, 'size-5')
12+
@else
13+
<x-heroicon-m-flag class="size-4" />
14+
@endif
1115
</div>
1216
</div>

resources/views/components/incident.blade.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@
5656
<div class="prose-sm md:prose prose-zinc dark:prose-invert prose-a:text-primary-500 prose-a:underline prose-p:leading-normal">{!! $update->formattedMessage() !!}</div>
5757
</div>
5858
@endforeach
59-
<div class="relative py-4" x-data="{ timestamp: new Date(@js($incident->created_at)) }">
60-
<x-cachet::incident-update-status :status="$incident->status" />
59+
<div class="relative py-4" x-data="{ timestamp: new Date(@js($incident->created_at)) }">
60+
<x-cachet::incident-update-status />
6161

62-
<span class="text-xs text-zinc-500 dark:text-zinc-400">
63-
{{ $incident->created_at->diffForHumans() }} — <time datetime="{{ $incident->created_at->toW3cString() }}" x-text="timestamp.toLocaleString()"></time>
64-
</span>
65-
<div class="prose-sm md:prose prose-zinc dark:prose-invert prose-a:text-primary-500 prose-a:underline prose-p:leading-normal">{!! $incident->formattedMessage() !!}</div>
66-
</div>
62+
<span class="text-xs text-zinc-500 dark:text-zinc-400">
63+
{{ $incident->created_at->diffForHumans() }} — <time datetime="{{ $incident->created_at->toW3cString() }}" x-text="timestamp.toLocaleString()"></time>
64+
</span>
65+
<div class="prose-sm md:prose prose-zinc dark:prose-invert prose-a:text-primary-500 prose-a:underline prose-p:leading-normal">{!! $incident->formattedMessage() !!}</div>
66+
</div>
6767
</div>
6868
</div>
6969
</div>

src/Enums/IncidentStatusEnum.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function getLabel(): string
3939
self::identified => __('Identified'),
4040
self::watching => __('Watching'),
4141
self::fixed => __('Fixed'),
42+
default => __('Reported'),
4243
};
4344
}
4445

@@ -56,9 +57,9 @@ public function getColor(): string|array|null
5657
{
5758
return match ($this) {
5859
self::investigating => 'warning',
59-
self::identified => 'gray',
6060
self::watching => 'info',
6161
self::fixed => 'success',
62+
default => 'gray',
6263
};
6364
}
6465
}

src/View/Components/IncidentUpdateStatus.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Cachet\View\Components;
44

55
use Cachet\Enums\IncidentStatusEnum;
6-
use Cachet\Models\IncidentUpdate;
76
use Closure;
87
use Illuminate\Contracts\View\View;
98
use Illuminate\View\Component;
@@ -13,7 +12,7 @@ class IncidentUpdateStatus extends Component
1312
/**
1413
* Create a new component instance.
1514
*/
16-
public function __construct(public IncidentStatusEnum $status)
15+
public function __construct(public readonly ?IncidentStatusEnum $status = null)
1716
{
1817
//
1918
}
@@ -24,8 +23,9 @@ public function __construct(public IncidentStatusEnum $status)
2423
public function render(): View|Closure|string
2524
{
2625
return view('cachet::components.incident-update-status', [
27-
'color' => $this->status->getColor(),
28-
'icon' => $this->status->getIcon(),
26+
'title' => $this->status?->getLabel(),
27+
'color' => $this->status?->getColor() ?? 'gray',
28+
'icon' => $this->status?->getIcon(),
2929
]);
3030
}
3131
}

0 commit comments

Comments
 (0)