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.
- package/.eslintrc.js +40 -40
- package/.gitattributes +2 -2
- package/lib/config.d.ts +0 -1
- package/lib/constants.d.ts +6 -2
- package/lib/constants.js +136 -136
- package/lib/constants.js.map +1 -1
- package/lib/features/analytics/useAnalytics.d.ts +0 -1
- package/lib/features/analytics/useAnalytics.js +3 -4
- package/lib/features/analytics/useAnalytics.js.map +1 -1
- package/lib/features/config.d.ts +133 -133
- package/lib/features/config.js +35 -35
- package/lib/features/contacts/contacts.d.ts +75 -75
- package/lib/features/contacts/contacts.js +105 -105
- package/lib/features/contacts/contactsSlice.d.ts +5 -5
- package/lib/features/contacts/useContacts.js +1 -2
- package/lib/features/contacts/useContacts.js.map +1 -1
- package/lib/features/downtime/useDowntime.d.ts +11 -11
- package/lib/features/downtime/useDowntime.js +22 -22
- package/lib/features/dropdown/useDropdown.d.ts +2 -3
- package/lib/features/dropdown/useDropdown.js +1 -2
- package/lib/features/dropdown/useDropdown.js.map +1 -1
- package/lib/features/global/downtime/useDowntime.d.ts +0 -1
- package/lib/features/global/downtime/useDowntime.js +1 -2
- package/lib/features/global/downtime/useDowntime.js.map +1 -1
- package/lib/features/global/users/useUserFunctions.d.ts +0 -1
- package/lib/features/global/users/useUserFunctions.js +7 -8
- package/lib/features/global/users/useUserFunctions.js.map +1 -1
- package/lib/features/placements/studentPlacements/activePlacement.d.ts +1 -1
- package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.d.ts +2 -2
- package/lib/features/placements/studentPlacements/studentPlacementsSlice.d.ts +63 -63
- package/lib/features/placements/studentPlacements/studentPlacementsSlice.js +81 -81
- package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.d.ts +2 -2
- package/lib/features/placements/studentPlacements/useStudentPlacements.d.ts +0 -1
- package/lib/features/placements/studentPlacements/useStudentPlacements.js +1 -2
- package/lib/features/placements/studentPlacements/useStudentPlacements.js.map +1 -1
- package/lib/features/providerPlacements/providerPlacementsSlice.d.ts +19 -19
- package/lib/features/providerPlacements/providerPlacementsSlice.js +24 -24
- package/lib/features/referrals/useReferrals.d.ts +0 -1
- package/lib/features/referrals/useReferrals.js +1 -2
- package/lib/features/referrals/useReferrals.js.map +1 -1
- package/lib/features/studentPlacements/studentPlacementsSlice.d.ts +62 -62
- package/lib/features/studentPlacements/studentPlacementsSlice.js +87 -87
- package/lib/features/studentPlacements/useStudentPlacements.d.ts +6 -6
- package/lib/features/studentPlacements/useStudentPlacements.js +18 -18
- package/lib/features/updates/useUpdates.js +1 -2
- package/lib/features/updates/useUpdates.js.map +1 -1
- package/lib/features/userSlice.d.ts +26 -26
- package/lib/features/userSlice.js +23 -23
- package/lib/features/users/useUserFunctions.d.ts +25 -25
- package/lib/features/users/useUserFunctions.js +124 -124
- package/lib/features/users/userSlice.d.ts +46 -46
- package/lib/features/users/userSlice.js +48 -48
- package/lib/firebase/firebase.d.ts +3 -1
- package/lib/firebase/firebase.js +9 -3
- package/lib/firebase/firebase.js.map +1 -1
- package/lib/firebase/firebaseConfig.js +3 -0
- package/lib/firebase/firebaseConfig.js.map +1 -1
- package/lib/firebase/firebaseQuery.d.ts +3 -1
- package/lib/firebase/firebaseQuery.js +11 -1
- package/lib/firebase/firebaseQuery.js.map +1 -1
- package/lib/firebase/persistence.js +2 -2
- package/lib/firebase/persistence.js.map +1 -1
- package/lib/firebase/readDatabase.d.ts +8 -7
- package/lib/firebase/readDatabase.js +41 -8
- package/lib/firebase/readDatabase.js.map +1 -1
- package/lib/firebase/util.d.ts +3 -4
- package/lib/firebase/util.js +49 -4
- package/lib/firebase/util.js.map +1 -1
- package/lib/firebase/writeDatabase.d.ts +7 -3
- package/lib/firebase/writeDatabase.js +9 -2
- package/lib/firebase/writeDatabase.js.map +1 -1
- package/lib/hooks.d.ts +476 -20
- package/lib/hooks.js +1855 -237
- package/lib/hooks.js.map +1 -1
- package/lib/images/GatsbyBenchmarks.d.ts +0 -1
- package/lib/images/GatsbyBenchmarks.js +1 -1
- package/lib/images/GatsbyBenchmarks.js.map +1 -1
- package/lib/reduxHooks.d.ts +9 -2
- package/lib/reduxHooks.js +36 -9
- package/lib/reduxHooks.js.map +1 -1
- package/lib/tasksAndTips.d.ts +25 -5
- package/lib/tasksAndTips.js +517 -48
- package/lib/tasksAndTips.js.map +1 -1
- package/lib/typeDefinitions.d.ts +472 -55
- package/lib/util.d.ts +1 -0
- package/lib/util.js +85 -7
- package/lib/util.js.map +1 -1
- package/package.json +52 -49
- package/src/DatabaseDefinitions.ts +18 -18
- package/src/apiCalls.ts +128 -128
- package/src/config.ts +50 -50
- package/src/constants.ts +714 -707
- package/src/databaseTypes.ts +42 -42
- package/src/features/analytics/useAnalytics.tsx +64 -64
- package/src/features/contacts/contactsSlice.ts +147 -147
- package/src/features/contacts/useContacts.tsx +73 -73
- package/src/features/dropdown/useDropdown.tsx +52 -52
- package/src/features/global/downtime/useDowntime.tsx +23 -23
- package/src/features/global/users/useUserFunctions.tsx +132 -132
- package/src/features/jobs/jobsSlice.ts +65 -65
- package/src/features/placements/studentPlacements/activePlacement.ts +68 -68
- package/src/features/placements/studentPlacements/completedStudentPlacementsSlice.ts +97 -97
- package/src/features/placements/studentPlacements/upcomingStudentPlacementsSlice.ts +108 -108
- package/src/features/placements/studentPlacements/useStudentPlacements.tsx +9 -9
- package/src/features/placements/types.ts +10 -10
- package/src/features/referrals/useReferrals.tsx +56 -56
- package/src/features/updates/useUpdates.tsx +38 -38
- package/src/firebase/firebase.tsx +144 -138
- package/src/firebase/firebaseConfig.tsx +45 -42
- package/src/firebase/firebaseQuery.tsx +150 -140
- package/src/firebase/persistence.ts +84 -84
- package/src/firebase/readDatabase.tsx +235 -197
- package/src/firebase/util.tsx +352 -308
- package/src/firebase/writeDatabase.tsx +77 -68
- package/src/hooks.tsx +4029 -1928
- package/src/images/GatsbyBenchmarks.tsx +711 -711
- package/src/images/LogFuturePlacement.jsx +64 -64
- package/src/images/LogPreviousPlacement.jsx +228 -228
- package/src/images/gatsby_benchmarks.svg +466 -466
- package/src/images/log_future_placement.svg +114 -114
- package/src/images/log_previous_placement.svg +199 -199
- package/src/index.ts +34 -34
- package/src/readDatabase.tsx +3 -3
- package/src/reduxHooks.ts +231 -200
- package/src/tasksAndTips.ts +917 -410
- package/src/tutorialTips.ts +58 -58
- package/src/typeDefinitions.ts +893 -503
- package/src/util.ts +137 -47
- package/tsconfig.dev.json +5 -5
- 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
|
+
|
package/src/readDatabase.tsx
CHANGED
|
@@ -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 {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
if (upcomingPlacements
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
// }
|