placementt-core 11.0.533 → 11.0.892

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.
Files changed (76) hide show
  1. package/lib/constants.d.ts +13 -1
  2. package/lib/constants.js +86 -1
  3. package/lib/constants.js.map +1 -1
  4. package/lib/features/analytics/useAnalytics.d.ts +2 -0
  5. package/lib/features/analytics/useAnalytics.js +22 -19
  6. package/lib/features/analytics/useAnalytics.js.map +1 -1
  7. package/lib/features/global/downtime/useDowntime.d.ts +1 -0
  8. package/lib/features/global/downtime/useDowntime.js +9 -7
  9. package/lib/features/global/downtime/useDowntime.js.map +1 -1
  10. package/lib/features/global/users/useUserFunctions.js +1 -1
  11. package/lib/features/global/users/useUserFunctions.js.map +1 -1
  12. package/lib/features/jobs/jobsSlice.d.ts +10 -2
  13. package/lib/features/jobs/jobsSlice.js +5 -2
  14. package/lib/features/jobs/jobsSlice.js.map +1 -1
  15. package/lib/features/placements/studentPlacements/activePlacement.d.ts +5 -1
  16. package/lib/features/placements/studentPlacements/activePlacement.js +7 -3
  17. package/lib/features/placements/studentPlacements/activePlacement.js.map +1 -1
  18. package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.d.ts +3 -2
  19. package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.js +4 -1
  20. package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.js.map +1 -1
  21. package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.d.ts +2 -2
  22. package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.js +1 -1
  23. package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.js.map +1 -1
  24. package/lib/features/placements/studentPlacements/useStudentPlacements.d.ts +2 -12
  25. package/lib/features/placements/studentPlacements/useStudentPlacements.js +1 -26
  26. package/lib/features/placements/studentPlacements/useStudentPlacements.js.map +1 -1
  27. package/lib/features/updates/useUpdates.d.ts +1 -0
  28. package/lib/features/updates/useUpdates.js +13 -12
  29. package/lib/features/updates/useUpdates.js.map +1 -1
  30. package/lib/firebase/firebase.d.ts +5 -3
  31. package/lib/firebase/firebase.js +23 -12
  32. package/lib/firebase/firebase.js.map +1 -1
  33. package/lib/firebase/firebaseConfig.js.map +1 -1
  34. package/lib/firebase/firebaseQuery.d.ts +6 -2
  35. package/lib/firebase/firebaseQuery.js +11 -3
  36. package/lib/firebase/firebaseQuery.js.map +1 -1
  37. package/lib/firebase/readDatabase.d.ts +2 -4
  38. package/lib/firebase/readDatabase.js +30 -5
  39. package/lib/firebase/readDatabase.js.map +1 -1
  40. package/lib/firebase/writeDatabase.d.ts +6 -2
  41. package/lib/firebase/writeDatabase.js +2 -1
  42. package/lib/firebase/writeDatabase.js.map +1 -1
  43. package/lib/hooks.d.ts +277 -192
  44. package/lib/hooks.js +1437 -704
  45. package/lib/hooks.js.map +1 -1
  46. package/lib/reduxHooks.d.ts +122 -5
  47. package/lib/reduxHooks.js +132 -29
  48. package/lib/reduxHooks.js.map +1 -1
  49. package/lib/tasksAndTips.d.ts +19 -7
  50. package/lib/tasksAndTips.js +637 -164
  51. package/lib/tasksAndTips.js.map +1 -1
  52. package/lib/typeDefinitions.d.ts +321 -110
  53. package/lib/util.d.ts +15 -3
  54. package/lib/util.js +47 -10
  55. package/lib/util.js.map +1 -1
  56. package/package.json +7 -4
  57. package/src/constants.ts +91 -3
  58. package/src/features/analytics/useAnalytics.tsx +25 -17
  59. package/src/features/global/downtime/useDowntime.tsx +11 -7
  60. package/src/features/global/users/useUserFunctions.tsx +1 -1
  61. package/src/features/jobs/jobsSlice.ts +9 -3
  62. package/src/features/placements/studentPlacements/activePlacement.ts +8 -3
  63. package/src/features/placements/studentPlacements/completedStudentPlacementsSlice.ts +5 -2
  64. package/src/features/placements/studentPlacements/upcomingStudentPlacementsSlice.ts +2 -2
  65. package/src/features/placements/studentPlacements/useStudentPlacements.tsx +4 -28
  66. package/src/features/updates/useUpdates.tsx +14 -12
  67. package/src/firebase/firebase.tsx +26 -15
  68. package/src/firebase/firebaseConfig.tsx +1 -1
  69. package/src/firebase/firebaseQuery.tsx +11 -3
  70. package/src/firebase/readDatabase.tsx +34 -6
  71. package/src/firebase/writeDatabase.tsx +3 -1
  72. package/src/hooks.tsx +1804 -935
  73. package/src/reduxHooks.ts +144 -32
  74. package/src/tasksAndTips.ts +689 -166
  75. package/src/typeDefinitions.ts +373 -109
  76. package/src/util.ts +63 -18
