Files
gridpilot.gg/apps/website/lib/view-models/TeamMemberViewModel.ts
2025-12-18 00:08:47 +01:00

53 lines
1.4 KiB
TypeScript

// Note: No generated DTO available for TeamMember yet
interface TeamMemberDTO {
driverId: string;
driver?: any;
role: string;
joinedAt: string;
}
export class TeamMemberViewModel {
driverId: string;
driver?: any;
role: string;
joinedAt: string;
private currentUserId: string;
private teamOwnerId: string;
constructor(dto: TeamMemberDTO, currentUserId: string, teamOwnerId: string) {
Object.assign(this, dto);
this.currentUserId = currentUserId;
this.teamOwnerId = teamOwnerId;
}
/** UI-specific: Role badge variant */
get roleBadgeVariant(): string {
switch (this.role) {
case 'owner': return 'primary';
case 'captain': return 'secondary';
case 'member': return 'default';
default: return 'default';
}
}
/** UI-specific: Whether this member is the owner */
get isOwner(): boolean {
return this.driverId === this.teamOwnerId;
}
/** UI-specific: Whether current user can manage this member */
get canManage(): boolean {
return this.currentUserId === this.teamOwnerId && this.driverId !== this.currentUserId;
}
/** UI-specific: Whether this is the current user */
get isCurrentUser(): boolean {
return this.driverId === this.currentUserId;
}
/** UI-specific: Formatted joined date */
get formattedJoinedAt(): string {
return new Date(this.joinedAt).toLocaleDateString();
}
}