5e146b8b60
FROM ghcr.io/relaticle/relaticle:latest + COPY de los 5 ficheros custom (migration + Notification + Action + 2 Observers) que implementan la notificación in-app/email a un team cuando se crea una Company o People vía API con creation_source=API. Se elige overlay en vez de fork completo para no perder las mejoras de upstream en cada build. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
76 lines
2.3 KiB
PHP
76 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\Team;
|
|
|
|
use App\Models\Company;
|
|
use App\Models\People;
|
|
use App\Models\Team;
|
|
use App\Notifications\NewApiLeadNotification;
|
|
use Filament\Actions\Action;
|
|
use Filament\Notifications\Notification as FilamentNotification;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Illuminate\Support\Facades\Notification as NotificationFacade;
|
|
|
|
final readonly class NotifyTeamOfNewApiLead
|
|
{
|
|
public function execute(Company|People $record): void
|
|
{
|
|
$team = $record->team;
|
|
|
|
if ($team === null || ! $team->notify_on_api_lead) {
|
|
return;
|
|
}
|
|
|
|
$recipients = $team->allUsers();
|
|
|
|
if ($recipients->isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
[$label, $url] = $this->resolveLabelAndUrl($record);
|
|
|
|
defer(function () use ($recipients, $label, $record, $url): void {
|
|
$recipients->each(function ($recipient) use ($label, $record, $url): void {
|
|
FilamentNotification::make()
|
|
->title("Nuevo {$label} desde la web: {$record->name}")
|
|
->actions([
|
|
Action::make('view')
|
|
->button()
|
|
->label("Ver {$label}")
|
|
->url($url)
|
|
->markAsRead(),
|
|
])
|
|
->icon(Heroicon::OutlinedUserPlus)
|
|
->iconColor('success')
|
|
->sendToDatabase($recipient);
|
|
});
|
|
|
|
NotificationFacade::send(
|
|
$recipients,
|
|
new NewApiLeadNotification($label, $record->name, $url)
|
|
);
|
|
});
|
|
}
|
|
|
|
/** @return array{0: string, 1: string} */
|
|
private function resolveLabelAndUrl(Company|People $record): array
|
|
{
|
|
if ($record instanceof Company) {
|
|
return ['empresa', $this->resolveUrl(\App\Filament\Resources\CompanyResource::class, $record)];
|
|
}
|
|
|
|
return ['candidato', $this->resolveUrl(\App\Filament\Resources\PeopleResource::class, $record)];
|
|
}
|
|
|
|
private function resolveUrl(string $resourceClass, Company|People $record): string
|
|
{
|
|
try {
|
|
return $resourceClass::getUrl('view', ['record' => $record]);
|
|
} catch (\Throwable) {
|
|
return '#';
|
|
}
|
|
}
|
|
}
|