@@ -1,22 +1,24 @@
1
1
  import FirebaseQuery from "../../firebase/firebaseQuery";
2
2
  import {orderBy, limit, arrayUnion} from "firebase/firestore";
3
- import {useState, useEffect} from "react";
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
- useEffect(() => {
11
- setTimeout(() => {
12
- firebaseQuery.getDocsWhere("updates", [orderBy("created", "desc"), limit(1)]).then((result) => {
13
- const item = Object.values(result as {[key:string]: {title: string, body: string, id: string}})[0];
14
- if (!user?.readUpdates?.includes(item.id)) {
15
- setActive(item);
16
- }
17
- })
18
- }, 1000);
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
  }
@@ -5,7 +5,7 @@ import {getUser} from "./readDatabase";
5
5
  import {UserData} from "../typeDefinitions";
6
6
  import FirebaseQuery from "./firebaseQuery";
7
7
  import {auth, functions} from "./firebaseConfig";
8
- import {addJob, setJobStatus} from "../features/jobs/jobsSlice";
8
+ import {addJob, Job, updateJob} from "../features/jobs/jobsSlice";
9
9
  import { useAppDispatch } from "../reduxHooks";
10
10
 
11
11
 
@@ -17,12 +17,15 @@ export const authListener = (setUser: SetStateAction<any>) => {
17
17
  return;
18
18
  }
19
19
  console.log("User logged in.");
20
+ if (!aUser.email) {
21
+ setUser(false);
22
+ return;
23
+ };
20
24
  getUser(aUser.uid, setUser);
21
25
  });
22
26
  };
23
27
 
24
28
  export const login = async (credentials: {email: string, password: string}) => {
25
- console.log("creds", credentials);
26
29
  return signInWithEmailAndPassword(auth, credentials.email, credentials.password);
27
30
  };
28
31
 
@@ -40,7 +43,6 @@ export type RegistrationData = {
40
43
  }
41
44
 
