website cleanup
This commit is contained in:
@@ -1,22 +1,27 @@
|
||||
import { RacesApiClient } from '@/lib/api/races/RacesApiClient';
|
||||
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
|
||||
import { TeamsApiClient } from '@/lib/api/teams/TeamsApiClient';
|
||||
import { AuthApiClient } from '@/lib/api/auth/AuthApiClient';
|
||||
import type { AllLeaguesWithCapacityDTO } from '@/lib/types/generated/AllLeaguesWithCapacityDTO';
|
||||
import type { GetAllTeamsOutputDTO } from '@/lib/types/generated/GetAllTeamsOutputDTO';
|
||||
import type { RacesPageDataDTO } from '@/lib/types/generated/RacesPageDataDTO';
|
||||
import type { LeagueSummaryDTO } from '@/lib/types/generated/LeagueSummaryDTO';
|
||||
import type { LeagueWithCapacityDTO } from '@/lib/types/generated/LeagueWithCapacityDTO';
|
||||
import type { TeamListItemDTO } from '@/lib/types/generated/TeamListItemDTO';
|
||||
import type { SignupParamsDTO } from '@/lib/types/generated/SignupParamsDTO';
|
||||
import type { AuthSessionDTO } from '@/lib/types/generated/AuthSessionDTO';
|
||||
import { RacesPageViewModel } from '@/lib/view-models/RacesPageViewModel';
|
||||
import { HomeDiscoveryViewModel } from '@/lib/view-models/HomeDiscoveryViewModel';
|
||||
import { LeagueCardViewModel } from '@/lib/view-models/LeagueCardViewModel';
|
||||
import { TeamCardViewModel } from '@/lib/view-models/TeamCardViewModel';
|
||||
import { UpcomingRaceCardViewModel } from '@/lib/view-models/UpcomingRaceCardViewModel';
|
||||
import { EmailSignupViewModel } from '@/lib/view-models/EmailSignupViewModel';
|
||||
|
||||
export class LandingService {
|
||||
constructor(
|
||||
private readonly racesApi: RacesApiClient,
|
||||
private readonly leaguesApi: LeaguesApiClient,
|
||||
private readonly teamsApi: TeamsApiClient,
|
||||
private readonly authApi: AuthApiClient,
|
||||
) {}
|
||||
|
||||
async getHomeDiscovery(): Promise<HomeDiscoveryViewModel> {
|
||||
@@ -29,10 +34,10 @@ export class LandingService {
|
||||
const racesVm = new RacesPageViewModel(racesDto);
|
||||
|
||||
const topLeagues = leaguesDto.leagues.slice(0, 4).map(
|
||||
(league: LeagueSummaryDTO) => new LeagueCardViewModel({
|
||||
(league: LeagueWithCapacityDTO) => new LeagueCardViewModel({
|
||||
id: league.id,
|
||||
name: league.name,
|
||||
description: 'Competitive iRacing league',
|
||||
description: league.description ?? 'Competitive iRacing league',
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -62,4 +67,36 @@ export class LandingService {
|
||||
upcomingRaces,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign up for early access with email
|
||||
* Uses the auth signup endpoint
|
||||
*/
|
||||
async signup(email: string): Promise<EmailSignupViewModel> {
|
||||
try {
|
||||
// Create signup params with default values for early access
|
||||
const signupParams: SignupParamsDTO = {
|
||||
email,
|
||||
password: 'temp_password_' + Math.random().toString(36).substring(7), // Temporary password
|
||||
displayName: email.split('@')[0], // Use email prefix as display name
|
||||
};
|
||||
|
||||
const session: AuthSessionDTO = await this.authApi.signup(signupParams);
|
||||
|
||||
if (session?.user?.userId) {
|
||||
return new EmailSignupViewModel(email, 'Welcome to GridPilot! Check your email to confirm.', 'success');
|
||||
} else {
|
||||
return new EmailSignupViewModel(email, 'Signup successful but session not created.', 'error');
|
||||
}
|
||||
} catch (error: any) {
|
||||
// Handle specific error cases
|
||||
if (error?.status === 429) {
|
||||
return new EmailSignupViewModel(email, 'Too many requests. Please try again later.', 'error');
|
||||
}
|
||||
if (error?.status === 409) {
|
||||
return new EmailSignupViewModel(email, 'This email is already registered.', 'info');
|
||||
}
|
||||
return new EmailSignupViewModel(email, 'Something broke. Try again?', 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user