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.
- package/lib/constants.d.ts +13 -1
- package/lib/constants.js +86 -1
- package/lib/constants.js.map +1 -1
- package/lib/features/analytics/useAnalytics.d.ts +2 -0
- package/lib/features/analytics/useAnalytics.js +22 -19
- package/lib/features/analytics/useAnalytics.js.map +1 -1
- package/lib/features/global/downtime/useDowntime.d.ts +1 -0
- package/lib/features/global/downtime/useDowntime.js +9 -7
- package/lib/features/global/downtime/useDowntime.js.map +1 -1
- package/lib/features/global/users/useUserFunctions.js +1 -1
- package/lib/features/global/users/useUserFunctions.js.map +1 -1
- package/lib/features/jobs/jobsSlice.d.ts +10 -2
- package/lib/features/jobs/jobsSlice.js +5 -2
- package/lib/features/jobs/jobsSlice.js.map +1 -1
- package/lib/features/placements/studentPlacements/activePlacement.d.ts +5 -1
- package/lib/features/placements/studentPlacements/activePlacement.js +7 -3
- package/lib/features/placements/studentPlacements/activePlacement.js.map +1 -1
- package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.d.ts +3 -2
- package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.js +4 -1
- package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.js.map +1 -1
- package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.d.ts +2 -2
- package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.js +1 -1
- package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.js.map +1 -1
- package/lib/features/placements/studentPlacements/useStudentPlacements.d.ts +2 -12
- package/lib/features/placements/studentPlacements/useStudentPlacements.js +1 -26
- package/lib/features/placements/studentPlacements/useStudentPlacements.js.map +1 -1
- package/lib/features/updates/useUpdates.d.ts +1 -0
- package/lib/features/updates/useUpdates.js +13 -12
- package/lib/features/updates/useUpdates.js.map +1 -1
- package/lib/firebase/firebase.d.ts +5 -3
- package/lib/firebase/firebase.js +15 -9
- package/lib/firebase/firebase.js.map +1 -1
- package/lib/firebase/firebaseConfig.js.map +1 -1
- package/lib/firebase/firebaseQuery.d.ts +6 -2
- package/lib/firebase/firebaseQuery.js +11 -3
- package/lib/firebase/firebaseQuery.js.map +1 -1
- package/lib/firebase/readDatabase.d.ts +2 -4
- package/lib/firebase/readDatabase.js +30 -5
- package/lib/firebase/readDatabase.js.map +1 -1
- package/lib/firebase/writeDatabase.d.ts +6 -2
- package/lib/firebase/writeDatabase.js +2 -1
- package/lib/firebase/writeDatabase.js.map +1 -1
- package/lib/hooks.d.ts +226 -16
- package/lib/hooks.js +938 -146
- package/lib/hooks.js.map +1 -1
- package/lib/reduxHooks.d.ts +56 -4
- package/lib/reduxHooks.js +63 -19
- package/lib/reduxHooks.js.map +1 -1
- package/lib/tasksAndTips.d.ts +7 -5
- package/lib/tasksAndTips.js +487 -23
- package/lib/tasksAndTips.js.map +1 -1
- package/lib/typeDefinitions.d.ts +149 -30
- package/lib/util.d.ts +7 -2
- package/lib/util.js +32 -9
- package/lib/util.js.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +91 -3
- package/src/features/analytics/useAnalytics.tsx +25 -17
- package/src/features/global/downtime/useDowntime.tsx +11 -7
- package/src/features/global/users/useUserFunctions.tsx +1 -1
- package/src/features/jobs/jobsSlice.ts +9 -3
- package/src/features/placements/studentPlacements/activePlacement.ts +8 -3
- package/src/features/placements/studentPlacements/completedStudentPlacementsSlice.ts +5 -2
- package/src/features/placements/studentPlacements/upcomingStudentPlacementsSlice.ts +2 -2
- package/src/features/placements/studentPlacements/useStudentPlacements.tsx +4 -28
- package/src/features/updates/useUpdates.tsx +14 -12
- package/src/firebase/firebase.tsx +19 -12
- package/src/firebase/firebaseConfig.tsx +1 -1
- package/src/firebase/firebaseQuery.tsx +11 -3
- package/src/firebase/readDatabase.tsx +34 -6
- package/src/firebase/writeDatabase.tsx +3 -1
- package/src/hooks.tsx +1124 -166
- package/src/reduxHooks.ts +71 -22
- package/src/tasksAndTips.ts +495 -30
- package/src/typeDefinitions.ts +140 -35
- 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
|
|
46
|
-
const 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
|
-
}, [
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
|
|
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,
|
|
84
|
-
if (upcomingPlacements[id]) dispatch(updateUpcomingStudentPlacement({placementId: id, attributes
|
|
85
|
-
else dispatch(updateCompletedStudentPlacement({placementId: id, attributes
|
|
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,
|
|
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
|
}
|