feat: update User model and UserInfo component to use full_name attribute
This commit is contained in:
parent
520696fb67
commit
aa46893885
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Appends;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
@ -16,6 +17,7 @@
|
|||||||
use Spatie\Permission\Traits\HasRoles;
|
use Spatie\Permission\Traits\HasRoles;
|
||||||
|
|
||||||
#[Guarded(['id'])]
|
#[Guarded(['id'])]
|
||||||
|
#[Appends(['full_name'])]
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
use HasFactory, HasRoles, Notifiable, SoftDeletes, TwoFactorAuthenticatable;
|
use HasFactory, HasRoles, Notifiable, SoftDeletes, TwoFactorAuthenticatable;
|
||||||
@ -37,10 +39,17 @@ protected function active(Builder $query): void
|
|||||||
$query->where('is_active', true);
|
$query->where('is_active', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function name(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
get: fn() => $this->userProfile?->full_name ?? '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected function fullName(): Attribute
|
protected function fullName(): Attribute
|
||||||
{
|
{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
get: fn () => $this->userProfile?->full_name ?? '',
|
get: fn() => $this->userProfile?->full_name ?? '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,13 +14,13 @@ export function UserInfo({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Avatar className="h-8 w-8 overflow-hidden rounded-full">
|
<Avatar className="h-8 w-8 overflow-hidden rounded-full">
|
||||||
<AvatarImage src={user.avatar} alt={user.name} />
|
<AvatarImage src={user.avatar} alt={user.full_name} />
|
||||||
<AvatarFallback className="rounded-lg bg-neutral-200 text-black dark:bg-neutral-700 dark:text-white">
|
<AvatarFallback className="rounded-lg bg-neutral-200 text-black dark:bg-neutral-700 dark:text-white">
|
||||||
{getInitials(user.name)}
|
{getInitials(user.full_name)}
|
||||||
</AvatarFallback>
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<div className="grid flex-1 text-left text-sm leading-tight">
|
<div className="grid flex-1 text-left text-sm leading-tight">
|
||||||
<span className="truncate font-medium">{user.name}</span>
|
<span className="truncate font-medium">{user.full_name}</span>
|
||||||
{showEmail && (
|
{showEmail && (
|
||||||
<span className="truncate text-xs text-muted-foreground">
|
<span className="truncate text-xs text-muted-foreground">
|
||||||
{user.email}
|
{user.email}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
export type User = {
|
export type User = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
full_name: string;
|
||||||
email: string;
|
email: string;
|
||||||
avatar?: string;
|
avatar?: string;
|
||||||
email_verified_at: string | null;
|
email_verified_at: string | null;
|
||||||
@ -18,6 +19,7 @@ export type Auth = {
|
|||||||
export type Passkey = {
|
export type Passkey = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
full_name: string;
|
||||||
authenticator: string | null;
|
authenticator: string | null;
|
||||||
created_at_diff: string;
|
created_at_diff: string;
|
||||||
last_used_at_diff: string | null;
|
last_used_at_diff: string | null;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user