placementt-core 11.0.533 → 11.10.151
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/lib/constants.d.ts +1 -0
- package/lib/constants.js +6 -0
- package/lib/constants.js.map +1 -1
- package/lib/features/analytics/useAnalytics.d.ts +2 -0
- package/lib/features/analytics/useAnalytics.js +21 -16
- package/lib/features/analytics/useAnalytics.js.map +1 -1
- package/lib/features/global/downtime/useDowntime.d.ts +1 -0
- package/lib/features/global/downtime/useDowntime.js +9 -7
- package/lib/features/global/downtime/useDowntime.js.map +1 -1
- package/lib/features/global/users/useUserFunctions.js +1 -1
- package/lib/features/global/users/useUserFunctions.js.map +1 -1
- package/lib/features/placements/studentPlacements/activePlacement.d.ts +5 -1
- package/lib/features/placements/studentPlacements/activePlacement.js +7 -3
- package/lib/features/placements/studentPlacements/activePlacement.js.map +1 -1
- package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.d.ts +3 -2
- package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.js +4 -1
- package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.js.map +1 -1
- package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.d.ts +2 -2
- package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.js +1 -1
- package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.js.map +1 -1
- package/lib/features/placements/studentPlacements/useStudentPlacements.d.ts +2 -12
- package/lib/features/placements/studentPlacements/useStudentPlacements.js +1 -26
- package/lib/features/placements/studentPlacements/useStudentPlacements.js.map +1 -1
- package/lib/features/updates/useUpdates.d.ts +1 -0
- package/lib/features/updates/useUpdates.js +13 -12
- package/lib/features/updates/useUpdates.js.map +1 -1
- package/lib/firebase/firebase.d.ts +3 -1
- package/lib/firebase/firebase.js +4 -3
- package/lib/firebase/firebase.js.map +1 -1
- package/lib/firebase/firebaseQuery.d.ts +3 -1
- package/lib/firebase/firebaseQuery.js +8 -1
- package/lib/firebase/firebaseQuery.js.map +1 -1
- package/lib/firebase/readDatabase.d.ts +2 -4
- package/lib/firebase/readDatabase.js +28 -5
- package/lib/firebase/readDatabase.js.map +1 -1
- package/lib/firebase/writeDatabase.d.ts +6 -2
- package/lib/firebase/writeDatabase.js +2 -1
- package/lib/firebase/writeDatabase.js.map +1 -1
- package/lib/hooks.d.ts +108 -9
- package/lib/hooks.js +547 -58
- package/lib/hooks.js.map +1 -1
- package/lib/reduxHooks.d.ts +41 -3
- package/lib/reduxHooks.js +61 -18
- package/lib/reduxHooks.js.map +1 -1
- package/lib/tasksAndTips.d.ts +1 -1
- package/lib/tasksAndTips.js +179 -8
- package/lib/tasksAndTips.js.map +1 -1
- package/lib/typeDefinitions.d.ts +14 -22
- package/lib/util.js +14 -8
- package/lib/util.js.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +7 -1
- package/src/features/analytics/useAnalytics.tsx +24 -15
- package/src/features/global/downtime/useDowntime.tsx +11 -7
- package/src/features/global/users/useUserFunctions.tsx +1 -1
- package/src/features/placements/studentPlacements/activePlacement.ts +8 -3
- package/src/features/placements/studentPlacements/completedStudentPlacementsSlice.ts +5 -2
- package/src/features/placements/studentPlacements/upcomingStudentPlacementsSlice.ts +2 -2
- package/src/features/placements/studentPlacements/useStudentPlacements.tsx +4 -28
- package/src/features/updates/useUpdates.tsx +14 -12
- package/src/firebase/firebase.tsx +5 -3
- package/src/firebase/firebaseQuery.tsx +8 -1
- package/src/firebase/readDatabase.tsx +33 -6
- package/src/firebase/writeDatabase.tsx +3 -1
- package/src/hooks.tsx +695 -61
- package/src/reduxHooks.ts +68 -20
- package/src/tasksAndTips.ts +184 -11
- package/src/typeDefinitions.ts +14 -20
- package/src/util.ts +14 -9
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import FirebaseQuery from "../../firebase/firebaseQuery";
|
|
2
2
|
import {orderBy, limit, arrayUnion} from "firebase/firestore";
|
|
3
|
-
import {useState
|
|
3
|
+
import {useState} from "react";
|
|
4
4
|
import { UserData } from "../../typeDefinitions";
|
|
5
5
|
|
|
6
6
|
export function useUpdates({user}: {user: UserData}){
|
|
7
7
|
const [active, setActive] = useState<{title: string, body: string, id: string}>();
|
|
8
8
|
const firebaseQuery = new FirebaseQuery();
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
const fetchUpdates = async () => {
|
|
11
|
+
try {
|
|
12
|
+
const docs = await firebaseQuery.getDocsWhere("updates", [orderBy("created", "desc"), limit(1)])
|
|
13
|
+
const item = Object.values(docs as {[key:string]: {title: string, body: string, id: string}})[0];
|
|
14
|
+
if (!user?.readUpdates?.includes(item.id)) setActive(item);
|
|
15
|
+
|
|
16
|
+
} catch(error) {
|
|
17
|
+
console.log(error)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
20
22
|
|
|
21
23
|
const dismiss = () => {
|
|
22
24
|
if (!user) return
|
|
@@ -31,6 +33,6 @@ export function useUpdates({user}: {user: UserData}){
|
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
return ({...{active, dismiss}})
|
|
36
|
+
return ({...{active, dismiss, fetchUpdates}})
|
|
35
37
|
|
|
36
38
|
}
|
|
@@ -48,16 +48,18 @@ export const register = async (credentials: RegistrationData, type:"Institute"|"
|
|
|
48
48
|
if (type === "Student") {
|
|
49
49
|
await login({email: credentials.email, password: credentials.passwordOne});
|
|
50
50
|
}
|
|
51
|
-
return (res.data as {
|
|
51
|
+
return (res.data as { msg: {uid: string}}).msg.uid as string;
|
|
52
52
|
});
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
export const executeCallable = async (functionName: string, data: unknown) => {
|
|
56
56
|
const funcCallable = httpsCallable(functions, functionName);
|
|
57
|
-
|
|
57
|
+
const res = await funcCallable(data).catch((e) => {
|
|
58
58
|
console.log("callableError", functionName, e);
|
|
59
|
-
|
|
59
|
+
throw e;
|
|
60
60
|
});
|
|
61
|
+
|
|
62
|
+
return res as {data: any};
|
|
61
63
|
};
|
|
62
64
|
|
|
63
65
|
|
|
@@ -82,6 +82,9 @@ export default class FirebaseQuery {
|
|
|
82
82
|
console.log(`Error in snapshot ${path}`, error);
|
|
83
83
|
throw error;
|
|
84
84
|
});
|
|
85
|
+
if (!result.exists()) {
|
|
86
|
+
throw new Error(`Document doesn't exist. ${typeof path === "string" ? path : path.join(", ")}`);
|
|
87
|
+
}
|
|
85
88
|
const resultData = result.data() || {};
|
|
86
89
|
resultData.id = result.id;
|
|
87
90
|
return resultData;
|
|
@@ -124,10 +127,14 @@ export default class FirebaseQuery {
|
|
|
124
127
|
});
|
|
125
128
|
}
|
|
126
129
|
|
|
127
|
-
collectionSnapshot(setState:SetStateAction<any
|
|
130
|
+
collectionSnapshot(setState:SetStateAction<any>|((e: DocumentData|{[key: string]: any}) => void), path: string[]|string, constraints?:QueryConstraint[]|QueryConstraint, dispatch?: AppDispatch, raw?: boolean) {
|
|
128
131
|
const q = this.createQuery("collection", path, constraints) as Query<DocumentData>;
|
|
129
132
|
|
|
130
133
|
return onSnapshot(q, (querySnapshot: DocumentData) => {
|
|
134
|
+
if (raw) {
|
|
135
|
+
setState(querySnapshot);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
131
138
|
const itemList: {[key: string]: any} = {};
|
|
132
139
|
|
|
133
140
|
querySnapshot.docs.forEach((doc: QueryDocumentSnapshot) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {collection, getDocs, limit, orderBy, query, QueryConstraint, where} from "firebase/firestore";
|
|
2
2
|
import {getDownloadURL, listAll, ref, StorageReference} from "firebase/storage";
|
|
3
3
|
import {SetStateAction} from "react";
|
|
4
|
-
import {CohortData, InstituteData, NotificationObject, PlacementListing, ProviderData, UserData, UserGroupData} from "../typeDefinitions";
|
|
4
|
+
import {BillingPackage, CohortData, InstituteData, NotificationObject, PlacementListing, ProviderData, UserData, UserGroupData} from "../typeDefinitions";
|
|
5
5
|
import {db, storage} from "./firebaseConfig";
|
|
6
6
|
import FirebaseQuery from "./firebaseQuery";
|
|
7
7
|
import {pathToArr, sortByReverseStringLength} from "./util";
|
|
@@ -76,6 +76,7 @@ export const getUser = async (uid: string, setState: SetStateAction<any>) => {
|
|
|
76
76
|
let oldUser:OldUserData = {};
|
|
77
77
|
let groupData = {};
|
|
78
78
|
let cohortData = {};
|
|
79
|
+
let packageData = {};
|
|
79
80
|
|
|
80
81
|
console.log("Fetching user");
|
|
81
82
|
|
|
@@ -89,6 +90,15 @@ export const getUser = async (uid: string, setState: SetStateAction<any>) => {
|
|
|
89
90
|
}
|
|
90
91
|
user.groupData = groupData as UserGroupData;
|
|
91
92
|
|
|
93
|
+
if (user.product === "providers") {
|
|
94
|
+
// Always set the groupData, but only get it if the user group has changed.keyof
|
|
95
|
+
if (oldUser?.userGroup !== user.userGroup) {
|
|
96
|
+
const provider = await firebaseQuery.getDocData(["providers", user.oId]) as ProviderData;
|
|
97
|
+
packageData = await firebaseQuery.getDocData(["billing", provider.package]) as BillingPackage;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
user.packageData = packageData as BillingPackage;
|
|
101
|
+
|
|
92
102
|
if (user.cohort) {
|
|
93
103
|
// Always set the groupData, but only get it if the user group has changed.keyof
|
|
94
104
|
if (oldUser?.cohort !== user.cohort) {
|
|
@@ -170,8 +180,21 @@ export const getFormsFromId = async (path: string[]|string, forms: string[]) =>
|
|
|
170
180
|
}, Promise.resolve({}))));
|
|
171
181
|
};
|
|
172
182
|
|
|
173
|
-
export const getUserById = async (id: string) => {
|
|
174
|
-
|
|
183
|
+
export const getUserById = async (id: string, setState?: SetStateAction<any>, getGroupData=true) => {
|
|
184
|
+
if (!setState) {
|
|
185
|
+
const user = await firebaseQuery.getDocData(["users", id]) as UserData;
|
|
186
|
+
if (getGroupData) {
|
|
187
|
+
user.groupData = user.userGroup && user.userGroup !== "admin" ? await firebaseQuery.getDocData(["userGroups", user.userGroup]) as UserGroupData : undefined
|
|
188
|
+
}
|
|
189
|
+
return user;
|
|
190
|
+
}
|
|
191
|
+
firebaseQuery.documentSnapshot(["users", id], async (user: UserData) => {
|
|
192
|
+
if (getGroupData) {
|
|
193
|
+
user.groupData = user.userGroup && user.userGroup !== "admin" ? await firebaseQuery.getDocData(["userGroups", user.userGroup]) as UserGroupData : undefined
|
|
194
|
+
}
|
|
195
|
+
setState(user);
|
|
196
|
+
});
|
|
197
|
+
return;
|
|
175
198
|
};
|
|
176
199
|
|
|
177
200
|
/* export const getUsersByType = async (q: Query, setState:SetStateAction<any>, uid:string, lim:number, limitType?:"start"|"end") => {
|
|
@@ -202,7 +225,11 @@ export const checkPlacementConflicts = async (instituteId:string, userGroupId:st
|
|
|
202
225
|
};
|
|
203
226
|
|
|
204
227
|
export const getPlacementListingsById = async (placementListings: string[]) => {
|
|
205
|
-
|
|
206
|
-
return [listingId, await firebaseQuery.getDocData(["placementListings", listingId]) as PlacementListing];
|
|
207
|
-
})) as [string, PlacementListing][]
|
|
228
|
+
const placements = await Promise.all(placementListings.map(async (listingId) => {
|
|
229
|
+
return [listingId, await firebaseQuery.getDocData(["placementListings", listingId]).catch(() => false) as PlacementListing];
|
|
230
|
+
})) as [string, PlacementListing|false][];
|
|
231
|
+
|
|
232
|
+
return placements.filter(([_, v]) => v !== false) as [string, PlacementListing][];
|
|
208
233
|
}
|
|
234
|
+
|
|
235
|
+
|
|
@@ -24,6 +24,8 @@ export const uploadFiles = async (files: any[]|any, path: string[] | string, fil
|
|
|
24
24
|
|
|
25
25
|
const storageRef = ref(storage, newPath);
|
|
26
26
|
|
|
27
|
+
console.log("FILE ELEMENT", element);
|
|
28
|
+
|
|
27
29
|
if (typeof element === "string") {
|
|
28
30
|
return await uploadString(storageRef, element, "base64", fileType ? {contentType: fileType} : undefined)
|
|
29
31
|
.catch((e) => {
|
|
@@ -31,7 +33,7 @@ export const uploadFiles = async (files: any[]|any, path: string[] | string, fil
|
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
await uploadBytes(storageRef, element).catch((e) => {
|
|
36
|
+
return await uploadBytes(storageRef, element).catch((e) => {
|
|
35
37
|
final = e;
|
|
36
38
|
});
|
|
37
39
|
})
|