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,53 +1,53 @@
1
- import {useState, useEffect} from "react"
2
- import FirebaseQuery from "../../firebase/firebaseQuery";
3
- import {countryList} from "../../constants";
4
-
5
-
6
- export interface DropdownProps {
7
- defaultValue?: string;
8
- required?: boolean;
9
- id?: string;
10
- disabled?: boolean,
11
- onValueChange?: (value: string) => void;
12
- value?: string;
13
- mode?: "default" | "modal"
14
- name?: string;
15
- search?: boolean | false
16
- data?: {key?: number, label: string, value: string}[]
17
- path?: string;
18
- label: string;
19
- size?: "small" | "medium" | "large";
20
- style?: any;
21
- errorText?: string;
22
- }
23
-
24
- export function useDropdown(props: DropdownProps){
25
- const [value, setValue] = useState<string>(
26
- props.defaultValue || props?.name === "country" ? countryList[0] : ""
27
- );
28
-
29
- const firebaseQuery = new FirebaseQuery();
30
-
31
- const [data, setData] = useState<{key?: number, label: string, value: string}[]|undefined>(props.data);
32
-
33
- useEffect(() => {
34
- // Get items from database if none are given as children.
35
- if (!props.path) {
36
- return;
37
- }
38
-
39
- firebaseQuery.getDocsWhere(props.path).then((collectionResult: any) => {
40
- const items = Object.keys(collectionResult).map((key) => {
41
- const item = collectionResult[key];
42
- return {
43
- label: item.name,
44
- value: key,
45
- };
46
- });
47
- setData(items);
48
- setValue(props.defaultValue || "");
49
- });
50
- }, []);
51
-
52
- return ({...{value, setValue, data, setData}})
1
+ import {useState, useEffect} from "react"
2
+ import FirebaseQuery from "../../firebase/firebaseQuery";
3
+ import {countryList} from "../../constants";
4
+
5
+
6
+ export interface DropdownProps {
7
+ defaultValue?: string;
8
+ required?: boolean;
9
+ id?: string;
10
+ disabled?: boolean,
11
+ onValueChange?: (value: string) => void;
12
+ value?: string;
13
+ mode?: "default" | "modal"
14
+ name?: string;
15
+ search?: boolean | false
16
+ data?: {key?: number, label: string, value: string}[]
17
+ path?: string;
18
+ label: string;
19
+ size?: "small" | "medium" | "large";
20
+ style?: any;
21
+ errorText?: string;
22
+ }
23
+
24
+ export function useDropdown(props: DropdownProps){
25
+ const [value, setValue] = useState<string>(
26
+ props.defaultValue || props?.name === "country" ? countryList[0] : ""
27
+ );
28
+
29
+ const firebaseQuery = new FirebaseQuery();
30
+
31
+ const [data, setData] = useState<{key?: number, label: string, value: string}[]|undefined>(props.data);
32
+
33
+ useEffect(() => {
34
+ // Get items from database if none are given as children.
35
+ if (!props.path) {
36
+ return;
37
+ }
38
+
39
+ firebaseQuery.getDocsWhere(props.path).then((collectionResult: any) => {
40
+ const items = Object.keys(collectionResult).map((key) => {
41
+ const item = collectionResult[key];
42
+ return {
43
+ label: item.name,
44
+ value: key,
45
+ };
46
+ });
47
+ setData(items);
48
+ setValue(props.defaultValue || "");
49
+ });
50
+ }, []);
51
+
52
+ return ({...{value, setValue, data, setData}})
53
53
  }
@@ -1,19 +1,20 @@
1
- import {where} from "firebase/firestore";
2
- import FirebaseQuery from "../../../firebase/firebaseQuery";
3
- import {useEffect, useState} from "react";
4
- import { UserData } from "../../../typeDefinitions";
5
-
6
- export function useDowntime({user}: {user: UserData}){
7
- const [downtime, setDowntime] = useState<{title: string, body: string}|false>();
8
- const firebaseQuery = new FirebaseQuery();
9
-
10
- useEffect(() => {
11
- firebaseQuery.getDocsWhere("downtime", [where("products", "array-contains", user?.product), where("active", "==", true)]).then((docs) => {
12
- const downtimeDocs = { ...docs as {[key: string]: {title: string, body: string}}};
13
- setDowntime(downtimeDocs[Object.keys(downtimeDocs)[0]] || false);
14
- })
15
- }, [user])
16
-
17
- return ({...{downtime, setDowntime}})
18
-
1
+ import {where} from "firebase/firestore";
2
+ import FirebaseQuery from "../../../firebase/firebaseQuery";
3
+ import {useEffect, useState} from "react";
4
+ import { UserData } from "../../../typeDefinitions";
5
+
6
+ export function useDowntime({user}: {user: UserData}){
7
+ const [downtime, setDowntime] = useState<{title: string, body: string}|false>();
8
+ const firebaseQuery = new FirebaseQuery();
9
+
10
+ useEffect(() => {
11
+ if (!user?.product) return;
12
+ firebaseQuery.getDocsWhere("downtime", [where("products", "array-contains", user?.product), where("active", "==", true)]).then((docs) => {
13
+ const downtimeDocs = { ...docs as {[key: string]: {title: string, body: string}}};
14
+ setDowntime(downtimeDocs[Object.keys(downtimeDocs)[0]] || false);
15
+ })
16
+ }, [user])
17
+
18
+ return ({...{downtime, setDowntime}})
19
+
19
20
  }
@@ -1,133 +1,133 @@
1
- import { useState, useEffect } from 'react'
2
- import { dateToString, convertDate } from '../../../firebase/util'
3
- import { executeCallable } from '../../../firebase/firebase'
4
- import { UserData, StudentPlacementData } from '../../../typeDefinitions'
5
- import { arrayUnion } from 'firebase/firestore'
6
- import FirebaseQuery from '../../../firebase/firebaseQuery'
7
-
8
- export function useUserFunctions({user}: {user: UserData}) {
9
- const firebaseQuery = new FirebaseQuery()
10
-
11
- const update = async (attributes: any) => {
12
- if (!user) return
13
- firebaseQuery.update(["users", user.id], {attributes})
14
- // dispatch(updateUser({userId: user.id, attributes: attributes}))
15
- }
16
-
17
- return ({...{update}});
18
- }
19
-
20
- export function useActivationCode({user}: {user: UserData}){
21
- const [code, setCode] = useState<string>("");
22
- const [newCodeSent, setNewCodeSent] = useState<boolean|undefined>(false);
23
- const [timer, setTimer] = useState<number>(30);
24
- const firebaseQuery = new FirebaseQuery()
25
-
26
- useEffect(() => {
27
- setInterval(() => {
28
- setTimer((t) => t > 0 ? t-1 : t);
29
- }, 1000)
30
- }, [])
31
-
32
- const submitCode = async (skip?: boolean) => {
33
- if (!user) return;
34
-
35
- if (skip || (parseInt(code) === user.activationCode)) {
36
- firebaseQuery.update(["users", user.id], {activated: dateToString(new Date()), status: "active"})
37
- //dispatch(updateUser({userId: user.id, attributes: {activated: dateToString(new Date()), status: "active"}}))
38
- }
39
- }
40
-
41
- const resendCode = async () => {
42
- setNewCodeSent(undefined)
43
- await executeCallable("registration-resendCode", {});
44
- setNewCodeSent(true);
45
- setTimer(30)
46
- }
47
-
48
- return ({...{code, setCode, submitCode, resendCode, newCodeSent, timer}})
49
-
50
- }
51
-
52
- export function useContactProviderConsent({user}: {user: UserData}){
53
- const [active, setActive] = useState<boolean>(false);
54
- const firebaseQuery = new FirebaseQuery()
55
-
56
- const consent = async (consent: boolean) => {
57
- if (!user) return
58
-
59
- try {
60
- await firebaseQuery.update(["users", user.id], {
61
- contactProviderConsent: consent,
62
- contactProviderConsenDate: (new Date()).toISOString()
63
- })
64
- // dispatch(updateUser({userId: user.id, attributes: {
65
- // contactProviderConsent: consent,
66
- // contactProviderConsentDate: (new Date()).toISOString()}
67
- // }))
68
-
69
- setActive(false);
70
- }
71
-
72
- catch(error) {
73
- console.log(error)
74
- }
75
- }
76
- return ({...{active, setActive, consent}})
77
-
78
- }
79
-
80
-
81
- export function useGuidance({user}: {user: UserData}){
82
- const firebaseQuery = new FirebaseQuery()
83
-
84
- const updateUserTutorials = () => {
85
- if (!user) return
86
- try {
87
- firebaseQuery.update(["users", user.id], {dismissedTutorials: arrayUnion("studentIntro")});
88
- // dispatch(updateUser({userId: user.id, attributes: {dismissedTutorials: arrayUnion("studentIntro")}}))
89
- }
90
-
91
- catch (error) {
92
- console.log(error)
93
- }
94
- }
95
-
96
- return ({...{updateUserTutorials}})
97
- }
98
-
99
- export function useStudents(user: UserData | null){
100
- const firebaseQuery = new FirebaseQuery()
101
-
102
- useEffect(() => {
103
- if (!user?.id) return;
104
- firebaseQuery.update(["users", user?.id], {lastAccessed: convertDate(new Date(), "dbstring")})
105
- //dispatch(updateUser({userId: user.id, attributes: {lastAccessed: convertDate(new Date(), "dbstring")}}))
106
-
107
- if (!user?.phone && user?.status === "inactive") {
108
- firebaseQuery.update(["users", user.id], {status: "active"})
109
- // dispatch(updateUser({userId: user.id, attributes: {status: "active"}}))
110
- };
111
- }, []);
112
-
113
-
114
- }
115
-
116
- export function useStudentData(placement: StudentPlacementData, student: UserData){
117
- const firebaseQuery = new FirebaseQuery();
118
- const [studentData, setStudentData] = useState<UserData | undefined>();
119
-
120
-
121
- useEffect(() => {
122
- const getStudentData = async () => {
123
- return student ? student : (await firebaseQuery.getDocData(["users", placement.uid])) as UserData;
124
- };
125
- getStudentData().then((data) => {
126
- setStudentData(data);
127
- });
128
- }, []);
129
-
130
-
131
- return ({...{studentData}})
132
-
1
+ import { useState, useEffect } from 'react'
2
+ import { dateToString, convertDate } from '../../../firebase/util'
3
+ import { executeCallable } from '../../../firebase/firebase'
4
+ import { UserData, StudentPlacementData } from '../../../typeDefinitions'
5
+ import { arrayUnion } from 'firebase/firestore'
6
+ import FirebaseQuery from '../../../firebase/firebaseQuery'
7
+
8
+ export function useUserFunctions({user}: {user: UserData}) {
9
+ const firebaseQuery = new FirebaseQuery()
10
+
11
+ const update = async (attributes: any) => {
12
+ if (!user) return
13
+ firebaseQuery.update(["users", user.id], {attributes})
14
+ // dispatch(updateUser({userId: user.id, attributes: attributes}))
15
+ }
16
+
17
+ return ({...{update}});
18
+ }
19
+
20
+ export function useActivationCode({user}: {user: UserData}){
21
+ const [code, setCode] = useState<string>("");
22
+ const [newCodeSent, setNewCodeSent] = useState<boolean|undefined>(false);
23
+ const [timer, setTimer] = useState<number>(30);
24
+ const firebaseQuery = new FirebaseQuery()
25
+
26
+ useEffect(() => {
27
+ setInterval(() => {
28
+ setTimer((t) => t > 0 ? t-1 : t);
29
+ }, 1000)
30
+ }, [])
31
+
32
+ const submitCode = async (skip?: boolean) => {
33
+ if (!user) return;
34
+
35
+ if (skip || (parseInt(code) === user.activationCode)) {
36
+ firebaseQuery.update(["users", user.id], {activated: dateToString(new Date()), status: "active"})
37
+ //dispatch(updateUser({userId: user.id, attributes: {activated: dateToString(new Date()), status: "active"}}))
38
+ }
39
+ }
40
+
41
+ const resendCode = async () => {
42
+ setNewCodeSent(undefined)
43
+ await executeCallable("registration-resendCode", {});
44
+ setNewCodeSent(true);
45
+ setTimer(30)
46
+ }
47
+
48
+ return ({...{code, setCode, submitCode, resendCode, newCodeSent, timer}})
49
+
50
+ }
51
+
52
+ export function useContactProviderConsent({user}: {user: UserData}){
53
+ const [active, setActive] = useState<boolean>(false);
54
+ const firebaseQuery = new FirebaseQuery()
55
+
56
+ const consent = async (consent: boolean) => {
57
+ if (!user) return
58
+
59
+ try {
60
+ await firebaseQuery.update(["users", user.id], {
61
+ contactProviderConsent: consent,
62
+ contactProviderConsenDate: (new Date()).toISOString()
63
+ })
64
+ // dispatch(updateUser({userId: user.id, attributes: {
65
+ // contactProviderConsent: consent,
66
+ // contactProviderConsentDate: (new Date()).toISOString()}
67
+ // }))
68
+
69
+ setActive(false);
70
+ }
71
+
72
+ catch(error) {
73
+ console.log(error)
74
+ }
75
+ }
76
+ return ({...{active, setActive, consent}})
77
+
78
+ }
79
+
80
+
81
+ export function useGuidance({user}: {user: UserData}){
82
+ const firebaseQuery = new FirebaseQuery()
83
+
84
+ const updateUserTutorials = () => {
85
+ if (!user) return
86
+ try {
87
+ firebaseQuery.update(["users", user.id], {dismissedTutorials: arrayUnion("studentIntro")});
88
+ // dispatch(updateUser({userId: user.id, attributes: {dismissedTutorials: arrayUnion("studentIntro")}}))
89
+ }
90
+
91
+ catch (error) {
92
+ console.log(error)
93
+ }
94
+ }
95
+
96
+ return ({...{updateUserTutorials}})
97
+ }
98
+
99
+ export function useStudents(user: UserData | null){
100
+ const firebaseQuery = new FirebaseQuery()
101
+
102
+ useEffect(() => {
103
+ if (!user?.id) return;
104
+ firebaseQuery.update(["users", user?.id], {lastAccessed: convertDate(new Date(), "dbstring")})
105
+ //dispatch(updateUser({userId: user.id, attributes: {lastAccessed: convertDate(new Date(), "dbstring")}}))
106
+
107
+ if (!user?.phone && user?.status === "inactive") {
108
+ firebaseQuery.update(["users", user.id], {status: "active"})
109
+ // dispatch(updateUser({userId: user.id, attributes: {status: "active"}}))
110
+ };
111
+ }, []);
112
+
113
+
114
+ }
115
+
116
+ export function useStudentData(placement: StudentPlacementData, student: UserData){
117
+ const firebaseQuery = new FirebaseQuery();
118
+ const [studentData, setStudentData] = useState<UserData | undefined>();
119
+
120
+
121
+ useEffect(() => {
122
+ const getStudentData = async () => {
123
+ return student ? student : (await firebaseQuery.getDocData(["users", placement.uid])) as UserData;
124
+ };
125
+ getStudentData().then((data) => {
126
+ setStudentData(data);
127
+ });
128
+ }, []);
129
+
130
+
131
+ return ({...{studentData}})
132
+
133
133
  }
@@ -1,66 +1,66 @@
1
- import {createSlice} from "@reduxjs/toolkit";
2
-
3
- export type Job = {
4
- id: string
5
- description: string
6
- finished: string
7
- logs: Array<string>
8
- oId: string
9
- outputMsg: string
10
- product: string
11
- started: string
12
- status: string
13
- title: string
14
- updated: string
15
- viewedBy: Array<string>
16
- };
17
-
18
-
19
- type InitialJobState = {
20
- values: {
21
- [jobId: string]: Job
22
- }
23
- }
24
-
25
- const initialState: InitialJobState = {
26
- values: {},
27
- };
28
-
29
-
30
- export const JobsSlice = createSlice({
31
- name: "jobs",
32
- initialState,
33
-
34
- reducers: {
35
- setJobs: (state, action) => {
36
- state.values = action.payload;
37
- },
38
-
39
- addJob: (state, action) => {
40
- const {job, jobId} = action.payload;
41
- console.log("j", job);
42
-
43
- const newJobs = {...state.values};
44
- newJobs[jobId] = job;
45
-
46
- state.values = Object.fromEntries(Object.entries(newJobs).sort(([, a], [, b]) => b.started > a.started ? 1 : -1));
47
- },
48
-
49
- setMarkRead: (state, action) => {
50
- console.log("Mark read", action.payload.data);
51
- state.values[action.payload.jobId].viewedBy.push(action.payload.userId);
52
- },
53
-
54
- setJobStatus: (state, action) => {
55
- state.values[action.payload.jobId].status = action.payload.status;
56
- state.values[action.payload.jobId].updated = (new Date()).toISOString();
57
- },
58
-
59
-
60
- },
61
-
62
- });
63
-
64
- export const {setJobs, addJob, setMarkRead, setJobStatus} = JobsSlice.actions;
65
-
1
+ import {createSlice} from "@reduxjs/toolkit";
2
+
3
+ export type Job = {
4
+ id: string
5
+ description: string
6
+ finished: string
7
+ logs: Array<string>
8
+ oId: string
9
+ outputMsg: string
10
+ product: string
11
+ started: string
12
+ status: string
13
+ title: string
14
+ updated: string
15
+ viewedBy: Array<string>
16
+ };
17
+
18
+
19
+ type InitialJobState = {
20
+ values: {
21
+ [jobId: string]: Job
22
+ }
23
+ }
24
+
25
+ const initialState: InitialJobState = {
26
+ values: {},
27
+ };
28
+
29
+
30
+ export const JobsSlice = createSlice({
31
+ name: "jobs",
32
+ initialState,
33
+
34
+ reducers: {
35
+ setJobs: (state, action) => {
36
+ state.values = action.payload;
37
+ },
38
+
39
+ addJob: (state, action) => {
40
+ const {job, jobId} = action.payload;
41
+ console.log("j", job);
42
+
43
+ const newJobs = {...state.values};
44
+ newJobs[jobId] = job;
45
+
46
+ state.values = Object.fromEntries(Object.entries(newJobs).sort(([, a], [, b]) => b.started > a.started ? 1 : -1));
47
+ },
48
+
49
+ setMarkRead: (state, action) => {
50
+ console.log("Mark read", action.payload.data);
51
+ state.values[action.payload.jobId].viewedBy.push(action.payload.userId);
52
+ },
53
+
54
+ setJobStatus: (state, action) => {
55
+ state.values[action.payload.jobId].status = action.payload.status;
56
+ state.values[action.payload.jobId].updated = (new Date()).toISOString();
57
+ },
58
+
59
+
60
+ },
61
+
62
+ });
63
+
64
+ export const {setJobs, addJob, setMarkRead, setJobStatus} = JobsSlice.actions;
65
+
66
66
  export default JobsSlice.reducer;
@@ -1,64 +1,64 @@
1
- import {createSlice, createAsyncThunk} from "@reduxjs/toolkit";
2
- import FirebaseQuery from "../../../firebase/firebaseQuery";
3
- import { StudentPlacementData } from "../../../typeDefinitions"
4
- import { orderBy, where } from "firebase/firestore";
5
-
6
- type InitialActivePlacementSlice = {
7
- status: string
8
- values: StudentPlacementData | undefined
9
- }
10
-
11
- const initialState: InitialActivePlacementSlice = {
12
- status: "",
13
- values: undefined,
14
- }
15
-
16
- export const fetchActivePlacement = createAsyncThunk(
17
- "studentPlacements/fetchActivePlacement",
18
- async ({userId}: {userId: string}) => {
19
- const firebaseQuery = new FirebaseQuery();
20
- try {
21
- const docs = await firebaseQuery.getDocsWhere(["placements"], [where("active", "==", true), where("uid", "==", userId), where("completed", "==", false), orderBy("endDate")]);
22
- const d = { ...docs as { [key: string]: StudentPlacementData } };
23
- return d[Object.keys(d)[0]] || undefined;
24
-
25
- } catch (error) {
26
- console.log(error)
27
- return undefined
28
- }
29
- }
30
- )
31
-
32
- export const activePlacementSlice = createSlice({
33
- name: "activePlacement",
34
- initialState,
35
-
36
- reducers: {
37
- setActivePlacement: (state, action) => {
38
- state.values = action.payload
39
- }
40
- },
41
-
42
- extraReducers(builder) {
43
- builder
44
- .addCase(fetchActivePlacement.fulfilled, (state, action) => {
45
- state.values = action.payload
46
- state.status = "success"
47
- })
48
-
49
- .addCase(fetchActivePlacement.pending, (state) => {
50
- state.status = "loading"
51
- })
52
-
53
- .addCase(fetchActivePlacement.rejected, (state) => {
54
- state.status = "error"
55
- })
56
-
57
- },
58
-
59
- })
60
-
61
-
62
- export const {setActivePlacement} = activePlacementSlice.actions
63
-
1
+ import {createSlice, createAsyncThunk} from "@reduxjs/toolkit";
2
+ import FirebaseQuery from "../../../firebase/firebaseQuery";
3
+ import { StudentPlacementData } from "../../../typeDefinitions"
4
+ import { where } from "firebase/firestore";
5
+
6
+ type InitialActivePlacementSlice = {
7
+ status: string
8
+ values: StudentPlacementData | undefined
9
+ }
10
+
11
+ const initialState: InitialActivePlacementSlice = {
12
+ status: "",
13
+ values: undefined,
14
+ }
15
+
16
+ export const fetchActivePlacement = createAsyncThunk(
17
+ "studentPlacements/fetchActivePlacement",
18
+ async ({userId}: {userId: string}) => {
19
+ const firebaseQuery = new FirebaseQuery();
20
+ try {
21
+ const docs = await firebaseQuery.getDocsWhere(["placements"], [where("active", "==", true), where("uid", "==", userId)]);
22
+ const d = { ...docs as { [key: string]: StudentPlacementData } };
23
+ return d[Object.keys(d)[0]] || undefined;
24
+
25
+ } catch (error) {
26
+ console.log(error)
27
+ return undefined
28
+ }
29
+ }
30
+ )
31
+
32
+ export const activePlacementSlice = createSlice({
33
+ name: "activePlacement",
34
+ initialState,
35
+
36
+ reducers: {
37
+ setActivePlacement: (state, action) => {
38
+ state.values = action.payload
39
+ }
40
+ },
41
+
42
+ extraReducers(builder) {
43
+ builder
44
+ .addCase(fetchActivePlacement.fulfilled, (state, action) => {
45
+ state.values = action.payload
46
+ state.status = "success"
47
+ })
48
+
49
+ .addCase(fetchActivePlacement.pending, (state) => {
50
+ state.status = "loading"
51
+ })
52
+
53
+ .addCase(fetchActivePlacement.rejected, (state) => {
54
+ state.status = "error"
55
+ })
56
+
57
+ },
58
+
59
+ })
60
+
61
+
62
+ export const {setActivePlacement} = activePlacementSlice.actions
63
+
64
64
  export default activePlacementSlice.reducer;