@tech4good/angular-schematics 21.4.0 → 21.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/package.json +1 -1
- package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +2 -1
- package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +2 -1
- package/src/entity/index.js +57 -0
- package/src/entity/index.js.map +1 -1
- package/src/entity/schema.json +4 -0
- package/src/ng-add/files/.firebaserc.template +2 -1
- package/src/ng-add/files/.gitignore.template +2 -0
- package/src/ng-add/files/bigquery/queries/active_time_by_route.sql.template +34 -0
- package/src/ng-add/files/bigquery/scripts/export_entities.py.template +143 -0
- package/src/ng-add/files/bigquery/scripts/run_query.py.template +167 -0
- package/src/ng-add/files/bigquery/views/events_flat.sql.template +60 -0
- package/src/ng-add/files/bigquery/views/logs_latest.sql.template +34 -0
- package/src/ng-add/files/docs-infra/analytics-guide.md.template +170 -0
- package/src/ng-add/files/docs-infra/authentication-architecture.md.template +270 -0
- package/src/ng-add/files/docs-infra/infrastructure-guide.md.template +16 -10
- package/src/ng-add/files/firebase.json.template +6 -0
- package/src/ng-add/files/firebase.logs.json.template +5 -0
- package/src/ng-add/files/firestore.indexes.json.template +112 -0
- package/src/ng-add/files/firestore.logs.rules.spec.ts.template +100 -0
- package/src/ng-add/files/firestore.logs.rules.template +8 -0
- package/src/ng-add/files/firestore.rules.spec.ts.template +84 -15
- package/src/ng-add/files/firestore.rules.template +29 -17
- package/src/ng-add/files/functions/.gitignore.template +3 -0
- package/src/ng-add/files/functions/package.json.template +12 -0
- package/src/ng-add/files/functions/src/index.ts.template +44 -0
- package/src/ng-add/files/functions/tsconfig.json.template +13 -0
- package/src/ng-add/files/jest.config.ts.template +1 -1
- package/src/ng-add/files/package.json.template +7 -4
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.html.template +3 -1
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.spec.ts.template +6 -8
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.ts.template +2 -0
- package/src/ng-add/files/src/app/app.component.html.template +2 -2
- package/src/ng-add/files/src/app/app.component.ts.template +2 -0
- package/src/ng-add/files/src/app/app.routes.ts.template +6 -0
- package/src/ng-add/files/src/app/auth-routing.spec.ts.template +9 -4
- package/src/ng-add/files/src/app/core/analytics/log.service.ts.template +26 -4
- package/src/ng-add/files/src/app/core/analytics/time-analytics.service.spec.ts.template +145 -2
- package/src/ng-add/files/src/app/core/analytics/time-analytics.service.ts.template +355 -149
- package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +6 -1
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.spec.ts.template +38 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.ts.template +3 -2
- package/src/ng-add/files/src/app/core/auth/guards/require-auth-and-consent.guard.ts.template +10 -3
- package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +11 -5
- package/src/ng-add/files/src/app/core/firebase/database.service.ts.template +34 -17
- package/src/ng-add/files/src/app/core/firebase/email-link-context.service.spec.ts.template +59 -0
- package/src/ng-add/files/src/app/core/firebase/email-link-context.service.ts.template +147 -0
- package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +104 -17
- package/src/ng-add/files/src/app/core/firebase/firebase.service.spec.ts.template +116 -0
- package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +367 -70
- package/src/ng-add/files/src/app/core/store/app.store.ts.template +4 -1
- package/src/ng-add/files/src/app/core/store/auth/auth.mock.ts.template +52 -66
- package/src/ng-add/files/src/app/core/store/auth/auth.store.spec.ts.template +127 -0
- package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +216 -147
- package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +2 -4
- package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +1 -1
- package/src/ng-add/files/src/app/core/store/user-private/user-private.model.ts.template +1 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.html.template +4 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.scss.template +1 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.ts.template +38 -0
- package/src/ng-add/files/src/app/first-time/consent/consent.component.html.template +172 -48
- package/src/ng-add/files/src/app/first-time/consent/consent.component.scss.template +31 -0
- package/src/ng-add/files/src/app/first-time/consent/consent.component.spec.ts.template +31 -3
- package/src/ng-add/files/src/app/first-time/consent/consent.component.ts.template +12 -11
- package/src/ng-add/files/src/app/first-time/consent/consent.guard.ts.template +5 -7
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.spec.ts.template +12 -1
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +93 -48
- package/src/ng-add/files/src/app/first-time/early-access/early-access.guard.ts.template +12 -2
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.html.template +18 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.scss.template +2 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.spec.ts.template +40 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.ts.template +76 -0
- package/src/ng-add/files/src/app/first-time/first-time-routing.spec.ts.template +14 -8
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.html.template +19 -7
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.scss.template +51 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +29 -5
- package/src/ng-add/files/src/app/first-time/landing/landing.component.html.template +2 -1
- package/src/ng-add/files/src/app/first-time/landing/landing.component.scss.template +12 -8
- package/src/ng-add/files/src/app/first-time/landing/landing.component.spec.ts.template +31 -10
- package/src/ng-add/files/src/app/first-time/landing/landing.component.ts.template +6 -19
- package/src/ng-add/files/src/app/first-time/login/login.component.html.template +58 -6
- package/src/ng-add/files/src/app/first-time/login/login.component.scss.template +151 -22
- package/src/ng-add/files/src/app/first-time/login/login.component.spec.ts.template +18 -38
- package/src/ng-add/files/src/app/first-time/login/login.component.ts.template +59 -31
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.html.template +12 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.scss.template +39 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.spec.ts.template +68 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.ts.template +20 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.html.template +24 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.scss.template +50 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.spec.ts.template +65 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.ts.template +59 -0
- package/src/ng-add/files/src/app/main/account-profile/guest-deletion-dialog.component.ts.template +51 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.html.template +50 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.scss.template +137 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.spec.ts.template +57 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.ts.template +59 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.html.template +133 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.scss.template +207 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.spec.ts.template +74 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.ts.template +130 -0
- package/src/ng-add/files/src/app/main/home/home.component.ts.template +0 -5
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.html.template +15 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.scss.template +79 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.spec.ts.template +59 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.ts.template +44 -0
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.html.template +45 -15
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.scss.template +103 -19
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.spec.ts.template +73 -9
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.ts.template +46 -18
- package/src/ng-add/files/src/environments/environment.prod.ts.template +1 -0
- package/src/ng-add/files/src/environments/environment.test.ts.template +1 -0
- package/src/ng-add/files/src/environments/environment.ts.template +1 -1
- package/src/ng-add/index_spec.d.ts +1 -0
- package/src/ng-add/index_spec.js +108 -0
- package/src/ng-add/index_spec.js.map +1 -0
- package/tsconfig.json +2 -2
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
OnInit,
|
|
4
|
+
OnDestroy,
|
|
5
|
+
ChangeDetectionStrategy,
|
|
6
|
+
computed,
|
|
7
|
+
Inject,
|
|
8
|
+
input,
|
|
9
|
+
output,
|
|
10
|
+
inject,
|
|
11
|
+
signal,
|
|
12
|
+
WritableSignal,
|
|
13
|
+
Signal,
|
|
14
|
+
Injector,
|
|
15
|
+
effect,
|
|
16
|
+
} from '@angular/core';
|
|
2
17
|
import { toObservable } from '@angular/core/rxjs-interop';
|
|
3
18
|
import { Observable } from 'rxjs';
|
|
4
19
|
import { filter, mergeMap } from 'rxjs/operators';
|
|
@@ -17,18 +32,14 @@ import { MatSnackBar } from '@angular/material/snack-bar';
|
|
|
17
32
|
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
18
33
|
import { UserStore } from 'src/app/core/store/user/user.store';
|
|
19
34
|
import { UserContextStore } from 'src/app/core/store/user-context/user-context.store';
|
|
35
|
+
import { environment } from 'src/environments/environment';
|
|
20
36
|
|
|
21
37
|
@Component({
|
|
22
38
|
selector: 'app-early-access',
|
|
23
39
|
templateUrl: './early-access.component.html',
|
|
24
40
|
styleUrl: './early-access.component.scss',
|
|
25
41
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
26
|
-
imports: [
|
|
27
|
-
NavbarComponent,
|
|
28
|
-
AsyncPipe,
|
|
29
|
-
SurveyFormComponent,
|
|
30
|
-
WaitlistViewComponent,
|
|
31
|
-
],
|
|
42
|
+
imports: [NavbarComponent, AsyncPipe, SurveyFormComponent, WaitlistViewComponent],
|
|
32
43
|
})
|
|
33
44
|
export class EarlyAccessComponent implements OnInit {
|
|
34
45
|
readonly authStore = inject(AuthStore);
|
|
@@ -54,13 +65,18 @@ export class EarlyAccessComponent implements OnInit {
|
|
|
54
65
|
outreachLeadName = 'OUTREACH_LEAD_NAME [FirstName]';
|
|
55
66
|
outreachLeadEmail = 'OUTREACH_LEAD_EMAIL [email@ucsc.edu]';
|
|
56
67
|
|
|
57
|
-
|
|
58
68
|
// --------------- COMPUTED DATA -----------------------
|
|
59
69
|
|
|
60
70
|
/** Waitlist data from app-state, user, and user-context. */
|
|
61
|
-
waitlistData: Signal<WaitlistData> = computed(() => {
|
|
62
|
-
const
|
|
63
|
-
|
|
71
|
+
waitlistData: Signal<WaitlistData | null> = computed(() => {
|
|
72
|
+
const currentUser = this.currentUser();
|
|
73
|
+
if (!currentUser) return null;
|
|
74
|
+
|
|
75
|
+
const userContext = this.userContextStore.selectFirst(
|
|
76
|
+
[['__userId', '==', currentUser.__id]],
|
|
77
|
+
{},
|
|
78
|
+
);
|
|
79
|
+
return { currentUser, userContext };
|
|
64
80
|
});
|
|
65
81
|
|
|
66
82
|
/** Waiting position number. */
|
|
@@ -71,10 +87,13 @@ export class EarlyAccessComponent implements OnInit {
|
|
|
71
87
|
const compareDate = user.joinedWaitlistAt || user._createdAt;
|
|
72
88
|
if (!compareDate) return '';
|
|
73
89
|
|
|
74
|
-
const posNum = await this.userStore.count(
|
|
75
|
-
[
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
const posNum = await this.userStore.count(
|
|
91
|
+
[
|
|
92
|
+
['joinedWaitlistAt', '<=', compareDate],
|
|
93
|
+
['accessState', '==', AccessState.WAITING],
|
|
94
|
+
],
|
|
95
|
+
{},
|
|
96
|
+
);
|
|
78
97
|
return this.nth(posNum === 0 ? 1 : posNum);
|
|
79
98
|
} catch (e) {
|
|
80
99
|
console.error('Error calculating position:', e);
|
|
@@ -88,9 +107,7 @@ export class EarlyAccessComponent implements OnInit {
|
|
|
88
107
|
filter((user: User) => !!user),
|
|
89
108
|
mergeMap(async (user) => {
|
|
90
109
|
try {
|
|
91
|
-
const total = await this.userStore.count([
|
|
92
|
-
['accessState', '==', AccessState.WAITING],
|
|
93
|
-
], {});
|
|
110
|
+
const total = await this.userStore.count([['accessState', '==', AccessState.WAITING]], {});
|
|
94
111
|
return `${total}`;
|
|
95
112
|
} catch (e) {
|
|
96
113
|
console.error('Error calculating total:', e);
|
|
@@ -102,10 +119,14 @@ export class EarlyAccessComponent implements OnInit {
|
|
|
102
119
|
/** Function for adding the appropriate suffix. */
|
|
103
120
|
nth(n: number): string {
|
|
104
121
|
switch (n % 10) {
|
|
105
|
-
case 1:
|
|
106
|
-
|
|
107
|
-
case
|
|
108
|
-
|
|
122
|
+
case 1:
|
|
123
|
+
return `${n}st`;
|
|
124
|
+
case 2:
|
|
125
|
+
return `${n}nd`;
|
|
126
|
+
case 3:
|
|
127
|
+
return `${n}rd`;
|
|
128
|
+
default:
|
|
129
|
+
return `${n}th`;
|
|
109
130
|
}
|
|
110
131
|
}
|
|
111
132
|
|
|
@@ -113,34 +134,58 @@ export class EarlyAccessComponent implements OnInit {
|
|
|
113
134
|
|
|
114
135
|
/** Submit background and interests. */
|
|
115
136
|
async submitInterest(formData: SurveyData) {
|
|
137
|
+
const waitlistData = this.waitlistData();
|
|
138
|
+
if (!waitlistData) return;
|
|
139
|
+
|
|
116
140
|
try {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
const hasWaitlist = environment.hasWaitlist;
|
|
142
|
+
const targetState = hasWaitlist ? AccessState.WAITING : AccessState.CONSENT;
|
|
143
|
+
|
|
144
|
+
await this.batch.batchWrite(
|
|
145
|
+
async (batchConfig) => {
|
|
146
|
+
await this.userStore.update(
|
|
147
|
+
waitlistData.currentUser.__id,
|
|
148
|
+
{
|
|
149
|
+
accessState: targetState,
|
|
150
|
+
joinedWaitlistAt: Timestamp.now(),
|
|
151
|
+
},
|
|
152
|
+
{ batchConfig },
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
if (waitlistData.userContext) {
|
|
156
|
+
this.userContextStore.update(
|
|
157
|
+
waitlistData.userContext.__id,
|
|
158
|
+
{
|
|
159
|
+
questionOne: formData.questionOne ?? '',
|
|
160
|
+
questionTwo: formData.questionTwo ?? '',
|
|
161
|
+
},
|
|
162
|
+
{ batchConfig },
|
|
163
|
+
);
|
|
164
|
+
} else {
|
|
165
|
+
this.userContextStore.add(
|
|
166
|
+
{
|
|
167
|
+
__userId: waitlistData.currentUser.__id,
|
|
168
|
+
questionOne: formData.questionOne ?? '',
|
|
169
|
+
questionTwo: formData.questionTwo ?? '',
|
|
170
|
+
},
|
|
171
|
+
{ batchConfig },
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
loading: this.loading,
|
|
177
|
+
snackBarConfig: {
|
|
178
|
+
successMessage: 'Submitted interest form!',
|
|
179
|
+
failureMessage: 'Failed to submit response',
|
|
180
|
+
undoOnAction: true,
|
|
181
|
+
config: { duration: 3000 },
|
|
182
|
+
},
|
|
142
183
|
},
|
|
143
|
-
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
if (!hasWaitlist) {
|
|
187
|
+
await this.router.navigate(['/consent'], { queryParams: this.route.snapshot.queryParams });
|
|
188
|
+
}
|
|
144
189
|
} catch (e) {
|
|
145
190
|
console.error(e);
|
|
146
191
|
}
|
|
@@ -4,6 +4,7 @@ import { map } from 'rxjs/operators';
|
|
|
4
4
|
import { AuthService } from '../../core/auth/auth.service';
|
|
5
5
|
import { User, AccessState } from '../../core/store/user/user.model';
|
|
6
6
|
import { hasAdminOverride } from '../../core/auth/guards/admin-override';
|
|
7
|
+
import { environment } from 'src/environments/environment';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Ensures the user is currently on the waitlist. Users who have already
|
|
@@ -17,12 +18,21 @@ export function handleAccess(
|
|
|
17
18
|
router: Router,
|
|
18
19
|
route: ActivatedRouteSnapshot,
|
|
19
20
|
state: RouterStateSnapshot,
|
|
21
|
+
hasWaitlist: boolean = environment.hasWaitlist,
|
|
20
22
|
): boolean {
|
|
21
23
|
if (hasAdminOverride(user, state.url)) return true;
|
|
22
24
|
|
|
23
|
-
const waitingStates =
|
|
25
|
+
const waitingStates = hasWaitlist ?
|
|
26
|
+
[AccessState.SUBMIT_INTEREST, AccessState.WAITING] :
|
|
27
|
+
[AccessState.SUBMIT_INTEREST];
|
|
24
28
|
if (user && !waitingStates.includes(user.accessState)) {
|
|
25
|
-
|
|
29
|
+
// Fully completed onboarding → go straight to home
|
|
30
|
+
if (user.consented && user.accessState === AccessState.DONE) {
|
|
31
|
+
router.navigate(['/home'], { queryParams: route.queryParams });
|
|
32
|
+
} else {
|
|
33
|
+
// Cleared waitlist but not yet consented → consent page
|
|
34
|
+
router.navigate(['/consent'], { queryParams: route.queryParams });
|
|
35
|
+
}
|
|
26
36
|
return false;
|
|
27
37
|
}
|
|
28
38
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<main class="email-link">
|
|
2
|
+
@if (isSubmitting()) {
|
|
3
|
+
<h1>Signing you in…</h1>
|
|
4
|
+
<p>Completing your secure email link.</p>
|
|
5
|
+
} @else {
|
|
6
|
+
<h1>Confirm your email</h1>
|
|
7
|
+
<p>Enter the email address where you received this link.</p>
|
|
8
|
+
<form (submit)="complete(); $event.preventDefault()">
|
|
9
|
+
<mat-form-field appearance="outline">
|
|
10
|
+
<mat-label>Email</mat-label>
|
|
11
|
+
<input matInput type="email" [formField]="form.email" autocomplete="email" />
|
|
12
|
+
@if (form.email().touched() && form.email().invalid()) { <mat-error>Enter a valid email address.</mat-error> }
|
|
13
|
+
</mat-form-field>
|
|
14
|
+
<button mat-flat-button color="primary" type="submit">Continue</button>
|
|
15
|
+
</form>
|
|
16
|
+
}
|
|
17
|
+
@if (message()) { <p role="status">{{ message() }}</p> }
|
|
18
|
+
</main>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Router } from '@angular/router';
|
|
2
|
+
import { render, screen, waitFor } from '@testing-library/angular';
|
|
3
|
+
import { EmailLinkComponent } from './email-link.component';
|
|
4
|
+
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
5
|
+
|
|
6
|
+
describe('EmailLinkComponent', () => {
|
|
7
|
+
it('completes automatically when the request email is stored in this browser', async () => {
|
|
8
|
+
const completeEmailSignInLink = jest.fn().mockResolvedValue({});
|
|
9
|
+
const getStoredEmailForEmailLink = jest.fn().mockReturnValue('learner@example.com');
|
|
10
|
+
const router = { navigate: jest.fn().mockResolvedValue(true) };
|
|
11
|
+
await render(EmailLinkComponent, {
|
|
12
|
+
providers: [
|
|
13
|
+
{
|
|
14
|
+
provide: AuthStore,
|
|
15
|
+
useValue: {
|
|
16
|
+
getStoredEmailForEmailLink,
|
|
17
|
+
completeEmailSignInLink,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{ provide: Router, useValue: router },
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await waitFor(() => expect(completeEmailSignInLink).toHaveBeenCalledWith(window.location.href, 'learner@example.com'));
|
|
25
|
+
expect(getStoredEmailForEmailLink).toHaveBeenCalledTimes(1);
|
|
26
|
+
expect(router.navigate).toHaveBeenCalledWith(['/home']);
|
|
27
|
+
expect(screen.queryByLabelText('Email')).not.toBeInTheDocument();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('asks for the email when the link is opened without same-browser state', async () => {
|
|
31
|
+
await render(EmailLinkComponent, {
|
|
32
|
+
providers: [
|
|
33
|
+
{ provide: AuthStore, useValue: { getStoredEmailForEmailLink: () => null } },
|
|
34
|
+
{ provide: Router, useValue: { navigate: jest.fn() } },
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
expect(screen.getByLabelText('Email')).toBeVisible();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ChangeDetectionStrategy, Component, inject, OnInit, signal } from '@angular/core';
|
|
2
|
+
import { form, FormField, required, email, submit } from '@angular/forms/signals';
|
|
3
|
+
import { Router } from '@angular/router';
|
|
4
|
+
import { MatButtonModule } from '@angular/material/button';
|
|
5
|
+
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
6
|
+
import { MatInputModule } from '@angular/material/input';
|
|
7
|
+
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Handles the completion phase of email magic-link authentication (`/email-link`).
|
|
11
|
+
*
|
|
12
|
+
* If the link was opened in the same browser session where it was requested, the target email
|
|
13
|
+
* is automatically retrieved from `EmailLinkContextService`. If opened in a different browser/device
|
|
14
|
+
* or if local storage was cleared, the component prompts the user to re-enter their email.
|
|
15
|
+
*/
|
|
16
|
+
@Component({
|
|
17
|
+
selector: 'app-email-link',
|
|
18
|
+
templateUrl: './email-link.component.html',
|
|
19
|
+
styleUrl: './email-link.component.scss',
|
|
20
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
21
|
+
imports: [FormField, MatButtonModule, MatFormFieldModule, MatInputModule],
|
|
22
|
+
})
|
|
23
|
+
export class EmailLinkComponent implements OnInit {
|
|
24
|
+
private readonly authStore = inject(AuthStore);
|
|
25
|
+
private readonly router = inject(Router);
|
|
26
|
+
private readonly storedEmail = this.authStore.getStoredEmailForEmailLink();
|
|
27
|
+
|
|
28
|
+
/** User-facing status or error message. */
|
|
29
|
+
readonly message = signal<string | null>(null);
|
|
30
|
+
|
|
31
|
+
/** Whether the email link completion request is currently processing. */
|
|
32
|
+
readonly isSubmitting = signal(Boolean(this.storedEmail));
|
|
33
|
+
|
|
34
|
+
/** Signal form model for the manual email entry fallback. */
|
|
35
|
+
readonly emailModel = signal({
|
|
36
|
+
email: this.storedEmail || '',
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/** Signal-based form validation schema for email input. */
|
|
40
|
+
readonly form = form(this.emailModel, (s) => {
|
|
41
|
+
required(s.email, { message: 'Email is required' });
|
|
42
|
+
email(s.email, { message: 'Enter a valid email address.' });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
async ngOnInit(): Promise<void> {
|
|
46
|
+
if (this.storedEmail) await this.completeWith(this.storedEmail);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Triggers manual completion when the user submits their email address. */
|
|
50
|
+
async complete(): Promise<void> {
|
|
51
|
+
await submit(this.form, async () => {
|
|
52
|
+
await this.completeWith(this.emailModel().email);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Verifies the email link URL and completes sign-in or account linking via AuthStore.
|
|
58
|
+
*/
|
|
59
|
+
private async completeWith(email: string): Promise<void> {
|
|
60
|
+
this.isSubmitting.set(true);
|
|
61
|
+
this.message.set(null);
|
|
62
|
+
try {
|
|
63
|
+
await this.authStore.completeEmailSignInLink(window.location.href, email);
|
|
64
|
+
await this.router.navigate(['/home']);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
const code = (error as { code?: string }).code;
|
|
67
|
+
this.message.set(
|
|
68
|
+
code === 'auth/link-requires-original-session' ?
|
|
69
|
+
'Return to the browser where you started this account upgrade to save that guest progress.' :
|
|
70
|
+
'This sign-in link is invalid, expired, or for a different email. Request a new link and try again.',
|
|
71
|
+
);
|
|
72
|
+
} finally {
|
|
73
|
+
this.isSubmitting.set(false);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -18,20 +18,22 @@ import { createMockUser } from '../core/store/user/user.mock';
|
|
|
18
18
|
describe('First-Time / Onboarding Routing', () => {
|
|
19
19
|
let harness: RouterTestingHarness;
|
|
20
20
|
let router: Router;
|
|
21
|
-
let mockAuthService: { resolveUser: jest.Mock };
|
|
21
|
+
let mockAuthService: { resolveUser: jest.Mock; resolveSession: jest.Mock };
|
|
22
22
|
let mockUserSignal: any;
|
|
23
23
|
|
|
24
24
|
beforeEach(async () => {
|
|
25
25
|
mockAuthService = {
|
|
26
26
|
resolveUser: jest.fn().mockReturnValue(of(null)),
|
|
27
|
+
resolveSession: jest.fn().mockReturnValue(of(null)),
|
|
27
28
|
};
|
|
28
29
|
mockUserSignal = signal(null);
|
|
30
|
+
const mockAfUserSignal = signal(null);
|
|
29
31
|
|
|
30
32
|
await TestBed.configureTestingModule({
|
|
31
33
|
providers: [
|
|
32
34
|
provideRouter(routes),
|
|
33
35
|
{ provide: AuthService, useValue: mockAuthService },
|
|
34
|
-
{ provide: AuthStore, useValue: { user: mockUserSignal } },
|
|
36
|
+
{ provide: AuthStore, useValue: { user: mockUserSignal, afUser: mockAfUserSignal } },
|
|
35
37
|
{ provide: DATABASE_SERVICE, useClass: FirebaseMockService },
|
|
36
38
|
{ provide: BATCH_WRITE_SERVICE, useClass: BatchWriteMockService },
|
|
37
39
|
{ provide: LOG_SERVICE, useClass: LogInDevService },
|
|
@@ -46,6 +48,7 @@ describe('First-Time / Onboarding Routing', () => {
|
|
|
46
48
|
beforeEach(() => {
|
|
47
49
|
const u = createMockUser({ accessState: AccessState.SUBMIT_INTEREST, consented: false });
|
|
48
50
|
mockAuthService.resolveUser.mockReturnValue(of(u));
|
|
51
|
+
mockAuthService.resolveSession.mockReturnValue(of({ isAnonymous: false, emailVerified: true }));
|
|
49
52
|
mockUserSignal.set(u);
|
|
50
53
|
});
|
|
51
54
|
|
|
@@ -72,6 +75,7 @@ describe('First-Time / Onboarding Routing', () => {
|
|
|
72
75
|
beforeEach(() => {
|
|
73
76
|
const u = createMockUser({ accessState: AccessState.CONSENT, consented: false });
|
|
74
77
|
mockAuthService.resolveUser.mockReturnValue(of(u));
|
|
78
|
+
mockAuthService.resolveSession.mockReturnValue(of({ isAnonymous: false, emailVerified: true }));
|
|
75
79
|
mockUserSignal.set(u);
|
|
76
80
|
});
|
|
77
81
|
|
|
@@ -87,10 +91,11 @@ describe('First-Time / Onboarding Routing', () => {
|
|
|
87
91
|
expect(router.url).toEqual('/consent');
|
|
88
92
|
});
|
|
89
93
|
|
|
90
|
-
it('should intercept navigation to /home and redirect to /consent', async () => {
|
|
94
|
+
it('should intercept navigation to /home and redirect to /consent with returnUrl', async () => {
|
|
91
95
|
await harness.navigateByUrl('/home');
|
|
92
96
|
await harness.fixture.whenStable();
|
|
93
|
-
expect(router.url).
|
|
97
|
+
expect(router.url).toContain('/consent');
|
|
98
|
+
expect(router.url).toContain('returnUrl');
|
|
94
99
|
});
|
|
95
100
|
});
|
|
96
101
|
|
|
@@ -98,6 +103,7 @@ describe('First-Time / Onboarding Routing', () => {
|
|
|
98
103
|
beforeEach(() => {
|
|
99
104
|
const fullyOnboardedUser = createMockUser({ accessState: AccessState.DONE, consented: true });
|
|
100
105
|
mockAuthService.resolveUser.mockReturnValue(of(fullyOnboardedUser));
|
|
106
|
+
mockAuthService.resolveSession.mockReturnValue(of({ isAnonymous: false, emailVerified: true }));
|
|
101
107
|
mockUserSignal.set(fullyOnboardedUser);
|
|
102
108
|
});
|
|
103
109
|
|
|
@@ -107,17 +113,17 @@ describe('First-Time / Onboarding Routing', () => {
|
|
|
107
113
|
expect(router.url).toEqual('/home');
|
|
108
114
|
});
|
|
109
115
|
|
|
110
|
-
it('should intercept navigation to /early-access and redirect to /
|
|
111
|
-
// earlyAccessGuard
|
|
116
|
+
it('should intercept navigation to /early-access and redirect to /home (skipping /consent)', async () => {
|
|
117
|
+
// earlyAccessGuard detects consented+DONE user and redirects directly to /home
|
|
112
118
|
await harness.navigateByUrl('/early-access');
|
|
113
119
|
await harness.fixture.whenStable();
|
|
114
120
|
expect(router.url).toEqual('/home');
|
|
115
121
|
});
|
|
116
122
|
|
|
117
|
-
it('should
|
|
123
|
+
it('should allow navigation to /consent (page is always readable)', async () => {
|
|
118
124
|
await harness.navigateByUrl('/consent');
|
|
119
125
|
await harness.fixture.whenStable();
|
|
120
|
-
expect(router.url).toEqual('/
|
|
126
|
+
expect(router.url).toEqual('/consent');
|
|
121
127
|
});
|
|
122
128
|
});
|
|
123
129
|
});
|
|
@@ -4,14 +4,26 @@
|
|
|
4
4
|
<div class="hero-subtitle">
|
|
5
5
|
<app-rotating-quotes [sentences]="sentences"></app-rotating-quotes>
|
|
6
6
|
</div>
|
|
7
|
-
<
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
<div class="cta-actions">
|
|
8
|
+
<a class="cta-button" href="/login" (click)="onGetStarted($event)">Get started</a>
|
|
9
|
+
@if (showGuestLogin()) {
|
|
10
|
+
<button
|
|
11
|
+
class="try-guest"
|
|
12
|
+
type="button"
|
|
13
|
+
[disabled]="isGuestLoading()"
|
|
14
|
+
(click)="tryWithoutLoggingIn()"
|
|
15
|
+
>
|
|
16
|
+
@if (isGuestLoading()) {
|
|
17
|
+
<svg class="spinner-icon" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
18
|
+
<path d="M21 12a9 9 0 1 1-6.219-8.56"/>
|
|
19
|
+
</svg>
|
|
20
|
+
<span>Creating guest session...</span>
|
|
21
|
+
} @else {
|
|
22
|
+
<span>Try without logging in</span>
|
|
23
|
+
}
|
|
24
|
+
</button>
|
|
13
25
|
}
|
|
14
|
-
</
|
|
26
|
+
</div>
|
|
15
27
|
</div>
|
|
16
28
|
<div class="hero-visual" animate.enter="animate-fade-in-up">
|
|
17
29
|
<img src="/images/abstract.png" alt="Abstract illustration placeholder" />
|
|
@@ -37,6 +37,18 @@
|
|
|
37
37
|
margin-bottom: 40px;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
.cta-actions {
|
|
41
|
+
display: flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
justify-content: center;
|
|
44
|
+
gap: 16px;
|
|
45
|
+
flex-wrap: wrap;
|
|
46
|
+
|
|
47
|
+
@media (min-width: 900px) {
|
|
48
|
+
justify-content: flex-start;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
40
52
|
.cta-button {
|
|
41
53
|
background-color: #0E7490;
|
|
42
54
|
color: #FFFFFF;
|
|
@@ -51,6 +63,7 @@
|
|
|
51
63
|
display: inline-flex;
|
|
52
64
|
align-items: center;
|
|
53
65
|
gap: 8px;
|
|
66
|
+
text-decoration: none;
|
|
54
67
|
|
|
55
68
|
&:hover:not(:disabled) {
|
|
56
69
|
background-color: #155E75;
|
|
@@ -73,6 +86,35 @@
|
|
|
73
86
|
stroke: #FFFFFF !important;
|
|
74
87
|
}
|
|
75
88
|
}
|
|
89
|
+
|
|
90
|
+
.try-guest {
|
|
91
|
+
display: inline-flex;
|
|
92
|
+
align-items: center;
|
|
93
|
+
gap: 8px;
|
|
94
|
+
margin: 0;
|
|
95
|
+
padding: 12px 16px;
|
|
96
|
+
border: 1px solid transparent;
|
|
97
|
+
border-radius: 8px;
|
|
98
|
+
background: transparent;
|
|
99
|
+
color: #0e7490;
|
|
100
|
+
cursor: pointer;
|
|
101
|
+
font: inherit;
|
|
102
|
+
font-weight: 600;
|
|
103
|
+
|
|
104
|
+
&:hover:not(:disabled) {
|
|
105
|
+
background-color: rgba(14, 116, 144, 0.08);
|
|
106
|
+
color: #155e75;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
&:disabled {
|
|
110
|
+
opacity: 0.65;
|
|
111
|
+
cursor: wait;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.spinner-icon {
|
|
115
|
+
animation: spin 0.8s linear infinite;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
76
118
|
}
|
|
77
119
|
|
|
78
120
|
.hero-visual {
|
|
@@ -90,3 +132,12 @@
|
|
|
90
132
|
}
|
|
91
133
|
}
|
|
92
134
|
}
|
|
135
|
+
|
|
136
|
+
@keyframes spin {
|
|
137
|
+
from {
|
|
138
|
+
transform: rotate(0deg);
|
|
139
|
+
}
|
|
140
|
+
to {
|
|
141
|
+
transform: rotate(360deg);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -1,20 +1,44 @@
|
|
|
1
|
-
import { Component, ChangeDetectionStrategy,
|
|
2
|
-
import {
|
|
1
|
+
import { Component, ChangeDetectionStrategy, inject, input, signal } from '@angular/core';
|
|
2
|
+
import { Router } from '@angular/router';
|
|
3
3
|
import { RotatingQuotesComponent } from '../rotating-quotes/rotating-quotes.component';
|
|
4
|
+
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
4
5
|
|
|
5
6
|
@Component({
|
|
6
7
|
selector: 'app-hero',
|
|
7
8
|
templateUrl: './hero.component.html',
|
|
8
9
|
styleUrl: './hero.component.scss',
|
|
9
10
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
10
|
-
imports: [RotatingQuotesComponent
|
|
11
|
+
imports: [RotatingQuotesComponent],
|
|
11
12
|
})
|
|
12
13
|
export class HeroComponent {
|
|
14
|
+
private readonly authStore = inject(AuthStore);
|
|
15
|
+
private readonly router = inject(Router);
|
|
16
|
+
|
|
13
17
|
readonly sentences = [
|
|
14
18
|
'First generic placeholder quote.',
|
|
15
19
|
'Second generic placeholder quote.',
|
|
16
20
|
'Third generic placeholder quote.',
|
|
17
21
|
];
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
showGuestLogin = input<boolean>(true);
|
|
23
|
+
|
|
24
|
+
readonly isGuestLoading = signal(false);
|
|
25
|
+
|
|
26
|
+
onGetStarted(event: Event) {
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
this.router.navigate(['/login']);
|
|
30
|
+
}, 0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async tryWithoutLoggingIn() {
|
|
34
|
+
if (this.isGuestLoading()) return;
|
|
35
|
+
this.isGuestLoading.set(true);
|
|
36
|
+
try {
|
|
37
|
+
await this.authStore.loginAnonymously();
|
|
38
|
+
await this.router.navigate(['/home']);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error('[HeroComponent] Guest login failed:', error);
|
|
41
|
+
this.isGuestLoading.set(false);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
20
44
|
}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
@use 'variables' as *;
|
|
2
|
+
|
|
1
3
|
:host {
|
|
2
4
|
display: block;
|
|
3
5
|
font-family: 'Inter', sans-serif;
|
|
4
6
|
color: #303030;
|
|
5
7
|
line-height: 1.6;
|
|
8
|
+
min-height: 100vh;
|
|
9
|
+
background: $bg-primary;
|
|
10
|
+
}
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
12
|
+
.landing-container {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
min-height: calc(100vh - 70px);
|
|
18
|
+
width: 100%;
|
|
15
19
|
}
|