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