placementt-core 1.20.197 → 11.0.533

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 (135) hide show
  1. package/.eslintrc.js +40 -40
  2. package/.gitattributes +2 -2
  3. package/lib/config.d.ts +0 -1
  4. package/lib/constants.d.ts +5 -2
  5. package/lib/constants.js +130 -136
  6. package/lib/constants.js.map +1 -1
  7. package/lib/features/analytics/useAnalytics.d.ts +0 -1
  8. package/lib/features/analytics/useAnalytics.js +3 -4
  9. package/lib/features/analytics/useAnalytics.js.map +1 -1
  10. package/lib/features/config.d.ts +133 -133
  11. package/lib/features/config.js +35 -35
  12. package/lib/features/contacts/contacts.d.ts +75 -75
  13. package/lib/features/contacts/contacts.js +105 -105
  14. package/lib/features/contacts/contactsSlice.d.ts +5 -5
  15. package/lib/features/contacts/useContacts.js +1 -2
  16. package/lib/features/contacts/useContacts.js.map +1 -1
  17. package/lib/features/downtime/useDowntime.d.ts +11 -11
  18. package/lib/features/downtime/useDowntime.js +22 -22
  19. package/lib/features/dropdown/useDropdown.d.ts +2 -3
  20. package/lib/features/dropdown/useDropdown.js +1 -2
  21. package/lib/features/dropdown/useDropdown.js.map +1 -1
  22. package/lib/features/global/downtime/useDowntime.d.ts +0 -1
  23. package/lib/features/global/downtime/useDowntime.js +3 -2
  24. package/lib/features/global/downtime/useDowntime.js.map +1 -1
  25. package/lib/features/global/users/useUserFunctions.d.ts +0 -1
  26. package/lib/features/global/users/useUserFunctions.js +6 -7
  27. package/lib/features/global/users/useUserFunctions.js.map +1 -1
  28. package/lib/features/placements/studentPlacements/activePlacement.d.ts +1 -1
  29. package/lib/features/placements/studentPlacements/activePlacement.js +1 -1
  30. package/lib/features/placements/studentPlacements/activePlacement.js.map +1 -1
  31. package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.d.ts +4 -5
  32. package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.js +1 -4
  33. package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.js.map +1 -1
  34. package/lib/features/placements/studentPlacements/studentPlacementsSlice.d.ts +63 -63
  35. package/lib/features/placements/studentPlacements/studentPlacementsSlice.js +81 -81
  36. package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.d.ts +4 -4
  37. package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.js +1 -1
  38. package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.js.map +1 -1
  39. package/lib/features/placements/studentPlacements/useStudentPlacements.d.ts +0 -1
  40. package/lib/features/placements/studentPlacements/useStudentPlacements.js +1 -2
  41. package/lib/features/placements/studentPlacements/useStudentPlacements.js.map +1 -1
  42. package/lib/features/providerPlacements/providerPlacementsSlice.d.ts +19 -19
  43. package/lib/features/providerPlacements/providerPlacementsSlice.js +24 -24
  44. package/lib/features/referrals/useReferrals.d.ts +0 -1
  45. package/lib/features/referrals/useReferrals.js +1 -2
  46. package/lib/features/referrals/useReferrals.js.map +1 -1
  47. package/lib/features/studentPlacements/studentPlacementsSlice.d.ts +62 -62
  48. package/lib/features/studentPlacements/studentPlacementsSlice.js +87 -87
  49. package/lib/features/studentPlacements/useStudentPlacements.d.ts +6 -6
  50. package/lib/features/studentPlacements/useStudentPlacements.js +18 -18
  51. package/lib/features/updates/useUpdates.js +1 -2
  52. package/lib/features/updates/useUpdates.js.map +1 -1
  53. package/lib/features/userSlice.d.ts +26 -26
  54. package/lib/features/userSlice.js +23 -23
  55. package/lib/features/users/useUserFunctions.d.ts +25 -25
  56. package/lib/features/users/useUserFunctions.js +124 -124
  57. package/lib/features/users/userSlice.d.ts +46 -46
  58. package/lib/features/users/userSlice.js +48 -48
  59. package/lib/firebase/firebase.d.ts +1 -1
  60. package/lib/firebase/firebase.js +9 -4
  61. package/lib/firebase/firebase.js.map +1 -1
  62. package/lib/firebase/firebaseConfig.js +3 -0
  63. package/lib/firebase/firebaseConfig.js.map +1 -1
  64. package/lib/firebase/firebaseQuery.js +3 -0
  65. package/lib/firebase/firebaseQuery.js.map +1 -1
  66. package/lib/firebase/persistence.js +2 -2
  67. package/lib/firebase/persistence.js.map +1 -1
  68. package/lib/firebase/readDatabase.d.ts +9 -6
  69. package/lib/firebase/readDatabase.js +16 -6
  70. package/lib/firebase/readDatabase.js.map +1 -1
  71. package/lib/firebase/util.d.ts +3 -4
  72. package/lib/firebase/util.js +49 -4
  73. package/lib/firebase/util.js.map +1 -1
  74. package/lib/firebase/writeDatabase.d.ts +3 -3
  75. package/lib/firebase/writeDatabase.js +7 -1
  76. package/lib/firebase/writeDatabase.js.map +1 -1
  77. package/lib/hooks.d.ts +384 -23
  78. package/lib/hooks.js +1342 -223
  79. package/lib/hooks.js.map +1 -1
  80. package/lib/images/GatsbyBenchmarks.d.ts +0 -1
  81. package/lib/images/GatsbyBenchmarks.js +1 -1
  82. package/lib/images/GatsbyBenchmarks.js.map +1 -1
  83. package/lib/reduxHooks.d.ts +11 -20
  84. package/lib/reduxHooks.js +28 -18
  85. package/lib/reduxHooks.js.map +1 -1
  86. package/lib/tasksAndTips.d.ts +25 -5
  87. package/lib/tasksAndTips.js +346 -48
  88. package/lib/tasksAndTips.js.map +1 -1
  89. package/lib/typeDefinitions.d.ts +478 -53
  90. package/lib/util.d.ts +1 -0
  91. package/lib/util.js +78 -6
  92. package/lib/util.js.map +1 -1
  93. package/package.json +52 -49
  94. package/src/DatabaseDefinitions.ts +18 -18
  95. package/src/apiCalls.ts +128 -128
  96. package/src/config.ts +50 -50
  97. package/src/constants.ts +708 -707
  98. package/src/databaseTypes.ts +42 -42
  99. package/src/features/analytics/useAnalytics.tsx +55 -55
  100. package/src/features/contacts/contactsSlice.ts +147 -147
  101. package/src/features/contacts/useContacts.tsx +73 -73
  102. package/src/features/dropdown/useDropdown.tsx +52 -52
  103. package/src/features/global/downtime/useDowntime.tsx +19 -18
  104. package/src/features/global/users/useUserFunctions.tsx +132 -132
  105. package/src/features/jobs/jobsSlice.ts +65 -65
  106. package/src/features/placements/studentPlacements/activePlacement.ts +63 -63
  107. package/src/features/placements/studentPlacements/completedStudentPlacementsSlice.ts +94 -97
  108. package/src/features/placements/studentPlacements/upcomingStudentPlacementsSlice.ts +108 -108
  109. package/src/features/placements/studentPlacements/useStudentPlacements.tsx +33 -33
  110. package/src/features/placements/types.ts +10 -10
  111. package/src/features/referrals/useReferrals.tsx +56 -56
  112. package/src/features/updates/useUpdates.tsx +36 -36
  113. package/src/firebase/firebase.tsx +142 -138
  114. package/src/firebase/firebaseConfig.tsx +45 -42
  115. package/src/firebase/firebaseQuery.tsx +143 -140
  116. package/src/firebase/persistence.ts +84 -84
  117. package/src/firebase/readDatabase.tsx +208 -197
  118. package/src/firebase/util.tsx +352 -308
  119. package/src/firebase/writeDatabase.tsx +75 -68
  120. package/src/hooks.tsx +3395 -1943
  121. package/src/images/GatsbyBenchmarks.tsx +711 -711
  122. package/src/images/LogFuturePlacement.jsx +64 -64
  123. package/src/images/LogPreviousPlacement.jsx +228 -228
  124. package/src/images/gatsby_benchmarks.svg +466 -466
  125. package/src/images/log_future_placement.svg +114 -114
  126. package/src/images/log_previous_placement.svg +199 -199
  127. package/src/index.ts +34 -34
  128. package/src/readDatabase.tsx +3 -3
  129. package/src/reduxHooks.ts +183 -170
  130. package/src/tasksAndTips.ts +744 -410
  131. package/src/tutorialTips.ts +58 -58
  132. package/src/typeDefinitions.ts +899 -503
  133. package/src/util.ts +132 -47
  134. package/tsconfig.dev.json +5 -5
  135. package/tsconfig.json +21 -21
