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
package/src/reduxHooks.ts CHANGED
@@ -1,14 +1,16 @@
1
- import { where } from "firebase/firestore"
1
+ import { orderBy, where } from "firebase/firestore"
2
2
  import { useEffect, useState } from "react"
3
3
  import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux"
4
4
  import { AppDispatch, RootState } from "./config"
5
5
  import { addContact, deleteContact, setContacts, updateContact } from "./features/contacts/contactsSlice"
6
- import { Job, addJob, setJobStatus, setJobs, setMarkRead } from "./features/jobs/jobsSlice"
7
- import { fetchActivePlacement } from "./features/placements/studentPlacements/activePlacement"
6
+ import { Job, addJob, setJobStatus, setJobs, setMarkRead, updateJob } from "./features/jobs/jobsSlice"
7
+ import { editActivePlacement, fetchActivePlacement, setActivePlacement } from "./features/placements/studentPlacements/activePlacement"
8
8
  import { addCompletedStudentPlacements, deleteCompletedStudentPlacement, setCompletedStudentPlacements, updateCompletedStudentPlacement } from "./features/placements/studentPlacements/completedStudentPlacementsSlice"
9
9
  import { addUpcomingStudentPlacements, deleteUpcomingStudentPlacement, setUpcoming, setUpcomingStudentPlacements, updateUpcomingStudentPlacement } from "./features/placements/studentPlacements/upcomingStudentPlacementsSlice"
10
10
  import FirebaseQuery from "./firebase/firebaseQuery"
11
11
  import { Address, Application, Contact, PlacementListing, ProviderData, StudentPlacementData, UserData } from "./typeDefinitions"
12
+ import {getPlacementsWhere} from "./firebase/readDatabase"
13
+ import {convertDate} from "./firebase/util"
12
14
 
13
15
  export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
14
16
  export const useAppDispatch = () => useDispatch<AppDispatch>();
@@ -22,7 +24,7 @@ export function useStudent({user} : {user: UserData}) {
22
24
  const activePlacement = useAppSelector((state) => state.activePlacement.values)
23
25
  const upcoming = useAppSelector((state) => state.upcomingStudentPlacements.upcoming)
24
26
  const contacts = useAppSelector((state) => state.contacts.values)
25
- const [applications, setApplications] = useState<{[key: string]: Application&{listing: PlacementListing, provider: ProviderData, address: Address}}>();
27
+ const [applications, setApplications] = useState<{[key: string]: Application&{listing: PlacementListing|false, provider: ProviderData|false, address: Address}}>();
26
28
  const firebaseQuery = new FirebaseQuery();
27
29
 
28
30
  const dispatch = useAppDispatch();
@@ -41,9 +43,9 @@ export function useStudent({user} : {user: UserData}) {
41
43
  firebaseQuery.collectionSnapshot(async (fApplications: {[key: string]: Application}) => {
42
44
 
43
45
  const applicationsWithProviderAndListing:{[key: string]: Application&{listing: PlacementListing, provider: ProviderData, address: Address}} = Object.fromEntries(await Promise.all(Object.entries(fApplications).map(async ([id, application]) => {
44
- const provider = await firebaseQuery.getDocData(["providers", application.providerId]) as ProviderData;
45
- const listing = await firebaseQuery.getDocData(["placementListings", application.listingId]) as PlacementListing;
46
- const address = listing.addressId && await firebaseQuery.getDocData(["addresses", listing.addressId]) as Address;
46
+ const provider = await firebaseQuery.getDocData(["providers", application.providerId]).catch(() => false) as ProviderData|false;
47
+ const listing = await firebaseQuery.getDocData(["placementListings", application.listingId]).catch(() => false) as PlacementListing|false;
48
+ const address = listing && listing?.addressId && await firebaseQuery.getDocData(["addresses", listing.addressId]) as Address;
47
49
 
48
50
  return [id, {...application, listing: listing, provider: provider, address: address}];
49
51
  })));
@@ -51,25 +53,44 @@ export function useStudent({user} : {user: UserData}) {
51
53
  setApplications(applicationsWithProviderAndListing);
52
54
 
53
55
  }, "applications", applicationsConstraints);
54
- }, [dispatch, user.id]);
55
-
56
+ }, [user.id]);
57
+ /*
56
58
  useEffect(() => {
57
59
  if (!user.id) return
58
60
  dispatch(fetchActivePlacement({userId: user.id}))
59
- }, [dispatch, user.id, upcomingPlacements])
61
+ }, [dispatch, user.id, upcomingPlacements]);
62
+ */
63
+ const fetchUpcomingPlacements = () => {
64
+ const constraints = [where("uid", "==", user.id), where("inProgress", "==", true), orderBy("startDate")]
65
+ firebaseQuery.collectionSnapshot(setUpcomingStudentPlacements, "placements", constraints, dispatch);
66
+ }
60
67
 
61
- useEffect(() => {
62
- console.log("UPDATE UPCOMING");
63
-
68
+ const fetchCompletedPlacements = () => {
69
+ const constraints = [where("uid", "==", user.id), where("completed", "==", true), orderBy("startDate")]
70
+ firebaseQuery.collectionSnapshot(setCompletedStudentPlacements, "placements", constraints, dispatch);
71
+ }
72
+
73
+ const fetchContacts = () => {
74
+ const constraints = [where("uid", "==", user.id)]
75
+ firebaseQuery.collectionSnapshot(setContacts, "contacts", constraints, dispatch);
76
+ }
77
+
78
+ const updateUpcomingPlacement = () => {
64
79
  if (!upcomingPlacements || !Object.entries(upcomingPlacements).length) {
65
80
  dispatch(setUpcoming(undefined));
66
81
  return;
67
82
  }
68
83
  const upcomingPlacement = Object.entries(upcomingPlacements).find(([, v]) => new Date(v.startDate).getTime() > today.getTime())
69
84
  upcomingPlacement ? dispatch(setUpcoming(upcomingPlacement[1])) : dispatch(setUpcoming(undefined))
85
+ }
70
86
 
71
- }, [dispatch, upcomingPlacements]);
72
-
87
+ const updateActivePlacement = () => {
88
+ const key = Object.keys(upcomingPlacements).find((key) => {
89
+ const placement = upcomingPlacements[key]
90
+ return placement.active
91
+ })
92
+ key ? dispatch(setActivePlacement(upcomingPlacements[key])) : dispatch(setActivePlacement(null))
93
+ }
73
94
 