42
45
  export const register = async (credentials: RegistrationData, type:"Institute"|"Provider"|"Student") => {
43
- console.log("creds", credentials);
44
46
  return await executeCallable(`registration-register${type}`, credentials).catch((e) => {
45
47
  console.log("Error in regsiter", e);
46
48
  throw e;
@@ -48,23 +50,25 @@ export const register = async (credentials: RegistrationData, type:"Institute"|"
48
50
  if (type === "Student") {
49
51
  await login({email: credentials.email, password: credentials.passwordOne});
50
52
  }
51
- return (res.data as { message: {uid: string}}).message.uid as string;
53
+ return (res.data as { msg: {uid: string}}).msg.uid as string;
52
54
  });
53
55
  };
54
56
 
55
57
  export const executeCallable = async (functionName: string, data: unknown) => {
56
58
  const funcCallable = httpsCallable(functions, functionName);
57
- return await funcCallable(data).catch((e) => {
59
+ const res = await funcCallable(data).catch((e) => {
58
60
  console.log("callableError", functionName, e);
59
- return e;
61
+ throw e;
60
62
  });
63
+
64
+ return res as {data: any};
61
65
  };
62
66
 
63
67
 
64
68
  export function useExecuteCallableJob({user}:{user: UserData}) {
65
69
  type CallableFunctionJobs = "userManagement-addUsers"|"userManagement-activateUsers"|
66
70
  "userManagement-deactivateUsers"|"userManagement-deleteUsers"|"admissions-createCohort"|"userManagement-uploadAnalytics"|
67
- "placementListing-add"
71
+ "providerContacts-add"|"userManagement-sendParentWelcomeEmail"
68
72
  const dispatch = useAppDispatch();
69
73
 
70
74
  const execute = async (functionName:CallableFunctionJobs, data:{[key:string]:unknown}) => {
@@ -93,10 +97,16 @@ export function useExecuteCallableJob({user}:{user: UserData}) {
93
97
  description: `Attempting deletion of ${Array.isArray((data as {users:{[key:string]:unknown}}).users) ?
94
98
  "multiple" : Object.entries((data as {users:{[key: string]: UserData}}).users).length || "multiple"} users.`,
95
99
  };
96
- case "placementListing-add":
100
+ case "providerContacts-add":
97
101
  return {
98
- title: "Adding placements",
99
- description: `Attempting addition of ${(data as {data:[]}).data.length} placements`,
102
+ title: "Adding employer contacts",
103
+ description: `Attempting addition of ${(data as {providerContacts:[]}).providerContacts.length} employer contacts`,
104
+ };
105
+ case "userManagement-sendParentWelcomeEmail":
106
+ return {
107
+ title: "Sending parent welcome emails",
108
+ description: `Sending parent welcome emails to ${Array.isArray((data as {users:{[key:string]:unknown}}).users) ?
109
+ "multiple" : Object.entries((data as {users:{[key: string]: UserData}}).users).length || "multiple"} users.`,
100
110
  };
101
111
  default:
102
112
  return;
@@ -129,13 +139,14 @@ export function useExecuteCallableJob({user}:{user: UserData}) {
129
139
 
130
140
  const funcCallable = httpsCallable(functions, functionName);
131
141
  console.log(items);
132
- funcCallable(items).then(() => {
133
- dispatch(setJobStatus({
142
+ funcCallable(items).then(async () => {
143
+ const jobResolved = await firebaseQuery.getDocData(["jobs", jobId]) as Job;
144
+ dispatch(updateJob({
134
145
  jobId: jobId,
135
- status: "success",
136
- }));
146
+ data: jobResolved
147
+ } as Partial<Job>));
137
148
  });
138
- return;
149
+ return jobId;
139
150
  };
140
151
 
141
152
  return {execute};
@@ -35,7 +35,7 @@ initializeAuth(firebaseConfig, {
35
35
 
36
36
  initializeFirestore(firebaseConfig, {
37
37
  ignoreUndefinedProperties: true,
38
- })
38
+ });
39
39
 
40
40
  export const auth = getAuth(firebaseConfig);
41
41
  export const db = getFirestore(firebaseConfig);
@@ -53,14 +53,14 @@ export default class FirebaseQuery {
53
53
  await deleteDoc(this.createQuery("doc", path) as DocumentReference);
54
54
  }
55
55
 
56
- async copy(path: string[]|string, id: string, oId: string, product: Products) {
56
+ async copy(path: string[]|string, id: string, oId: string, product: Products, additionalData?: {[key: string]: unknown}) {
57
57
  const existing = await this.getDocData([...path, id]);
58
58
  console.log("existing", existing);
59
59
  existing.name = await this.getUniqueDocName(path, existing.name, oId, product);
60
60
  if (existing.default) {
61
61
  existing.default = false;
62
62
  }
63
- return await this.add(path, existing);
63
+ return await this.add(path, {...existing, ...additionalData});
64
64
  }
65
65
 
66
66
  async getUniqueDocName(path: string[]|string, name: string, oId: string, product: Products): Promise<string> {
@@ -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>, path: string[]|string, constraints?:QueryConstraint[]|QueryConstraint, dispatch?: AppDispatch) {
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) => {
@@ -138,6 +145,7 @@ export default class FirebaseQuery {
138
145
  dispatch ? dispatch(setState(itemList)) : setState(itemList);
139
146
  }, (error) => {
140
147
  console.log(`Error in snapshot ${path}`, error);
148
+ console.log(constraints)
141
149
  });
142
150
  }
143
151
  }
@@ -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,22 @@ 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
- return await firebaseQuery.getDocData(["users", id]) as UserData;
183
+ export const getUserById = async (id: string, setState?: SetStateAction<any>, getGroupData=true) => {
184
+ if (!setState) {
185
+ const user = await firebaseQuery.getDocData(["users", id]).catch(() => false) as UserData|false;
186
+ if (!user) return;
187
+ if (getGroupData) {
188
+ user.groupData = user.userGroup && user.userGroup !== "admin" ? await firebaseQuery.getDocData(["userGroups", user.userGroup]) as UserGroupData : undefined
189
+ }
190
+ return user;
191
+ }
192
+ firebaseQuery.documentSnapshot(["users", id], async (user: UserData) => {
193
+ if (getGroupData) {
194
+ user.groupData = user.userGroup && user.userGroup !== "admin" ? await firebaseQuery.getDocData(["userGroups", user.userGroup]) as UserGroupData : undefined
195
+ }
196
+ setState(user);
197
+ });
198
+ return;
175
199
  };
176
200
 
177
201
  /* export const getUsersByType = async (q: Query, setState:SetStateAction<any>, uid:string, lim:number, limitType?:"start"|"end") => {
@@ -202,7 +226,11 @@ export const checkPlacementConflicts = async (instituteId:string, userGroupId:st
202
226
  };
203
227
 
204
228
  export const getPlacementListingsById = async (placementListings: string[]) => {
205
- return Object.fromEntries(await Promise.all(placementListings.map(async (listingId) => {
206
- return [listingId, await firebaseQuery.getDocData(["placementListings", listingId]) as PlacementListing];
207
- })) as [string, PlacementListing][]);
229
+ const placements = await Promise.all(placementListings.map(async (listingId) => {
230
+ return [listingId, await firebaseQuery.getDocData(["placementListings", listingId]).catch(() => false) as PlacementListing];
231
+ })) as [string, PlacementListing|false][];
232
+
233
+ return placements.filter(([_, v]) => v !== false) as [string, PlacementListing][];
208
234
  }
235
+
236
+
@@ -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
  })