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

54 lines
1.5 KiB
TypeScript

import type { TeamMemberDTO } from '@/lib/types/generated/GetTeamMembersOutputDTO';
export class TeamMemberViewModel {
driverId: string;
driverName: string;
role: 'owner' | 'manager' | 'member';
joinedAt: string;
isActive: boolean;
avatarUrl: string;
private currentUserId: string;
private teamOwnerId: string;
constructor(dto: TeamMemberDTO, currentUserId: string, teamOwnerId: string) {
this.driverId = dto.driverId;
this.driverName = dto.driverName;
this.role = dto.role;
this.joinedAt = dto.joinedAt;
this.isActive = dto.isActive;
this.avatarUrl = dto.avatarUrl;
this.currentUserId = currentUserId;
this.teamOwnerId = teamOwnerId;
}
/** UI-specific: Role badge variant */
get roleBadgeVariant(): string {
switch (this.role) {
case 'owner': return 'primary';
case 'manager': 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();
}
}