74
95
  const getItemById = async (path: "contacts"|"placements", id: string) => {
75
96
  return await firebaseQuery.getDocData([path, id])
@@ -80,9 +101,9 @@ export function useStudent({user} : {user: UserData}) {
80
101
  else dispatch(deleteCompletedStudentPlacement({placementId: id}))
81
102
  }
82
103
 
83
- const handleUpdatePlacement = async (id: string, data: StudentPlacementData) => {
84
- if (upcomingPlacements[id]) dispatch(updateUpcomingStudentPlacement({placementId: id, attributes: data}))
85
- else dispatch(updateCompletedStudentPlacement({placementId: id, attributes: data}))
104
+ const handleUpdatePlacement = async (id: string, attributes: Partial<StudentPlacementData>) => {
105
+ if (upcomingPlacements[id]) dispatch(updateUpcomingStudentPlacement({placementId: id, attributes}))
106
+ else dispatch(updateCompletedStudentPlacement({placementId: id, attributes}))
86
107
  }
87
108
 
88
109
  const handleAddPlacement = async (formData: StudentPlacementData) => {
@@ -90,19 +111,46 @@ export function useStudent({user} : {user: UserData}) {
90
111
  else dispatch(addUpcomingStudentPlacements({formData}))
91
112
  }
92
113
 
114
+ const getUserPlacements = async () => {
115
+ return await getPlacementsWhere({w: where("uid", "==", user?.id)})
116
+ }
117
+
118
+ const getPlacementsStart = async (start: Date, end: Date) => {
119
+ return await firebaseQuery.getDocsWhere("placements", [where("uid", "==", user?.id), where("startDate", ">=", convertDate(start, "dbstring")), where("startDate", "<=", convertDate(end, "dbstring"))]) as {[key:string]: StudentPlacementData};
120
+ }
121
+
122
+ const getPlacementsEnd = async (end: Date) => {
123
+ return await firebaseQuery.getDocsWhere("placements", [where("uid", "==", user?.id), where("endDate", ">=", convertDate(end, "dbstring")), where("endDate", "<=", convertDate(end, "dbstring"))]) as {[key:string]: StudentPlacementData};
124
+ }
125
+
126
+ const dispatchActivePlacement = () => {
127
+ dispatch(fetchActivePlacement({userId: user.id}))
128
+ }
129
+
93
130
  return {
94
131
  contacts: {
95
- add: async (contactForm: Contact) => dispatch(addContact({contactForm: contactForm, userId: user.id})),
96
- update: async (contactId: string, data: Partial<Contact>) => dispatch(updateContact({contactId: contactId, attributes: data})),
97
- delete: async (contactId: string) => dispatch(deleteContact({contactId: contactId})),
132
+ add: async (contactForm: Contact) => await dispatch(addContact({contactForm: contactForm, userId: user.id})),
133
+ update: async (contactId: string, data: Partial<Contact>) => await dispatch(updateContact({contactId: contactId, attributes: data})),
134
+ delete: async (contactId: string) => await dispatch(deleteContact({contactId: contactId})),
98
135
  contacts,
136
+ fetchContacts,
99
137
  getById: async (item: string) => await getItemById("contacts", item)
100
138
  },
139
+
101
140
  placements: {
102
141
  add: async (formData: StudentPlacementData) => await handleAddPlacement(formData),
103
- update: async (placementId: string, data: StudentPlacementData) => handleUpdatePlacement(placementId, data),
142
+ update: async (placementId: string, attributes: Partial<StudentPlacementData>) => await handleUpdatePlacement(placementId, attributes),
104
143
  delete: async (id: string) => await handleDeletePlacement(id),
144
+ getUserPlacements,
145
+ getPlacementsStart,
146
+ getPlacementsEnd,
105
147
  activePlacement,
148
+ editActivePlacement: (attributes: Partial<StudentPlacementData>) => dispatch(editActivePlacement(attributes)),
149
+ updateActivePlacement,
150
+ updateUpcomingPlacement,
151
+ fetchUpcomingPlacements,
152
+ fetchCompletedPlacements,
153
+ dispatchActivePlacement,
106
154
  upcoming,
107
155
  upcomingPlacements: upcomingPlacements || {},
108
156
  completedPlacements: completedPlacements || {},
@@ -135,6 +183,7 @@ export function useInstituteStaff({user}: {user: UserData}) {
135
183
  addJob: async ({job, jobId} : {job: Partial<Job>, jobId: string}) => dispatch(addJob({job: job, jobId: jobId})),
136
184
  setMarkRead: async (payload) => dispatch(setMarkRead(payload)),
137
185
  setJobStatus: async ({jobId, status}: {jobId: string, status: string}) => dispatch(setJobStatus({jobId: jobId, status: status})),
186
+ updateJob: async ({jobId, data}: {jobId: string, data: string}) => dispatch(updateJob({jobId: jobId, data: data})),
138
187
  getById: getJobById
139
188
  }
140
189
  }