package/src/index.ts CHANGED
@@ -1,34 +1,34 @@
1
-
2
- export * from "./firebase/firebase";
3
- export * from "./firebase/readDatabase";
4
- export * from "./firebase/writeDatabase";
5
- export * from "./firebase/util";
6
- export * from "./firebase/firebaseConfig";
7
- export * from "./firebase/firebaseQuery";
8
-
9
- export * from "./typeDefinitions";
10
- export * from "./tutorialTips";
11
- export * from "./constants";
12
- export * from "./hooks";
13
- export * from "./util";
14
- export * from "./images/GatsbyBenchmarks";
15
- export * from "./databaseTypes";
16
- export * from "./tasksAndTips";
17
- export * from "./config";
18
- export * from "./features/jobs/jobsSlice";
19
- export * from "./features/analytics/useAnalytics"
20
- export * from "./features/global/downtime/useDowntime";
21
- export * from "./features/dropdown/useDropdown";
22
- export * from "./features/contacts/useContacts";
23
- export * from "./features/contacts/contactsSlice";
24
- export * from "./features/placements/studentPlacements/upcomingStudentPlacementsSlice";
25
- export * from "./features/placements/studentPlacements/completedStudentPlacementsSlice";
26
- export * from "./features/placements/studentPlacements/useStudentPlacements";
27
- export * from "./features/referrals/useReferrals";
28
- export * from "./features/updates/useUpdates";
29
- export * from "./features/global/users/useUserFunctions";
30
- export * from "./apiCalls";
31
- export * from "./DatabaseDefinitions";
32
- export * from "./reduxHooks"
33
-
34
-
1
+
2
+ export * from "./firebase/firebase";
3
+ export * from "./firebase/readDatabase";
4
+ export * from "./firebase/writeDatabase";
5
+ export * from "./firebase/util";
6
+ export * from "./firebase/firebaseConfig";
7
+ export * from "./firebase/firebaseQuery";
8
+
9
+ export * from "./typeDefinitions";
10
+ export * from "./tutorialTips";
11
+ export * from "./constants";
12
+ export * from "./hooks";
13
+ export * from "./util";
14
+ export * from "./images/GatsbyBenchmarks";
15
+ export * from "./databaseTypes";
16
+ export * from "./tasksAndTips";
17
+ export * from "./config";
18
+ export * from "./features/jobs/jobsSlice";
19
+ export * from "./features/analytics/useAnalytics"
20
+ export * from "./features/global/downtime/useDowntime";
21
+ export * from "./features/dropdown/useDropdown";
22
+ export * from "./features/contacts/useContacts";
23
+ export * from "./features/contacts/contactsSlice";
24
+ export * from "./features/placements/studentPlacements/upcomingStudentPlacementsSlice";
25
+ export * from "./features/placements/studentPlacements/completedStudentPlacementsSlice";
26
+ export * from "./features/placements/studentPlacements/useStudentPlacements";
27
+ export * from "./features/referrals/useReferrals";
28
+ export * from "./features/updates/useUpdates";
29
+ export * from "./features/global/users/useUserFunctions";
30
+ export * from "./apiCalls";
31
+ export * from "./DatabaseDefinitions";
32
+ export * from "./reduxHooks"
33
+
34
+
@@ -1,4 +1,4 @@
1
-
2
- export const getContact = async (contactId: number, ) => {
3
-
1
+
2
+ export const getContact = async (contactId: number, ) => {
3
+
4
4
  }
package/src/reduxHooks.ts CHANGED
@@ -1,171 +1,184 @@
1
- import { where, orderBy } from "firebase/firestore"
2
- import { useEffect } from "react"
3
- import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux"
4
- import { AppDispatch, RootState } from "./config"
5
- import { addContact, deleteContact, setContacts, updateContact } from "./features/contacts/contactsSlice"
6
- import { Job, addJob, setJobStatus, setJobs, setMarkRead } from "./features/jobs/jobsSlice"
7
- import { fetchActivePlacement, setActivePlacement } from "./features/placements/studentPlacements/activePlacement"
8
- import { addCompletedStudentPlacements, deleteCompletedStudentPlacement, setCompletedStudentPlacements, updateCompletedStudentPlacement } from "./features/placements/studentPlacements/completedStudentPlacementsSlice"
9
- import { addUpcomingStudentPlacements, deleteUpcomingStudentPlacement, setUpcoming, setUpcomingStudentPlacements, updateUpcomingStudentPlacement } from "./features/placements/studentPlacements/upcomingStudentPlacementsSlice"
10
- import FirebaseQuery from "./firebase/firebaseQuery"
11
- import { Contact, StudentPlacementData, UserData } from "./typeDefinitions"
12
-
13
- export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
14
- export const useAppDispatch = () => useDispatch<AppDispatch>();
15
-
16
-
17
- export function useStudent({user} : {user: UserData}) {
18
- if (!user || user.product !== "students") return {};
19
-
20
- const upcomingPlacements = useAppSelector((state) => state.upcomingStudentPlacements.values)
21
- const completedPlacements = useAppSelector((state) => state.completedStudentPlacements.values)
22
- const activePlacement = useAppSelector((state) => state.activePlacement.values)
23
- const upcoming = useAppSelector((state) => state.upcomingStudentPlacements.upcoming)
24
- const contacts = useAppSelector((state) => state.contacts.values)
25
- const firebaseQuery = new FirebaseQuery();
26
-
27
- const dispatch = useAppDispatch();
28
-
29
- const today = new Date();
30
-
31
- const upcomingPlacementsConstraints = [where("uid", "==", user.id), where("inProgress", "==", true), orderBy("startDate")]
32
- const completedPlacementsConstraints = [where("uid", "==", user.id), where("completed", "==", true), orderBy("startDate")]
33
- const contactsConstraints = [where("uid", "==", user.id)]
34
-
35
- useEffect(() => {
36
- firebaseQuery.collectionSnapshot(setUpcomingStudentPlacements, "placements", upcomingPlacementsConstraints, dispatch);
37
- firebaseQuery.collectionSnapshot(setCompletedStudentPlacements, "placements", completedPlacementsConstraints, dispatch);
38
- firebaseQuery.collectionSnapshot(setContacts, "contacts", contactsConstraints, dispatch);
39
- }, [dispatch, user.id]);
40
-
41
- useEffect(() => {
42
- if (!user.id) return
43
- dispatch(fetchActivePlacement({userId: user.id}))
44
- }, [dispatch, user.id, upcomingPlacements])
45
-
46
- useEffect(() => {
47
- console.log("UPDATE UPCOMING");
48
-
49
- if (!upcomingPlacements || !Object.entries(upcomingPlacements).length) {
50
- dispatch(setUpcoming(undefined));
51
- return;
52
- }
53
- const upcomingPlacement = Object.entries(upcomingPlacements).find(([, v]) => new Date(v.startDate).getTime() > today.getTime())
54
- upcomingPlacement ? dispatch(setUpcoming(upcomingPlacement[1])) : dispatch(setUpcoming(undefined))
55
-
56
- }, [dispatch, upcomingPlacements, completedPlacements]);
57
-
58
-
59
- const getItemById = async (path: "contacts"|"placements", id: string) => {
60
- return await firebaseQuery.getDocData([path, id])
61
- }
62
-
63
- const handleDeletePlacement = async (id: string) => {
64
- if (upcomingPlacements[id]) dispatch(deleteUpcomingStudentPlacement({placementId: id}))
65
- else dispatch(deleteCompletedStudentPlacement({placementId: id}))
66
- }
67
-
68
- const handleUpdatePlacement = async (id: string, attributes: Partial<StudentPlacementData>) => {
69
- if (upcomingPlacements[id]) dispatch(updateUpcomingStudentPlacement({placementId: id, attributes}))
70
- else dispatch(updateCompletedStudentPlacement({placementId: id, attributes}))
71
- }
72
-
73
- const handleAddPlacement = async (formData: StudentPlacementData) => {
74
- if (formData.completed) dispatch(addCompletedStudentPlacements({formData}))
75
- else dispatch(addUpcomingStudentPlacements({formData}))
76
- }
77
-
78
- return {
79
- contacts: {
80
- add: async (contactForm: Contact) => await dispatch(addContact({contactForm: contactForm, userId: user.id})),
81
- update: async (contactId: string, data: Partial<Contact>) => await dispatch(updateContact({contactId: contactId, attributes: data})),
82
- delete: async (contactId: string) => await dispatch(deleteContact({contactId: contactId})),
83
- contacts,
84
- getById: async (item: string) => await getItemById("contacts", item)
85
- },
86
-
87
- placements: {
88
- add: async (formData: StudentPlacementData) => await handleAddPlacement(formData),
89
- update: async (placementId: string, attributes: Partial<StudentPlacementData>) => await handleUpdatePlacement(placementId, attributes),
90
- delete: async (id: string) => await handleDeletePlacement(id),
91
- activePlacement,
92
- updateActivePlacement: (formData: StudentPlacementData) => dispatch(setActivePlacement(formData)),
93
- upcoming,
94
- updateUpcomingPlacement: (formData: StudentPlacementData) => dispatch(setUpcoming(formData)),
95
- upcomingPlacements: upcomingPlacements || {},
96
- completedPlacements: completedPlacements || {},
97
- getById: async (item: string) => await getItemById("placements", item)
98
- }
99
- } ;
100
- };
101
-
102
-
103
- export function useInstituteStaff({user}: {user: UserData}) {
104
- const firebaseQuery = new FirebaseQuery();
105
- const dispatch = useAppDispatch();
106
-
107
- if (!user || user?.product !== "institutes" || user.userType !== "Staff") return {};
108
-
109
- const getJobById = async (id: string) => {
110
- try {
111
- const job = await firebaseQuery.getDocData(["jobs", id])
112
- return job
113
-
114
- } catch (error) {
115
- throw error
116
- }
117
- }
118
-
119
- return {
120
- jobs: {
121
- setJobs: async (jobs: {[jobId: string]: Job}) => dispatch(setJobs(jobs)),
122
- addJob: async ({job, jobId} : {job: Partial<Job>, jobId: string}) => dispatch(addJob({job: job, jobId: jobId})),
123
- setMarkRead: async (payload) => dispatch(setMarkRead(payload)),
124
- setJobStatus: async ({jobId, status}: {jobId: string, status: string}) => dispatch(setJobStatus({jobId: jobId, status: status})),
125
- getById: getJobById
126
- }
127
- }
128
-
129
-
130
- }
131
-
132
- export function useInstituteStudent({user}: {user: UserData}) {
133
- const {contacts, placements} = useStudent({user});
134
-
135
- if (!user || user?.product !== "institutes" || user.userType !== "Students") return {};
136
-
137
- return {
138
- contacts,
139
- placements
140
- }
141
-
142
- }
143
-
144
- export function useProvider({user}: {user: UserData}) {
145
- if (!user || user?.product !== "providers") return {};
146
-
147
- const {jobs} = useInstituteStaff({user});
148
-
149
- return {
150
- jobs
151
- }
152
-
153
- }
154
-
155
-
156
-
157
- // function MyContactComponent() {
158
- // const {contacts} = useStudent({});
159
-
160
- // contacts.add({data})
161
-
162
- // return null
163
- // }
164
-
165
- // function MyPlacementComponent() {
166
- // const {placements} = useStudent();
167
-
168
- // placements.add({data})
169
-
170
- // return null
1
+ import { where } from "firebase/firestore"
2
+ import { useEffect, useState } from "react"
3
+ import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux"
4
+ import { AppDispatch, RootState } from "./config"
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"
8
+ import { addCompletedStudentPlacements, deleteCompletedStudentPlacement, setCompletedStudentPlacements, updateCompletedStudentPlacement } from "./features/placements/studentPlacements/completedStudentPlacementsSlice"
9
+ import { addUpcomingStudentPlacements, deleteUpcomingStudentPlacement, setUpcoming, setUpcomingStudentPlacements, updateUpcomingStudentPlacement } from "./features/placements/studentPlacements/upcomingStudentPlacementsSlice"
10
+ import FirebaseQuery from "./firebase/firebaseQuery"
11
+ import { Address, Application, Contact, PlacementListing, ProviderData, StudentPlacementData, UserData } from "./typeDefinitions"
12
+
13
+ export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
14
+ export const useAppDispatch = () => useDispatch<AppDispatch>();
15
+
16
+
17
+ export function useStudent({user} : {user: UserData}) {
18
+ if (!user || user.product !== "students") return {};
19
+
20
+ const upcomingPlacements = useAppSelector((state) => state.upcomingStudentPlacements.values)
21
+ const completedPlacements = useAppSelector((state) => state.completedStudentPlacements.values)
22
+ const activePlacement = useAppSelector((state) => state.activePlacement.values)
23
+ const upcoming = useAppSelector((state) => state.upcomingStudentPlacements.upcoming)
24
+ const contacts = useAppSelector((state) => state.contacts.values)
25
+ const [applications, setApplications] = useState<{[key: string]: Application&{listing: PlacementListing, provider: ProviderData, address: Address}}>();
26
+ const firebaseQuery = new FirebaseQuery();
27
+
28
+ const dispatch = useAppDispatch();
29
+
30
+ const today = new Date();
31
+
32
+ const applicationsConstraints = [where("uid", "==", user.id)]
33
+ const upcomingPlacementsConstraints = [where("uid", "==", user.id), where("inProgress", "==", true)]
34
+ const completedPlacementsConstraints = [where("uid", "==", user.id), where("completed", "==", true)]
35
+ const contactsConstraints = [where("uid", "==", user.id)]
36
+
37
+ useEffect(() => {
38
+ firebaseQuery.collectionSnapshot(setUpcomingStudentPlacements, "placements", upcomingPlacementsConstraints, dispatch);
39
+ firebaseQuery.collectionSnapshot(setCompletedStudentPlacements, "placements", completedPlacementsConstraints, dispatch);
40
+ firebaseQuery.collectionSnapshot(setContacts, "contacts", contactsConstraints, dispatch);
41
+ firebaseQuery.collectionSnapshot(async (fApplications: {[key: string]: Application}) => {
42
+
43
+ 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;
47
+
48
+ return [id, {...application, listing: listing, provider: provider, address: address}];
49
+ })));
50
+
51
+ setApplications(applicationsWithProviderAndListing);
52
+
53
+ }, "applications", applicationsConstraints);
54
+ }, [dispatch, user.id]);
55
+
56
+ useEffect(() => {
57
+ if (!user.id) return
58
+ dispatch(fetchActivePlacement({userId: user.id}))
59
+ }, [dispatch, user.id, upcomingPlacements])
60
+
61
+ useEffect(() => {
62
+ console.log("UPDATE UPCOMING");
63
+
64
+ if (!upcomingPlacements || !Object.entries(upcomingPlacements).length) {
65
+ dispatch(setUpcoming(undefined));
66
+ return;
67
+ }
68
+ const upcomingPlacement = Object.entries(upcomingPlacements).find(([, v]) => new Date(v.startDate).getTime() > today.getTime())
69
+ upcomingPlacement ? dispatch(setUpcoming(upcomingPlacement[1])) : dispatch(setUpcoming(undefined))
70
+
71
+ }, [dispatch, upcomingPlacements]);
72
+
73
+
74
+ const getItemById = async (path: "contacts"|"placements", id: string) => {
75
+ return await firebaseQuery.getDocData([path, id])
76
+ }
77
+
78
+ const handleDeletePlacement = async (id: string) => {
79
+ if (upcomingPlacements[id]) dispatch(deleteUpcomingStudentPlacement({placementId: id}))
80
+ else dispatch(deleteCompletedStudentPlacement({placementId: id}))
81
+ }
82
+
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}))
86
+ }
87
+
88
+ const handleAddPlacement = async (formData: StudentPlacementData) => {
89
+ if (formData.completed) dispatch(addCompletedStudentPlacements({formData}))
90
+ else dispatch(addUpcomingStudentPlacements({formData}))
91
+ }
92
+
93
+ return {
94
+ 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})),
98
+ contacts,
99
+ getById: async (item: string) => await getItemById("contacts", item)
100
+ },
101
+ placements: {
102
+ add: async (formData: StudentPlacementData) => await handleAddPlacement(formData),
103
+ update: async (placementId: string, data: StudentPlacementData) => handleUpdatePlacement(placementId, data),
104
+ delete: async (id: string) => await handleDeletePlacement(id),
105
+ activePlacement,
106
+ upcoming,
107
+ upcomingPlacements: upcomingPlacements || {},
108
+ completedPlacements: completedPlacements || {},
109
+ getById: async (item: string) => await getItemById("placements", item)
110
+ },
111
+ applications: applications,
112
+ } ;
113
+ };
114
+
115
+
116
+ export function useInstituteStaff({user}: {user: UserData}) {
117
+ const firebaseQuery = new FirebaseQuery();
118
+ const dispatch = useAppDispatch();
119
+
120
+ if (!user || user?.product !== "institutes" || user.userType !== "Staff") return {};
121
+
122
+ const getJobById = async (id: string) => {
123
+ try {
124
+ const job = await firebaseQuery.getDocData(["jobs", id])
125
+ return job
126
+
127
+ } catch (error) {
128
+ throw error
129
+ }
130
+ }
131
+
132
+ return {
133
+ jobs: {
134
+ setJobs: async (jobs: {[jobId: string]: Job}) => dispatch(setJobs(jobs)),
135
+ addJob: async ({job, jobId} : {job: Partial<Job>, jobId: string}) => dispatch(addJob({job: job, jobId: jobId})),
136
+ setMarkRead: async (payload) => dispatch(setMarkRead(payload)),
137
+ setJobStatus: async ({jobId, status}: {jobId: string, status: string}) => dispatch(setJobStatus({jobId: jobId, status: status})),
138
+ getById: getJobById
139
+ }
140
+ }
141
+
142
+
143
+ }
144
+
145
+ export function useInstituteStudent({user}: {user: UserData}) {
146
+ const {contacts, placements} = useStudent({user});
147
+
148
+ if (!user || user?.product !== "institutes" || user.userType !== "Students") return {};
149
+
150
+ return {
151
+ contacts,
152
+ placements
153
+ }
154
+
155
+ }
156
+
157
+ export function useProvider({user}: {user: UserData}) {
158
+ if (!user || user?.product !== "providers") return {};
159
+
160
+ const {jobs} = useInstituteStaff({user});
161
+
162
+ return {
163
+ jobs
164
+ }
165
+
166
+ }
167
+
168
+
169
+
170
+ // function MyContactComponent() {
171
+ // const {contacts} = useStudent({});
172
+
173
+ // contacts.add({data})
174
+
175
+ // return null
176
+ // }
177
+
178
+ // function MyPlacementComponent() {
179
+ // const {placements} = useStudent();
180
+
181
+ // placements.add({data})
182
+
183
+ // return null
171
184
  // }