placementt-core 11.0.533 → 11.0.803

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 +15 -9
  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 +226 -16
  44. package/lib/hooks.js +938 -146
  45. package/lib/hooks.js.map +1 -1
  46. package/lib/reduxHooks.d.ts +56 -4
  47. package/lib/reduxHooks.js +63 -19
  48. package/lib/reduxHooks.js.map +1 -1
  49. package/lib/tasksAndTips.d.ts +7 -5
  50. package/lib/tasksAndTips.js +487 -23
  51. package/lib/tasksAndTips.js.map +1 -1
  52. package/lib/typeDefinitions.d.ts +149 -30
  53. package/lib/util.d.ts +7 -2
  54. package/lib/util.js +32 -9
  55. package/lib/util.js.map +1 -1
  56. package/package.json +1 -1
  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 +19 -12
  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 +1124 -166
  73. package/src/reduxHooks.ts +71 -22
  74. package/src/tasksAndTips.ts +495 -30
  75. package/src/typeDefinitions.ts +140 -35
  76. package/src/util.ts +45 -17
@@ -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
 
@@ -22,7 +22,6 @@ export const authListener = (setUser: SetStateAction<any>) => {
22
22
  };
23
23
 
24
24
  export const login = async (credentials: {email: string, password: string}) => {
25
- console.log("creds", credentials);
26
25
  return signInWithEmailAndPassword(auth, credentials.email, credentials.password);
27
26
  };
28
27
 
@@ -40,7 +39,6 @@ export type RegistrationData = {
40
39
  }
41
40
 
42
41
  export const register = async (credentials: RegistrationData, type:"Institute"|"Provider"|"Student") => {
43
- console.log("creds", credentials);
44
42
  return await executeCallable(`registration-register${type}`, credentials).catch((e) => {
45
43
  console.log("Error in regsiter", e);
46
44
  throw e;
@@ -48,23 +46,25 @@ export const register = async (credentials: RegistrationData, type:"Institute"|"
48
46
  if (type === "Student") {
49
47
  await login({email: credentials.email, password: credentials.passwordOne});
50
48
  }
51
- return (res.data as { message: {uid: string}}).message.uid as string;
49
+ return (res.data as { msg: {uid: string}}).msg.uid as string;
52
50
  });
53
51
  };
54
52
 
55
53
  export const executeCallable = async (functionName: string, data: unknown) => {
56
54
  const funcCallable = httpsCallable(functions, functionName);
57
- return await funcCallable(data).catch((e) => {
55
+ const res = await funcCallable(data).catch((e) => {
58
56
  console.log("callableError", functionName, e);
59
- return e;
57
+ throw e;
60
58
  });
59
+
60
+ return res as {data: any};
61
61
  };
62
62
 
63
63
 
64
64
  export function useExecuteCallableJob({user}:{user: UserData}) {
65
65
  type CallableFunctionJobs = "userManagement-addUsers"|"userManagement-activateUsers"|
66
66
  "userManagement-deactivateUsers"|"userManagement-deleteUsers"|"admissions-createCohort"|"userManagement-uploadAnalytics"|
67
- "placementListing-add"
67
+ "placementListing-add"|"userManagement-sendParentWelcomeEmail"
68
68
  const dispatch = useAppDispatch();
69
69
 
70
70
  const execute = async (functionName:CallableFunctionJobs, data:{[key:string]:unknown}) => {
@@ -98,6 +98,12 @@ export function useExecuteCallableJob({user}:{user: UserData}) {
98
98
  title: "Adding placements",
99
99
  description: `Attempting addition of ${(data as {data:[]}).data.length} placements`,
100
100
  };
101
+ case "userManagement-sendParentWelcomeEmail":
102
+ return {
103
+ title: "Sending parent welcome emails",
104
+ description: `Sending parent welcome emails to ${Array.isArray((data as {users:{[key:string]:unknown}}).users) ?
105
+ "multiple" : Object.entries((data as {users:{[key: string]: UserData}}).users).length || "multiple"} users.`,
106
+ };
101
107
  default:
102
108
  return;
103
109
  }
@@ -129,13 +135,14 @@ export function useExecuteCallableJob({user}:{user: UserData}) {
129
135
 
130
136
  const funcCallable = httpsCallable(functions, functionName);
131
137
  console.log(items);
132
- funcCallable(items).then(() => {
133
- dispatch(setJobStatus({
138
+ funcCallable(items).then(async () => {
139
+ const jobResolved = await firebaseQuery.getDocData(["jobs", jobId]) as Job;
140
+ dispatch(updateJob({
134
141
  jobId: jobId,
135
- status: "success",
136
- }));
142
+ data: jobResolved
143
+ } as Partial<Job>));
137
144
  });
138
- return;
145
+ return jobId;
139
146
  };
140
147
 
141
148
  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
  })