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
@@ -1,42 +1,42 @@
1
- // import {WorkflowStage} from "./typeDefinitions";
2
-
3
- export type StudentUser = {
4
- UserID: string,
5
- forename: string,
6
- surname: string,
7
- email:string,
8
- created: Date,
9
- referral: string
10
- }
11
-
12
- export type InstituteStudentUser = {
13
- UserID: string,
14
- forename: string,
15
- surname: string,
16
- email: string,
17
- created: Date,
18
- activated: Date,
19
- cohortID: string,
20
- // cohortData: Cohort
21
- }
22
-
23
- export type InstituteStaffUser = {
24
- UserID: string,
25
- forename: string,
26
- surname: string,
27
- email: string,
28
- created: Date,
29
- activated: Date,
30
- }
31
-
32
- export type ProviderUser = {
33
- UserID: string,
34
- }
35
- /*
36
- export type Cohort = {
37
- CohortID: string,
38
- name: string,
39
- created: Date,
40
- workflow: WorkflowStage[],
41
- }
42
- */
1
+ // import {WorkflowStage} from "./typeDefinitions";
2
+
3
+ export type StudentUser = {
4
+ UserID: string,
5
+ forename: string,
6
+ surname: string,
7
+ email:string,
8
+ created: Date,
9
+ referral: string
10
+ }
11
+
12
+ export type InstituteStudentUser = {
13
+ UserID: string,
14
+ forename: string,
15
+ surname: string,
16
+ email: string,
17
+ created: Date,
18
+ activated: Date,
19
+ cohortID: string,
20
+ // cohortData: Cohort
21
+ }
22
+
23
+ export type InstituteStaffUser = {
24
+ UserID: string,
25
+ forename: string,
26
+ surname: string,
27
+ email: string,
28
+ created: Date,
29
+ activated: Date,
30
+ }
31
+
32
+ export type ProviderUser = {
33
+ UserID: string,
34
+ }
35
+ /*
36
+ export type Cohort = {
37
+ CohortID: string,
38
+ name: string,
39
+ created: Date,
40
+ workflow: WorkflowStage[],
41
+ }
42
+ */
@@ -1,56 +1,56 @@
1
- import {useState, useEffect} from "react"
2
- import FirebaseQuery from "../../firebase/firebaseQuery"
3
- import {where} from "firebase/firestore"
4
- import {StudentPlacementData, UserData} from "../../typeDefinitions"
5
- import {useAppDispatch} from "../../reduxHooks"
6
- import {updateUpcomingStudentPlacement} from "../placements/studentPlacements/upcomingStudentPlacementsSlice"
7
- import { updateCompletedStudentPlacement } from "../placements/studentPlacements/completedStudentPlacementsSlice"
8
-
9
- export function useAnalyticsCard({user}: {user: UserData}){
10
- const [total, setTotal] = useState<number>();
11
- const [completed, setCompleted] = useState<number>();
12
- const [_, setPlacementsWithoutAnalytics] = useState<{[key:string]: StudentPlacementData}>();
13
- const firebaseQuery = new FirebaseQuery();
14
-
15
- useEffect(() => {
16
- if (!user) return
17
- firebaseQuery.getCount("placements", [where("uid", "==", user.id)]).then(setTotal);
18
- firebaseQuery.getCount("placements", [where("uid", "==", user.id), where("completed", "==", true)]).then(setCompleted);
19
- firebaseQuery.getDocsWhere("placements", [where("uid", "==", user.id)]).then((placements) => setPlacementsWithoutAnalytics(placements as {[key:string]: StudentPlacementData}));
20
- }, [user]);
21
-
22
-
23
- return ({...{total, completed}})
24
- }
25
-
26
- export function useAnalyticsViews(user: UserData | null){
27
- const [placementsWithoutAnalytics, setPlacementsWithoutAnalytics] = useState<{[key:string]: StudentPlacementData}>();
28
- const firebaseQuery = new FirebaseQuery();
29
-
30
- useEffect(() => {
31
- if (!user) return
32
- firebaseQuery.getDocsWhere("placements", [where("uid", "==", user.id)]).then((placements) => {
33
- const p = Object.fromEntries(Object.entries(placements as {[key:string]: StudentPlacementData}).filter(([k, v]) => (!v.units || !v.personalAnalytics)))
34
- setPlacementsWithoutAnalytics(p)
35
- });
36
- }, [user]);
37
-
38
- return ({...{placementsWithoutAnalytics}})
39
-
40
- }
41
-
42
- export function useReviewPlacementItem(id: string, onComplete: () => void){
43
- const [analytics, setAnalytics] = useState<{units: string|undefined, personalAnalytics: string[]|undefined}>();
44
- const dispatch = useAppDispatch()
45
-
46
- const submitPlacementData = async (type: "upcoming" | "completed") => {
47
- if (!analytics?.units || !analytics.personalAnalytics?.[0]?.length) return;
48
- console.log("PLACEMENTTTT", id);
49
- // await firebaseQuery.update(["placements", id], analytics);
50
- type === "upcoming" ? dispatch(updateUpcomingStudentPlacement({placementId: id, attributes: analytics})) : dispatch(updateCompletedStudentPlacement({placementId: id, attributes: analytics}))
51
- onComplete()
52
- }
53
-
54
- return ({...{analytics, setAnalytics, submitPlacementData}})
55
-
1
+ import {useState, useEffect} from "react"
2
+ import FirebaseQuery from "../../firebase/firebaseQuery"
3
+ import {where} from "firebase/firestore"
4
+ import {StudentPlacementData, UserData} from "../../typeDefinitions"
5
+ import {useAppDispatch} from "../../reduxHooks"
6
+ import {updateUpcomingStudentPlacement} from "../placements/studentPlacements/upcomingStudentPlacementsSlice"
7
+ import { updateCompletedStudentPlacement } from "../placements/studentPlacements/completedStudentPlacementsSlice"
8
+
9
+ export function useAnalyticsCard({user}: {user: UserData}){
10
+ const [total, setTotal] = useState<number>();
11
+ const [completed, setCompleted] = useState<number>();
12
+ const [_, setPlacementsWithoutAnalytics] = useState<{[key:string]: StudentPlacementData}>();
13
+ const firebaseQuery = new FirebaseQuery();
14
+
15
+ useEffect(() => {
16
+ if (!user) return
17
+ firebaseQuery.getCount("placements", [where("uid", "==", user.id)]).then(setTotal);
18
+ firebaseQuery.getCount("placements", [where("uid", "==", user.id), where("completed", "==", true)]).then(setCompleted);
19
+ firebaseQuery.getDocsWhere("placements", [where("uid", "==", user.id)]).then((placements) => setPlacementsWithoutAnalytics(placements as {[key:string]: StudentPlacementData}));
20
+ }, [user]);
21
+
22
+
23
+ return ({...{total, completed}})
24
+ }
25
+
26
+ export function useAnalyticsViews(user: UserData | null){
27
+ const [placementsWithoutAnalytics, setPlacementsWithoutAnalytics] = useState<{[key:string]: StudentPlacementData}>();
28
+ const firebaseQuery = new FirebaseQuery();
29
+
30
+ useEffect(() => {
31
+ if (!user) return
32
+ firebaseQuery.getDocsWhere("placements", [where("uid", "==", user.id)]).then((placements) => {
33
+ const p = Object.fromEntries(Object.entries(placements as {[key:string]: StudentPlacementData}).filter(([k, v]) => (!v.units || !v.personalAnalytics)))
34
+ setPlacementsWithoutAnalytics(p)
35
+ });
36
+ }, [user]);
37
+
38
+ return ({...{placementsWithoutAnalytics}})
39
+
40
+ }
41
+
42
+ export function useReviewPlacementItem(id: string, onComplete: () => void){
43
+ const [analytics, setAnalytics] = useState<{units: string|undefined, personalAnalytics: string[]|undefined}>();
44
+ const dispatch = useAppDispatch()
45
+
46
+ const submitPlacementData = async (type: "upcoming" | "completed") => {
47
+ if (!analytics?.units || !analytics.personalAnalytics?.[0]?.length) return;
48
+ console.log("PLACEMENTTTT", id);
49
+ // await firebaseQuery.update(["placements", id], analytics);
50
+ type === "upcoming" ? dispatch(updateUpcomingStudentPlacement({placementId: id, attributes: analytics})) : dispatch(updateCompletedStudentPlacement({placementId: id, attributes: analytics}))
51
+ onComplete()
52
+ }
53
+
54
+ return ({...{analytics, setAnalytics, submitPlacementData}})
55
+
56
56
  }
@@ -1,148 +1,148 @@
1
- import {createSlice, createAsyncThunk} from "@reduxjs/toolkit";
2
- import {Contact} from "../../typeDefinitions";
3
- import FirebaseQuery from "../../firebase/firebaseQuery";
4
- import {DocumentData, QueryConstraint, QueryDocumentSnapshot, QuerySnapshot} from "firebase/firestore";
5
-
6
- type InitialContactState = {
7
- status: string;
8
- lastContact: QueryDocumentSnapshot<DocumentData> | undefined;
9
- values: {
10
- [key: string]: {
11
- [key: string]: unknown;
12
- };
13
- };
14
- };
15
-
16
-
17
- const initialState: InitialContactState = {
18
- status: "",
19
- lastContact: undefined,
20
- values: {},
21
- };
22
-
23
- export const fetchContacts = createAsyncThunk(
24
- "contacts/fetchContacts",
25
- async ({ formattedConstraints }: {formattedConstraints?: QueryConstraint | QueryConstraint[] }, { rejectWithValue}) => {
26
- const firebaseQuery = new FirebaseQuery();
27
- try {
28
- const documents = await firebaseQuery.getDocsWhere("contacts", formattedConstraints, true) as QuerySnapshot<DocumentData>;
29
- return documents
30
-
31
- } catch (error) {
32
- return rejectWithValue(error);
33
- }
34
- }
35
- );
36
-
37
-
38
- export const addContact = createAsyncThunk(
39
- "contacts/addContact",
40
- async ({ contactForm, userId }: { contactForm: Contact; userId: string }, { rejectWithValue }) => {
41
- const firebaseQuery = new FirebaseQuery();
42
- try {
43
- await firebaseQuery.add(["contacts"], {...contactForm, uid: userId})
44
- return contactForm
45
-
46
- } catch (error) {
47
- return rejectWithValue(error);
48
- }
49
- }
50
- );
51
-
52
-
53
- export const updateContact = createAsyncThunk(
54
- "contacts/updateContact",
55
- async ({contactId, attributes }: { contactId: string, attributes: any }, { rejectWithValue }) => {
56
- const firebaseQuery = new FirebaseQuery();
57
- try {
58
- await firebaseQuery.update(["contacts", contactId], attributes);
59
- return {contactId, attributes}
60
-
61
- } catch (error) {
62
- return rejectWithValue(error);
63
- }
64
- }
65
- );
66
-
67
- export const deleteContact = createAsyncThunk(
68
- "contacts/deleteContact",
69
- async ({ contactId }: { contactId: string }, { rejectWithValue }) => {
70
- const firebaseQuery = new FirebaseQuery();
71
- try {
72
- await firebaseQuery.delete(["contacts", contactId])
73
- return contactId
74
-
75
- } catch (error) {
76
- return rejectWithValue(error);
77
- }
78
- }
79
- );
80
-
81
-
82
-
83
-
84
- export const contactsSlice = createSlice({
85
- name: "contacts",
86
- initialState,
87
-
88
- reducers: {
89
- setContacts: (state, action) => {
90
- state.values = action.payload
91
- },
92
-
93
- addContacts: (state, action) => {
94
- state.values = {...state.values, ...action.payload}
95
- },
96
-
97
- setLastContact: (state, action) => {
98
- state.lastContact = action.payload
99
- }
100
- },
101
-
102
-
103
- extraReducers(builder){
104
- builder
105
- .addCase(fetchContacts.pending, (state) => {
106
- state.status = "loading"
107
- })
108
-
109
- .addCase(fetchContacts.fulfilled, (state, action) => {
110
- state.status = "success";
111
- const newContacts = Object.fromEntries(
112
- action.payload.docs.map(doc => [doc.id, { ...doc.data(), docPath: doc.ref }])
113
- );
114
- return {
115
- ...state,
116
- values: {
117
- ...state.values,
118
- ...newContacts
119
- },
120
- lastContact: action.payload.docs[action.payload.docs.length - 1]
121
- };
122
- })
123
- .addCase(fetchContacts.rejected, (state) => {
124
- state.status = "rejected"
125
- })
126
-
127
- .addCase(addContact.fulfilled, (state, action) => {
128
- const newContact = action.payload
129
- const newContacts = {...state.values}
130
- newContacts[action.payload.id] = newContact
131
- })
132
-
133
- .addCase(updateContact.fulfilled, (state, action) => {
134
- state.values[action.payload.contactId] = { ...state.values[action.payload.contactId], ...action.payload.attributes };
135
- })
136
-
137
- .addCase(deleteContact.fulfilled, (state, action) => {
138
- const contactIdToDelete = action.payload;
139
- const newContacts = { ...state, values: { ...state.values } };
140
- delete newContacts.values[contactIdToDelete];
141
- return newContacts;
142
- })
143
- }
144
- })
145
-
146
- export const {setContacts, setLastContact, addContacts} = contactsSlice.actions;
147
-
1
+ import {createSlice, createAsyncThunk} from "@reduxjs/toolkit";
2
+ import {Contact} from "../../typeDefinitions";
3
+ import FirebaseQuery from "../../firebase/firebaseQuery";
4
+ import {DocumentData, QueryConstraint, QueryDocumentSnapshot, QuerySnapshot} from "firebase/firestore";
5
+
6
+ type InitialContactState = {
7
+ status: string;
8
+ lastContact: QueryDocumentSnapshot<DocumentData> | undefined;
9
+ values: {
10
+ [key: string]: {
11
+ [key: string]: unknown;
12
+ };
13
+ };
14
+ };
15
+
16
+
17
+ const initialState: InitialContactState = {
18
+ status: "",
19
+ lastContact: undefined,
20
+ values: {},
21
+ };
22
+
23
+ export const fetchContacts = createAsyncThunk(
24
+ "contacts/fetchContacts",
25
+ async ({ formattedConstraints }: {formattedConstraints?: QueryConstraint | QueryConstraint[] }, { rejectWithValue}) => {
26
+ const firebaseQuery = new FirebaseQuery();
27
+ try {
28
+ const documents = await firebaseQuery.getDocsWhere("contacts", formattedConstraints, true) as QuerySnapshot<DocumentData>;
29
+ return documents
30
+
31
+ } catch (error) {
32
+ return rejectWithValue(error);
33
+ }
34
+ }
35
+ );
36
+
37
+
38
+ export const addContact = createAsyncThunk(
39
+ "contacts/addContact",
40
+ async ({ contactForm, userId }: { contactForm: Contact; userId: string }, { rejectWithValue }) => {
41
+ const firebaseQuery = new FirebaseQuery();
42
+ try {
43
+ await firebaseQuery.add(["contacts"], {...contactForm, uid: userId})
44
+ return contactForm
45
+
46
+ } catch (error) {
47
+ return rejectWithValue(error);
48
+ }
49
+ }
50
+ );
51
+
52
+
53
+ export const updateContact = createAsyncThunk(
54
+ "contacts/updateContact",
55
+ async ({contactId, attributes }: { contactId: string, attributes: any }, { rejectWithValue }) => {
56
+ const firebaseQuery = new FirebaseQuery();
57
+ try {
58
+ await firebaseQuery.update(["contacts", contactId], attributes);
59
+ return {contactId, attributes}
60
+
61
+ } catch (error) {
62
+ return rejectWithValue(error);
63
+ }
64
+ }
65
+ );
66
+
67
+ export const deleteContact = createAsyncThunk(
68
+ "contacts/deleteContact",
69
+ async ({ contactId }: { contactId: string }, { rejectWithValue }) => {
70
+ const firebaseQuery = new FirebaseQuery();
71
+ try {
72
+ await firebaseQuery.delete(["contacts", contactId])
73
+ return contactId
74
+
75
+ } catch (error) {
76
+ return rejectWithValue(error);
77
+ }
78
+ }
79
+ );
80
+
81
+
82
+
83
+
84
+ export const contactsSlice = createSlice({
85
+ name: "contacts",
86
+ initialState,
87
+
88
+ reducers: {
89
+ setContacts: (state, action) => {
90
+ state.values = action.payload
91
+ },
92
+
93
+ addContacts: (state, action) => {
94
+ state.values = {...state.values, ...action.payload}
95
+ },
96
+
97
+ setLastContact: (state, action) => {
98
+ state.lastContact = action.payload
99
+ }
100
+ },
101
+
102
+
103
+ extraReducers(builder){
104
+ builder
105
+ .addCase(fetchContacts.pending, (state) => {
106
+ state.status = "loading"
107
+ })
108
+
109
+ .addCase(fetchContacts.fulfilled, (state, action) => {
110
+ state.status = "success";
111
+ const newContacts = Object.fromEntries(
112
+ action.payload.docs.map(doc => [doc.id, { ...doc.data(), docPath: doc.ref }])
113
+ );
114
+ return {
115
+ ...state,
116
+ values: {
117
+ ...state.values,
118
+ ...newContacts
119
+ },
120
+ lastContact: action.payload.docs[action.payload.docs.length - 1]
121
+ };
122
+ })
123
+ .addCase(fetchContacts.rejected, (state) => {
124
+ state.status = "rejected"
125
+ })
126
+
127
+ .addCase(addContact.fulfilled, (state, action) => {
128
+ const newContact = action.payload
129
+ const newContacts = {...state.values}
130
+ newContacts[action.payload.id] = newContact
131
+ })
132
+
133
+ .addCase(updateContact.fulfilled, (state, action) => {
134
+ state.values[action.payload.contactId] = { ...state.values[action.payload.contactId], ...action.payload.attributes };
135
+ })
136
+
137
+ .addCase(deleteContact.fulfilled, (state, action) => {
138
+ const contactIdToDelete = action.payload;
139
+ const newContacts = { ...state, values: { ...state.values } };
140
+ delete newContacts.values[contactIdToDelete];
141
+ return newContacts;
142
+ })
143
+ }
144
+ })
145
+
146
+ export const {setContacts, setLastContact, addContacts} = contactsSlice.actions;
147
+
148
148
  export default contactsSlice.reducer;
@@ -1,73 +1,73 @@
1
- import {where} from "firebase/firestore";
2
- import {useLazyLoadQueryList} from "../../hooks";
3
- import { useAppDispatch } from "../../reduxHooks";
4
- import { Contact, UserData } from "../../typeDefinitions";
5
- import { addContact, deleteContact, updateContact } from "./contactsSlice";
6
-
7
- export function useContacts({user}: {user: UserData}){
8
- const dispatch = useAppDispatch()
9
- const {items, loadMore, loadMoreIcon, reset} = useLazyLoadQueryList({path: "contacts", constraints: where("uid", "==", user?.id), number: 5});
10
-
11
- // const contacts = user?.product === "institutes" && user.userType === "Students" ?
12
- // useInstituteStudentSelector((state) => state.contacts) :
13
- // user?.product === "students" ? useStudentSelector((state) => state.contacts) : undefined;
14
- // const [loadMoreIcon, setLoadMoreIcon] = useState<boolean>(false);
15
- // const firebaseQuery = new FirebaseQuery()
16
- // const dispatch = user?.product === "institutes" && user.userType === "Students" ?
17
- // useInstituteStudentDispatch() :
18
- // user?.product === "students" ? useStudentDispatch() : undefined;
19
-
20
- // if (!dispatch || !contacts) {
21
- // throw new Error("Cannot access featture.");
22
- // }
23
-
24
- // const reset = () => {
25
- // dispatch(setContacts({}))
26
- // dispatch(setLastContact(undefined));
27
- // };
28
-
29
- // const loadMore = async () => {
30
- // setLoadMoreIcon(true);
31
- // let formattedConstraints:QueryConstraint[] = [];
32
-
33
- // if (constraints) {
34
- // formattedConstraints = (Array.isArray(constraints) ? [...constraints, limit(number)] : [constraints, limit(number)]);
35
- // }
36
- // if (contacts.lastContact) {
37
- // formattedConstraints.push(startAfter(contacts.lastContact));
38
- // }
39
- // const documents = await firebaseQuery.getDocsWhere("contacts", formattedConstraints, true) as QuerySnapshot<DocumentData>;
40
- // const lastContact = documents.docs[documents.docs.length - 1];
41
- // dispatch(setLastContact(lastContact))
42
- // console.log("docs", Object.entries(documents.docs))
43
- // dispatch(setContacts({
44
- // ...contacts,
45
- // ...Object.fromEntries(
46
- // documents.docs.map(doc => [doc.id, {...doc.data(), docPath: doc.ref}])
47
- // )
48
- // }));
49
-
50
- // setLoadMoreIcon(false);
51
- // };
52
-
53
- // useEffect(() => {
54
- // loadMore();
55
- // }, []);
56
-
57
- const addContactForm = async (contactForm: Contact) => {
58
- if (!user?.id) return
59
- dispatch(addContact({contactForm: contactForm, userId: user.id}))
60
- }
61
-
62
- const updateContactForm = async (contactId: string, attributes: any) => {
63
- dispatch(updateContact({contactId: contactId, attributes: attributes}))
64
- };
65
-
66
- const deleteContactForm = async (contactId: string) => {
67
- dispatch(deleteContact({contactId: contactId}))
68
- }
69
-
70
-
71
- return ({...{updateContactForm, addContactForm, deleteContactForm, contacts: items, loadMore, loadMoreIcon, reset}});
72
-
73
- };
1
+ import {where} from "firebase/firestore";
2
+ import {useLazyLoadQueryList} from "../../hooks";
3
+ import { useAppDispatch } from "../../reduxHooks";
4
+ import { Contact, UserData } from "../../typeDefinitions";
5
+ import { addContact, deleteContact, updateContact } from "./contactsSlice";
6
+
7
+ export function useContacts({user}: {user: UserData}){
8
+ const dispatch = useAppDispatch()
9
+ const {items, loadMore, loadMoreIcon, reset} = useLazyLoadQueryList({path: "contacts", constraints: where("uid", "==", user?.id), number: 5});
10
+
11
+ // const contacts = user?.product === "institutes" && user.userType === "Students" ?
12
+ // useInstituteStudentSelector((state) => state.contacts) :
13
+ // user?.product === "students" ? useStudentSelector((state) => state.contacts) : undefined;
14
+ // const [loadMoreIcon, setLoadMoreIcon] = useState<boolean>(false);
15
+ // const firebaseQuery = new FirebaseQuery()
16
+ // const dispatch = user?.product === "institutes" && user.userType === "Students" ?
17
+ // useInstituteStudentDispatch() :
18
+ // user?.product === "students" ? useStudentDispatch() : undefined;
19
+
20
+ // if (!dispatch || !contacts) {
21
+ // throw new Error("Cannot access featture.");
22
+ // }
23
+
24
+ // const reset = () => {
25
+ // dispatch(setContacts({}))
26
+ // dispatch(setLastContact(undefined));
27
+ // };
28
+
29
+ // const loadMore = async () => {
30
+ // setLoadMoreIcon(true);
31
+ // let formattedConstraints:QueryConstraint[] = [];
32
+
33
+ // if (constraints) {
34
+ // formattedConstraints = (Array.isArray(constraints) ? [...constraints, limit(number)] : [constraints, limit(number)]);
35
+ // }
36
+ // if (contacts.lastContact) {
37
+ // formattedConstraints.push(startAfter(contacts.lastContact));
38
+ // }
39
+ // const documents = await firebaseQuery.getDocsWhere("contacts", formattedConstraints, true) as QuerySnapshot<DocumentData>;
40
+ // const lastContact = documents.docs[documents.docs.length - 1];
41
+ // dispatch(setLastContact(lastContact))
42
+ // console.log("docs", Object.entries(documents.docs))
43
+ // dispatch(setContacts({
44
+ // ...contacts,
45
+ // ...Object.fromEntries(
46
+ // documents.docs.map(doc => [doc.id, {...doc.data(), docPath: doc.ref}])
47
+ // )
48
+ // }));
49
+
50
+ // setLoadMoreIcon(false);
51
+ // };
52
+
53
+ // useEffect(() => {
54
+ // loadMore();
55
+ // }, []);
56
+
57
+ const addContactForm = async (contactForm: Contact) => {
58
+ if (!user?.id) return
59
+ dispatch(addContact({contactForm: contactForm, userId: user.id}))
60
+ }
61
+
62
+ const updateContactForm = async (contactId: string, attributes: any) => {
63
+ dispatch(updateContact({contactId: contactId, attributes: attributes}))
64
+ };
65
+
66
+ const deleteContactForm = async (contactId: string) => {
67
+ dispatch(deleteContact({contactId: contactId}))
68
+ }
69
+
70
+
71
+ return ({...{updateContactForm, addContactForm, deleteContactForm, contacts: items, loadMore, loadMoreIcon, reset}});
72
+
73
+ };