Skip to content

Commit

Permalink
fix avatar colors
Browse files Browse the repository at this point in the history
  • Loading branch information
atmonshi committed Mar 23, 2024
1 parent adb11c0 commit 2e16a28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
26 changes: 14 additions & 12 deletions src/Middleware/SetTenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Closure;
use Filament\Support\Colors\Color;
use Filament\Support\Facades\FilamentColor;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use LaraZeus\Tartarus\Models\Company;
use Symfony\Component\HttpFoundation\Response;

class SetTenant
Expand All @@ -32,17 +32,19 @@ public function handle(Request $request, Closure $next): Response
return $next($request);
}

private function setPanelConfiguration(Model $tenant): void
private function setPanelConfiguration(Company $tenant): void
{
$colorName = str($tenant->primary_color ?? 'Blue')->title();
$color = constant("Filament\Support\Colors\Color::$colorName");
FilamentColor::register([
'primary' => $color,
'secondary' => Color::Amber,
'danger' => Color::Red,
'info' => Color::Blue,
'success' => Color::Green,
'warning' => Color::Yellow,
]);
if ($tenant->primary_color !== null) {
$colorName = str($tenant->primary_color)->title();
$color = constant("Filament\Support\Colors\Color::$colorName");
FilamentColor::register([
'primary' => $color,
'secondary' => Color::Amber,
'danger' => Color::Red,
'info' => Color::Blue,
'success' => Color::Green,
'warning' => Color::Yellow,
]);
}
}
}
10 changes: 7 additions & 3 deletions src/Models/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Company extends Model implements HasAvatar, HasCurrentTenantLabel, HasName

public function getTenantId(): ?string
{
// @phpstan-ignore-next-line
return auth()->user()?->company_id;
}

Expand Down Expand Up @@ -133,9 +134,12 @@ protected function defaultProfilePhotoUrl(): string
return mb_substr($segment, 0, 1);
})->join(' '));

$colorName = str(tenant()->primary_color ?? 'Blue')->title();
$color = constant("Filament\Support\Colors\Color::$colorName");
$bgColor = str(Rgb::fromString('rgb(' . $color[500] . ')')->toHex())->replace('#', '');
$bgColor = 'BFA577';
if (tenant()->primary_color !== null) {
$colorName = str(tenant()->primary_color)->title();
$color = constant("Filament\Support\Colors\Color::$colorName");
$bgColor = str(Rgb::fromString('rgb(' . $color[500] . ')')->toHex())->replace('#', '');
}

return sprintf('https://ui-avatars.com/api/?name=%s&color=FFFFFF&background=' . $bgColor, urlencode($name));
}
Expand Down

0 comments on commit 2e16a28

Please sign in to comment.