@tech4good/angular-schematics 20.2.0 → 20.3.1
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/.agents/skills/publish-npm/SKILL.md +2 -0
- package/.agents/skills/publish-npm/eval.yaml +1 -1
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +1 -0
- package/.t4g/agent-memory.db +0 -0
- package/CHANGELOG.md +56 -0
- package/README.md +16 -7
- package/commitlint.config.js +15 -0
- package/package.json +6 -2
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.scss.template +1 -0
- package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +1 -1
- package/src/ng-add/files/.gitignore.template +3 -0
- package/src/ng-add/files/package.json.template +3 -2
- package/src/ng-add/files/public/images/abstract.png +0 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.html.template +27 -22
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.scss.template +35 -4
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.ts.template +31 -75
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.html.template +25 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.scss.template +67 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.ts.template +74 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.animations.ts.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.html.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.scss.template +22 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.spec.ts.template +37 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.ts.template +36 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.animations.ts.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.html.template +11 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.scss.template +22 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.spec.ts.template +37 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.ts.template +47 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.html.template +52 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.scss.template +66 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.ts.template +220 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.animations.ts.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.html.template +81 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.scss.template +136 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.spec.ts.template +37 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.ts.template +118 -0
- package/src/ng-add/files/src/app/app.component.html.template +2 -0
- package/src/ng-add/files/src/app/app.component.ts.template +2 -0
- package/src/ng-add/files/src/app/app.routes.ts.template +14 -18
- package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +58 -0
- package/src/ng-add/files/src/app/core/auth/guards/admin-override.ts.template +9 -0
- package/src/ng-add/files/src/app/core/auth/guards/index.ts.template +11 -0
- package/src/ng-add/files/src/app/core/auth/guards/redirect-if-authenticated.guard.ts.template +42 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.ts.template +39 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-auth-and-consent.guard.ts.template +69 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-auth.guard.ts.template +35 -0
- package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +1 -1
- package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +7 -1
- package/src/ng-add/files/src/app/core/store/app.model.ts.template +1 -1
- package/src/ng-add/files/src/app/core/store/app.store.ts.template +71 -6
- package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +94 -53
- package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +5 -5
- package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +5 -7
- package/src/ng-add/files/src/app/core/store/user-context/user-context.mock.ts.template +3 -5
- package/src/ng-add/files/src/app/core/store/user-context/user-context.model.ts.template +2 -5
- package/src/ng-add/files/src/app/first-time/consent/consent.component.ts.template +4 -3
- package/src/ng-add/files/src/app/first-time/consent/consent.guard.ts.template +54 -0
- package/src/ng-add/files/src/app/first-time/early-access/early-access.animations.ts.template +6 -0
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.html.template +70 -52
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.scss.template +73 -6
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +59 -111
- package/src/ng-add/files/src/app/first-time/early-access/early-access.guard.ts.template +44 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.animations.ts.template +15 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.html.template +12 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.scss.template +79 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +20 -0
- package/src/ng-add/files/src/app/first-time/landing/landing.component.html.template +1 -1
- package/src/ng-add/files/src/app/first-time/landing/landing.component.scss.template +11 -8
- package/src/ng-add/files/src/app/first-time/landing/landing.component.ts.template +2 -0
- package/src/ng-add/files/src/app/first-time/landing/rotating-quotes/rotating-quotes.component.html.template +3 -0
- package/src/ng-add/files/src/app/first-time/landing/rotating-quotes/rotating-quotes.component.scss.template +26 -0
- package/src/ng-add/files/src/app/first-time/landing/rotating-quotes/rotating-quotes.component.ts.template +52 -0
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.html.template +21 -0
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.scss.template +71 -0
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.ts.template +70 -0
- package/src/ng-add/files/src/app/shared/hint-visibility/hint-visibility.directive.ts.template +131 -0
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.html.template +1 -1
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.ts.template +1 -1
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.ts.template +2 -2
- package/src/ng-add/files/src/environments/environment.ts.template +1 -1
- package/src/ng-add/files/src/index.html.template +3 -2
- package/src/ng-add/files/src/styles/_variables.scss.template +1 -0
- package/src/ng-add/files/src/styles.scss.template +4 -2
- package/src/ng-add/files/src/app/core/auth/auth.guard.ts.template +0 -96
|
@@ -92,15 +92,52 @@ export function withEntitiesAndSelectMethods<S extends AnyEntity>() {
|
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
|
+
function serializeMockDBData(data: any): string {
|
|
97
|
+
return JSON.stringify(data, (key, value) => {
|
|
98
|
+
if (value && typeof value === 'object' && 'seconds' in value && 'nanoseconds' in value) {
|
|
99
|
+
return { __type: 'Timestamp', seconds: value.seconds, nanoseconds: value.nanoseconds };
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
|
+
function deserializeMockDBData(jsonString: string): any {
|
|
107
|
+
return JSON.parse(jsonString, (key, value) => {
|
|
108
|
+
if (value && typeof value === 'object' && value.__type === 'Timestamp') {
|
|
109
|
+
return new Timestamp(value.seconds, value.nanoseconds);
|
|
110
|
+
}
|
|
111
|
+
return value;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function withEntitiesForMockDB<S extends AnyEntity>(collectionName: string) {
|
|
96
116
|
return signalStoreFeature(
|
|
97
117
|
withEntitiesAndSelectMethods<S>(),
|
|
98
118
|
withMethods((store) => ({
|
|
119
|
+
init(entities: S[]) {
|
|
120
|
+
const saved = localStorage.getItem(`mockDB_${collectionName}`);
|
|
121
|
+
if (saved) {
|
|
122
|
+
patchState(store, setAllEntities<S>(deserializeMockDBData(saved), { selectId }));
|
|
123
|
+
} else {
|
|
124
|
+
patchState(store, setAllEntities<S>(entities, { selectId }));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Listen for changes from other tabs to keep mockDB in sync
|
|
128
|
+
window.addEventListener('storage', (event) => {
|
|
129
|
+
if (event.key === `mockDB_${collectionName}` && event.newValue) {
|
|
130
|
+
patchState(store, setAllEntities<S>(deserializeMockDBData(event.newValue), { selectId }));
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
},
|
|
99
134
|
add(entity: S) {
|
|
100
135
|
patchState(store, setEntity<S>(entity, { selectId }));
|
|
136
|
+
localStorage.setItem(`mockDB_${collectionName}`, serializeMockDBData(Object.values(store.entityMap())));
|
|
101
137
|
},
|
|
102
138
|
update(id: string, changes: Partial<S>) {
|
|
103
139
|
patchState(store, updateEntity({ id, changes }, { selectId }));
|
|
140
|
+
localStorage.setItem(`mockDB_${collectionName}`, serializeMockDBData(Object.values(store.entityMap())));
|
|
104
141
|
},
|
|
105
142
|
})),
|
|
106
143
|
);
|
|
@@ -793,21 +830,49 @@ export function selectEntities<T>(entityMap: Record<string, T>, queryParams: Que
|
|
|
793
830
|
// If orderBy is provided, will only return entities with that property
|
|
794
831
|
// just like the Firestore API
|
|
795
832
|
|
|
796
|
-
|
|
833
|
+
let orderings: [string, string][] = [];
|
|
834
|
+
if (Array.isArray(queryOptions.orderBy)) {
|
|
835
|
+
if (Array.isArray(queryOptions.orderBy[0])) {
|
|
836
|
+
orderings = queryOptions.orderBy as [string, string][];
|
|
837
|
+
} else {
|
|
838
|
+
orderings = [queryOptions.orderBy as [string, string]];
|
|
839
|
+
}
|
|
840
|
+
} else {
|
|
841
|
+
orderings = [[queryOptions.orderBy as string, 'asc']];
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// Filter out entities missing any of the orderBy fields
|
|
845
|
+
for (const [field] of orderings) {
|
|
846
|
+
filteredEntities = filteredEntities.filter((e) => e[field] !== undefined && e[field] !== null);
|
|
847
|
+
}
|
|
797
848
|
|
|
798
|
-
filteredEntities = filteredEntities.filter((e) => e[field] !== undefined && e[field] !== null);
|
|
799
849
|
filteredEntities.sort((a, b) => {
|
|
800
|
-
|
|
801
|
-
|
|
850
|
+
for (const [field, order] of orderings) {
|
|
851
|
+
if (a[field] < b[field]) return order === 'desc' ? 1 : -1;
|
|
852
|
+
if (a[field] > b[field]) return order === 'desc' ? -1 : 1;
|
|
853
|
+
}
|
|
802
854
|
return 0;
|
|
803
855
|
});
|
|
804
856
|
}
|
|
805
857
|
|
|
806
858
|
// Filter based on startAt/startAfter/endAt/endAfter
|
|
859
|
+
// Note: Only supports single field orderBy for cursor pagination in local store mock for now
|
|
807
860
|
if (queryOptions?.orderBy && (queryOptions?.startAt !== undefined || queryOptions?.startAfter !== undefined ||
|
|
808
861
|
queryOptions?.endAt !== undefined || queryOptions?.endBefore !== undefined)) {
|
|
862
|
+
|
|
863
|
+
let primaryField = '';
|
|
864
|
+
if (Array.isArray(queryOptions.orderBy)) {
|
|
865
|
+
if (Array.isArray(queryOptions.orderBy[0])) {
|
|
866
|
+
primaryField = queryOptions.orderBy[0][0];
|
|
867
|
+
} else {
|
|
868
|
+
primaryField = queryOptions.orderBy[0] as string;
|
|
869
|
+
}
|
|
870
|
+
} else {
|
|
871
|
+
primaryField = queryOptions.orderBy as string;
|
|
872
|
+
}
|
|
873
|
+
|
|
809
874
|
filteredEntities = filteredEntities.filter((e) => {
|
|
810
|
-
const value = e[
|
|
875
|
+
const value = e[primaryField];
|
|
811
876
|
if (queryOptions.startAt !== undefined && value < queryOptions.startAt) {
|
|
812
877
|
return false;
|
|
813
878
|
}
|
|
@@ -1,83 +1,127 @@
|
|
|
1
|
-
import { Inject, inject, effect } from '@angular/core';
|
|
2
|
-
import { signalStore, patchState, withState, withMethods } from '@ngrx/signals';
|
|
1
|
+
import { Inject, inject, effect, Injector, computed } from '@angular/core';
|
|
2
|
+
import { signalStore, patchState, withState, withMethods, withComputed } from '@ngrx/signals';
|
|
3
3
|
import { rxMethod } from '@ngrx/signals/rxjs-interop';
|
|
4
4
|
import { User, AccessState } from '../user/user.model';
|
|
5
5
|
import { DATABASE_SERVICE, DatabaseService } from '../../firebase/database.service';
|
|
6
|
-
import { firstValueFrom, EMPTY, of, pipe } from 'rxjs';
|
|
6
|
+
import { firstValueFrom, EMPTY, of, pipe, from } from 'rxjs';
|
|
7
7
|
import { tap, catchError, switchMap, map } from 'rxjs/operators';
|
|
8
8
|
import { Router } from '@angular/router';
|
|
9
|
+
import { UserStore } from '../user/user.store';
|
|
10
|
+
import { toObservable } from '@angular/core/rxjs-interop';
|
|
11
|
+
import { setEntity } from '@ngrx/signals/entities';
|
|
9
12
|
|
|
10
13
|
type State = {
|
|
11
|
-
|
|
14
|
+
afUser: { uid: string, email: string, displayName: string, photoURL: string } | null;
|
|
12
15
|
isLoadingLogin: boolean;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
const initialState: State = {
|
|
16
|
-
|
|
19
|
+
afUser: null,
|
|
17
20
|
isLoadingLogin: false,
|
|
18
21
|
};
|
|
19
22
|
|
|
20
23
|
export const AuthStore = signalStore(
|
|
21
24
|
{ providedIn: 'root' },
|
|
22
25
|
withState(initialState),
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
withComputed((store, userStore = inject(UserStore)) => ({
|
|
27
|
+
user: computed(() => {
|
|
28
|
+
const afUser = store.afUser();
|
|
29
|
+
if (!afUser) return null;
|
|
30
|
+
return userStore.selectEntity(afUser.uid) || null;
|
|
31
|
+
}),
|
|
32
|
+
})),
|
|
33
|
+
withMethods((store, db = inject(DATABASE_SERVICE), router = inject(Router), userStore = inject(UserStore), injector = inject(Injector)) => {
|
|
34
|
+
return {
|
|
35
|
+
loadAuth: rxMethod<void>(
|
|
36
|
+
pipe(
|
|
37
|
+
// 1. Listen for changes in the authenticated Firebase user.
|
|
38
|
+
// This emits immediately if a user is already signed in (from local cache/cookie),
|
|
39
|
+
// or emits whenever they log in or out.
|
|
40
|
+
switchMap(() => db.afUser().pipe(
|
|
41
|
+
catchError((e) => {
|
|
42
|
+
console.error(e);
|
|
43
|
+
return EMPTY;
|
|
44
|
+
}),
|
|
45
|
+
)),
|
|
46
|
+
|
|
47
|
+
// 2. Load the corresponding database User record.
|
|
48
|
+
switchMap((afUser) => {
|
|
49
|
+
if (afUser) {
|
|
50
|
+
// We perform a blocking 'load()' first to ensure the UserStore is populated
|
|
51
|
+
// with the database user data before we continue. This ensures the 'user'
|
|
52
|
+
// computed signal is populated instantly for any route guards.
|
|
53
|
+
return from(userStore.load([['__id', '==', afUser.uid]], {})).pipe(
|
|
54
|
+
switchMap(() => {
|
|
55
|
+
// After the initial load completes, we set up a background 'stream()'.
|
|
56
|
+
// This ensures the UserStore stays continuously in sync with any
|
|
57
|
+
// real-time backend database updates (e.g. from cloud functions).
|
|
58
|
+
userStore.stream([['__id', '==', afUser.uid]], {}, injector);
|
|
59
|
+
|
|
60
|
+
// Pass the afUser down the pipe to the tap() handler.
|
|
61
|
+
return of(afUser);
|
|
62
|
+
}),
|
|
63
|
+
catchError((e) => {
|
|
64
|
+
console.error('[AuthStore loadAuth] streamEntity error:', e);
|
|
65
|
+
return EMPTY;
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
} else {
|
|
69
|
+
// If signed out, just pass null down.
|
|
70
|
+
return of(null);
|
|
71
|
+
}
|
|
72
|
+
}),
|
|
73
|
+
|
|
74
|
+
// 3. Update the local AuthStore state and handle brand new signups.
|
|
75
|
+
tap(async (afUser: any) => {
|
|
76
|
+
if (!afUser) {
|
|
77
|
+
patchState(store, { afUser: null });
|
|
78
|
+
} else {
|
|
79
|
+
patchState(store, { afUser });
|
|
80
|
+
const dbUser = userStore.selectEntity(afUser.uid);
|
|
81
|
+
|
|
82
|
+
if (!dbUser) {
|
|
83
|
+
// afUser exists but dbUser doesn't exist yet, we should create it
|
|
84
|
+
const newUser = {
|
|
85
|
+
__id: afUser.uid,
|
|
86
|
+
email: afUser.email,
|
|
87
|
+
name: afUser.displayName || afUser.email,
|
|
88
|
+
photoURL: afUser.photoURL || null,
|
|
89
|
+
isAdmin: false,
|
|
90
|
+
consented: false,
|
|
91
|
+
accessState: AccessState.SUBMIT_INTEREST,
|
|
92
|
+
};
|
|
93
|
+
try {
|
|
94
|
+
await db.addEntity('users', newUser);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
console.error(`[AuthStore loadAuth] Error creating new user:`, e);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
31
100
|
}),
|
|
32
101
|
)),
|
|
33
|
-
switchMap((afUser) => {
|
|
34
|
-
if (afUser) {
|
|
35
|
-
return db.streamEntity('users', afUser.uid).pipe(
|
|
36
|
-
map((dbUser) => ({ afUser, dbUser })),
|
|
37
|
-
catchError((e) => {
|
|
38
|
-
console.error(e);
|
|
39
|
-
return EMPTY;
|
|
40
|
-
}),
|
|
41
|
-
);
|
|
42
|
-
} else {
|
|
43
|
-
return of({ afUser, dbUser: null });
|
|
44
|
-
}
|
|
45
|
-
}),
|
|
46
|
-
tap(async ({ afUser, dbUser }) => {
|
|
47
|
-
if (!afUser) {
|
|
48
|
-
patchState(store, { user: undefined });
|
|
49
|
-
} else if (afUser && dbUser) {
|
|
50
|
-
patchState(store, { user: dbUser });
|
|
51
|
-
}
|
|
52
|
-
}),
|
|
53
|
-
),
|
|
54
|
-
),
|
|
55
102
|
async login(provider: string, params: {
|
|
56
103
|
scope?: string,
|
|
57
104
|
doNotRoute: boolean
|
|
58
105
|
} = { doNotRoute: false }): Promise<void> {
|
|
59
106
|
patchState(store, { isLoadingLogin: true });
|
|
60
|
-
|
|
107
|
+
|
|
61
108
|
try {
|
|
62
109
|
const loginResult = await db.login(provider, params.scope);
|
|
63
110
|
const afUser = loginResult.user;
|
|
64
|
-
|
|
111
|
+
patchState(store, { afUser });
|
|
112
|
+
|
|
65
113
|
const dbUser: User = await db.getEntity('users', afUser.uid);
|
|
66
114
|
|
|
67
115
|
const navLocation = ['/home'];
|
|
68
|
-
// update the
|
|
116
|
+
// update the user if there is already a dbUser
|
|
69
117
|
if (dbUser) {
|
|
70
|
-
const tokenHash = {};
|
|
71
|
-
tokenHash[provider] = afUser.accessToken;
|
|
72
118
|
const changes = {
|
|
73
119
|
email: afUser.email,
|
|
74
120
|
name: afUser.displayName || afUser.email,
|
|
75
|
-
photoURL: afUser.photoURL,
|
|
76
|
-
tokens: Object.assign({}, dbUser.tokens || {}, tokenHash),
|
|
121
|
+
photoURL: afUser.photoURL || null,
|
|
77
122
|
};
|
|
78
123
|
try {
|
|
79
|
-
|
|
80
|
-
await db.updateEntity('users', dbUser.__id, changes);
|
|
124
|
+
await userStore.update(dbUser.__id, changes);
|
|
81
125
|
|
|
82
126
|
if (!params || !params.doNotRoute) {
|
|
83
127
|
router.navigate(navLocation, { queryParamsHandling: 'preserve' });
|
|
@@ -87,27 +131,23 @@ export const AuthStore = signalStore(
|
|
|
87
131
|
throw e;
|
|
88
132
|
}
|
|
89
133
|
} else {
|
|
90
|
-
const tokenHash = {};
|
|
91
|
-
tokenHash[provider] = afUser.accessToken;
|
|
92
134
|
const newUser = {
|
|
93
135
|
__id: afUser.uid,
|
|
94
136
|
email: afUser.email,
|
|
95
137
|
name: afUser.displayName || afUser.email,
|
|
96
|
-
photoURL: afUser.photoURL,
|
|
97
|
-
tokens: tokenHash,
|
|
138
|
+
photoURL: afUser.photoURL || null,
|
|
98
139
|
isAdmin: false,
|
|
99
140
|
consented: false,
|
|
100
|
-
accessState: AccessState.
|
|
141
|
+
accessState: AccessState.SUBMIT_INTEREST,
|
|
101
142
|
};
|
|
102
143
|
try {
|
|
103
|
-
await
|
|
104
|
-
patchState(store, { user: newUser });
|
|
144
|
+
await userStore.add(newUser);
|
|
105
145
|
|
|
106
146
|
if (!params || !params.doNotRoute) {
|
|
107
147
|
router.navigate(navLocation, { queryParamsHandling: 'preserve' });
|
|
108
148
|
}
|
|
109
149
|
} catch (e) {
|
|
110
|
-
console.error(e);
|
|
150
|
+
console.error(`[AuthStore login] Error creating new user:`, e);
|
|
111
151
|
throw e;
|
|
112
152
|
}
|
|
113
153
|
}
|
|
@@ -132,5 +172,6 @@ export const AuthStore = signalStore(
|
|
|
132
172
|
throw e;
|
|
133
173
|
}
|
|
134
174
|
},
|
|
135
|
-
}
|
|
175
|
+
};
|
|
176
|
+
}),
|
|
136
177
|
);
|
|
@@ -5,7 +5,7 @@ import { User, AccessState } from './user.model';
|
|
|
5
5
|
|
|
6
6
|
export const UserMockDB = signalStore(
|
|
7
7
|
{ providedIn: 'root' },
|
|
8
|
-
withEntitiesForMockDB<User>(),
|
|
8
|
+
withEntitiesForMockDB<User>('users'),
|
|
9
9
|
);
|
|
10
10
|
|
|
11
11
|
export const USER_DB: User[] = [
|
|
@@ -13,10 +13,10 @@ export const USER_DB: User[] = [
|
|
|
13
13
|
__id: '1',
|
|
14
14
|
email: 'a@sample.com',
|
|
15
15
|
name: 'User A',
|
|
16
|
-
photoURL: 'http://loremflickr.com/100/100',
|
|
17
|
-
isAdmin:
|
|
18
|
-
consented:
|
|
19
|
-
accessState: AccessState.
|
|
16
|
+
photoURL: 'http://loremflickr.com/100/100?lock=1',
|
|
17
|
+
isAdmin: true,
|
|
18
|
+
consented: false,
|
|
19
|
+
accessState: AccessState.SUBMIT_INTEREST,
|
|
20
20
|
_createdAt: Timestamp.now(),
|
|
21
21
|
_updatedAt: Timestamp.now(),
|
|
22
22
|
_deleted: false,
|
|
@@ -9,19 +9,17 @@ export interface User {
|
|
|
9
9
|
name: string;
|
|
10
10
|
email: string;
|
|
11
11
|
photoURL?: string;
|
|
12
|
-
tokens?: {
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
[index: string]: any;
|
|
15
|
-
};
|
|
16
12
|
isAdmin: boolean;
|
|
17
13
|
accessState: AccessState;
|
|
18
14
|
consented: boolean;
|
|
19
15
|
joinedWaitlistAt?: Timestamp;
|
|
16
|
+
/** Admin-only: routes where auth guards are bypassed for testing/debugging. */
|
|
17
|
+
adminOverridePaths?: string[];
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
export enum AccessState {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
SUBMIT_INTEREST = '01 - submit interest', // on basic interest form
|
|
22
|
+
WAITING = '02 - waiting', // on waitlist for early access
|
|
23
|
+
CONSENT = '03 - consent', // on consent form
|
|
26
24
|
DONE = 'done', // finished with the access flow
|
|
27
25
|
}
|
|
@@ -6,17 +6,15 @@ import { USER_DB } from '../user/user.mock';
|
|
|
6
6
|
|
|
7
7
|
export const UserContextMockDB = signalStore(
|
|
8
8
|
{ providedIn: 'root' },
|
|
9
|
-
withEntitiesForMockDB<UserContext>(),
|
|
9
|
+
withEntitiesForMockDB<UserContext>('userContexts'),
|
|
10
10
|
);
|
|
11
11
|
|
|
12
12
|
export const USERCONTEXT_DB = [
|
|
13
13
|
{
|
|
14
14
|
__id: 'uc1',
|
|
15
15
|
__userId: USER_DB[0].__id,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
},
|
|
19
|
-
desiredValue: 'test',
|
|
16
|
+
questionOne: 'test',
|
|
17
|
+
questionTwo: 'test',
|
|
20
18
|
_createdAt: Timestamp.now(),
|
|
21
19
|
_updatedAt: Timestamp.now(),
|
|
22
20
|
_deleted: false,
|
|
@@ -3,11 +3,8 @@ import { Timestamp } from '@angular/fire/firestore';
|
|
|
3
3
|
export interface UserContext {
|
|
4
4
|
__id: string;
|
|
5
5
|
__userId: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
other?: string;
|
|
9
|
-
}
|
|
10
|
-
desiredValue: string;
|
|
6
|
+
questionOne: string;
|
|
7
|
+
questionTwo: string;
|
|
11
8
|
_createdAt?: Timestamp;
|
|
12
9
|
_updatedAt?: Timestamp;
|
|
13
10
|
_deleted?: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Component, OnInit, ChangeDetectionStrategy, input, output, inject, WritableSignal, Signal, signal, computed, Inject, Injector } from '@angular/core';
|
|
2
2
|
import { ConsentAnimations } from './consent.animations';
|
|
3
|
-
import { Router } from '@angular/router';
|
|
3
|
+
import { Router, RouterLink } from '@angular/router';
|
|
4
4
|
import { User, AccessState } from 'src/app/core/store/user/user.model';
|
|
5
5
|
import { Location } from '@angular/common';
|
|
6
6
|
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
@@ -21,6 +21,7 @@ import { NavbarComponent } from 'src/app/shared/navbar/navbar.component';
|
|
|
21
21
|
ReactiveFormsModule,
|
|
22
22
|
NavbarComponent,
|
|
23
23
|
MatCheckbox,
|
|
24
|
+
RouterLink
|
|
24
25
|
],
|
|
25
26
|
})
|
|
26
27
|
export class ConsentComponent implements OnInit {
|
|
@@ -64,10 +65,10 @@ export class ConsentComponent implements OnInit {
|
|
|
64
65
|
async submit() {
|
|
65
66
|
try {
|
|
66
67
|
await this.userStore.update(this.currentUser().__id, {
|
|
67
|
-
accessState: AccessState.
|
|
68
|
+
accessState: AccessState.DONE,
|
|
68
69
|
consented: true,
|
|
69
70
|
});
|
|
70
|
-
this.router.navigate(['/
|
|
71
|
+
this.router.navigate(['/home']);
|
|
71
72
|
} catch (e) {
|
|
72
73
|
console.error(e);
|
|
73
74
|
this.snackBar.open('Failed to update consent status', '', { duration: 3000 });
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { inject } from '@angular/core';
|
|
2
|
+
import { CanActivateFn, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
|
3
|
+
import { map } from 'rxjs/operators';
|
|
4
|
+
import { AuthService } from '../../core/auth/auth.service';
|
|
5
|
+
import { User, AccessState } from '../../core/store/user/user.model';
|
|
6
|
+
import { hasAdminOverride } from '../../core/auth/guards/admin-override';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Single guard logic for the consent page that checks two conditions:
|
|
10
|
+
*
|
|
11
|
+
* 1. User has cleared the waitlist (accessState is CONSENT or DONE,
|
|
12
|
+
* i.e. not SUBMIT_INTEREST or WAITING). If still on the waitlist,
|
|
13
|
+
* redirects to `/early-access`.
|
|
14
|
+
*
|
|
15
|
+
* 2. User still needs to consent (accessState is not DONE, or consented
|
|
16
|
+
* is false). If already fully consented, redirects to `/home`.
|
|
17
|
+
*/
|
|
18
|
+
export function handleAccess(
|
|
19
|
+
user: User | null | undefined,
|
|
20
|
+
router: Router,
|
|
21
|
+
route: ActivatedRouteSnapshot,
|
|
22
|
+
state: RouterStateSnapshot
|
|
23
|
+
): boolean {
|
|
24
|
+
if (hasAdminOverride(user, state.url)) return true;
|
|
25
|
+
|
|
26
|
+
// Check 1: Has the user cleared the waitlist?
|
|
27
|
+
const waitingStates = [AccessState.SUBMIT_INTEREST, AccessState.WAITING];
|
|
28
|
+
if (user && waitingStates.includes(user.accessState)) {
|
|
29
|
+
router.navigate(['/early-access'], { queryParams: route.queryParams });
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Check 2: Does the user still need to consent?
|
|
34
|
+
if (user && user.accessState === AccessState.DONE && user.consented) {
|
|
35
|
+
router.navigate(['/home'], { queryParams: route.queryParams });
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Route guard that delegates to `handleAccess`.
|
|
44
|
+
*/
|
|
45
|
+
export const consentGuard: CanActivateFn = (route, state) => {
|
|
46
|
+
const auth = inject(AuthService);
|
|
47
|
+
const router = inject(Router);
|
|
48
|
+
|
|
49
|
+
return auth.resolveUser().pipe(
|
|
50
|
+
map((user) => {
|
|
51
|
+
return handleAccess(user, router, route, state);
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
};
|
package/src/ng-add/files/src/app/first-time/early-access/early-access.animations.ts.template
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { trigger, group, query, animateChild, state, style, animate, transition } from '@angular/animations';
|
|
2
2
|
|
|
3
3
|
export const EarlyAccessAnimations = [
|
|
4
|
+
trigger('fadeIn', [
|
|
5
|
+
transition(':enter', [
|
|
6
|
+
style({ opacity: 0 }),
|
|
7
|
+
animate('400ms ease-in', style({ opacity: 1 }))
|
|
8
|
+
])
|
|
9
|
+
])
|
|
4
10
|
];
|
package/src/ng-add/files/src/app/first-time/early-access/early-access.component.html.template
CHANGED
|
@@ -1,65 +1,83 @@
|
|
|
1
1
|
<app-navbar></app-navbar>
|
|
2
2
|
@if (waitlistData(); as data) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
<div class="early-access-container">
|
|
4
|
+
<div class="content-split">
|
|
5
|
+
<div class="text-section">
|
|
6
|
+
<!-- Core questions on motivation and desired value -->
|
|
7
|
+
@if (data.currentUser.accessState === AccessState.SUBMIT_INTEREST) {
|
|
8
|
+
<div @fadeIn>
|
|
9
|
+
<h1>Hello and Welcome! 👋</h1>
|
|
10
|
+
<p class="subtitle">Please help us understand your context and needs so that we know how to best support you!</p>
|
|
11
|
+
<form [formGroup]="surveyForm" (ngSubmit)="submitInterest()">
|
|
12
|
+
<div class="form-field-group">
|
|
13
|
+
<mat-label class="question">QUESTION_1 [What is your current role and what are you hoping to achieve?]</mat-label>
|
|
14
|
+
<mat-form-field class="question-one" appearance="outline">
|
|
15
|
+
<mat-label>QUESTION_1_SHORT_LABEL [Current role & goals]</mat-label>
|
|
16
|
+
<textarea #q1Text matInput cdkTextareaAutosize formControlName="questionOne" name="questionOne" required appHintVisibility [hintControl]="questionOne!" [hintSiblingControl]="questionTwo!" #q1Hint="hintVisibility"></textarea>
|
|
17
|
+
@if (q1Hint.showHint()) {
|
|
18
|
+
<mat-hint>
|
|
19
|
+
@if (q1Text.value?.length < 25) {
|
|
20
|
+
You've shared {{q1Text.value?.length || 0}} of 25 characters. If you could say a little more, that'd help us! 🙏
|
|
21
|
+
} @else {
|
|
22
|
+
Thank you! This helps us understand your context better! 🙏
|
|
23
|
+
}
|
|
24
|
+
</mat-hint>
|
|
25
|
+
}
|
|
26
|
+
</mat-form-field>
|
|
21
27
|
</div>
|
|
22
|
-
</div>
|
|
23
|
-
@if (backgroundForm.contains('backgroundOther')) {
|
|
24
28
|
<div class="form-field-group">
|
|
25
|
-
<mat-label class="question">
|
|
26
|
-
<mat-form-field class="
|
|
27
|
-
<mat-label>
|
|
28
|
-
<
|
|
29
|
-
@if (
|
|
30
|
-
|
|
29
|
+
<mat-label class="question">QUESTION_2 [What is the biggest hurdle preventing you from achieving this right now?]</mat-label>
|
|
30
|
+
<mat-form-field class="question-two" appearance="outline">
|
|
31
|
+
<mat-label>QUESTION_2_SHORT_LABEL [Biggest hurdle]</mat-label>
|
|
32
|
+
<textarea #q2Text matInput cdkTextareaAutosize formControlName="questionTwo" required appHintVisibility [hintControl]="questionTwo!" [hintSiblingControl]="questionOne!" #q2Hint="hintVisibility"></textarea>
|
|
33
|
+
@if (q2Hint.showHint() && questionOne?.valid) {
|
|
34
|
+
<mat-hint>
|
|
35
|
+
@if (q2Text.value?.length < 50) {
|
|
36
|
+
You've shared {{q2Text.value?.length || 0}} of 50 characters. Knowing your hurdles helps us build the right tools!
|
|
37
|
+
} @else {
|
|
38
|
+
Thank you! We're excited to see how we can help clear these hurdles.
|
|
39
|
+
}
|
|
40
|
+
</mat-hint>
|
|
31
41
|
}
|
|
32
42
|
</mat-form-field>
|
|
33
43
|
</div>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
<mat-form-field class="desired-value" appearance="fill">
|
|
38
|
-
<mat-label>Your ideal experience or outcomes</mat-label>
|
|
39
|
-
<textarea #text matInput formControlName="desiredValue" name="desiredValue" required></textarea>
|
|
40
|
-
@if (text.value?.length < 50) {
|
|
41
|
-
<mat-hint>You've shared {{text.value?.length || 0}} of 50 characters. If you could say a little more about your goals or why you decided to try it out, that'd help us! 🙏</mat-hint>
|
|
44
|
+
<button type="submit" class="btn continue-btn" [disabled]="surveyForm.invalid || loading()">
|
|
45
|
+
@if (loading()) {
|
|
46
|
+
Submitting...
|
|
42
47
|
} @else {
|
|
43
|
-
|
|
48
|
+
Submit and Continue
|
|
49
|
+
<img src="https://icongr.am/feather/arrow-right.svg?size=20&color=B2B6C7">
|
|
44
50
|
}
|
|
45
|
-
</
|
|
46
|
-
</
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
</button>
|
|
51
|
-
</form>
|
|
52
|
-
} @else if (data.currentUser.accessState === AccessState.WAITING && !loading()) {
|
|
53
|
-
<!-- Waiting list position and path for going getting access early -->
|
|
51
|
+
</button>
|
|
52
|
+
</form>
|
|
53
|
+
</div>
|
|
54
|
+
} @else if (data.currentUser.accessState === AccessState.WAITING) {
|
|
55
|
+
<!-- Waiting list position and path for going getting access early -->
|
|
54
56
|
@let position = positionText$ | async;
|
|
55
57
|
@let total = totalWaiting$ | async;
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
<div @fadeIn class="waitlist-content">
|
|
59
|
+
@if (position && total) {
|
|
60
|
+
<h1 class="waitlist-header">
|
|
61
|
+
You are <span class="your-position">{{ position }}</span> of {{ total }} on the waitlist
|
|
62
|
+
</h1>
|
|
63
|
+
} @else {
|
|
64
|
+
<h1 class="waitlist-header">
|
|
65
|
+
You are on the waitlist!
|
|
66
|
+
</h1>
|
|
67
|
+
}
|
|
68
|
+
<p>Thanks for signing up! We're personally onboarding our first cohort of users
|
|
69
|
+
to ensure we understand your context deeply and can provide a delightful experience. We'll be in touch soon!
|
|
70
|
+
😊
|
|
71
|
+
</p>
|
|
72
|
+
<p>If you would really benefit from getting off the waitlist faster, send {{
|
|
73
|
+
outreachLeadName }} an email at <a [href]="'mailto:' + outreachLeadEmail">{{ outreachLeadEmail }}</a>
|
|
74
|
+
explaining and we'll see what we can do!</p>
|
|
62
75
|
</div>
|
|
63
|
-
|
|
76
|
+
}
|
|
77
|
+
</div>
|
|
78
|
+
<div @fadeIn class="mentorship-graphic">
|
|
79
|
+
<img src="/images/abstract.png" alt="Abstract mentorship graphic" />
|
|
80
|
+
</div>
|
|
64
81
|
</div>
|
|
65
|
-
|
|
82
|
+
</div>
|
|
83
|
+
}
|