placementt-core 1.20.211 → 11.10.151

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/.eslintrc.js +40 -40
  2. package/.gitattributes +2 -2
  3. package/lib/config.d.ts +0 -1
  4. package/lib/constants.d.ts +6 -2
  5. package/lib/constants.js +136 -136
  6. package/lib/constants.js.map +1 -1
  7. package/lib/features/analytics/useAnalytics.d.ts +0 -1
  8. package/lib/features/analytics/useAnalytics.js +3 -4
  9. package/lib/features/analytics/useAnalytics.js.map +1 -1
  10. package/lib/features/config.d.ts +133 -133
  11. package/lib/features/config.js +35 -35
  12. package/lib/features/contacts/contacts.d.ts +75 -75
  13. package/lib/features/contacts/contacts.js +105 -105
  14. package/lib/features/contacts/contactsSlice.d.ts +5 -5
  15. package/lib/features/contacts/useContacts.js +1 -2
  16. package/lib/features/contacts/useContacts.js.map +1 -1
  17. package/lib/features/downtime/useDowntime.d.ts +11 -11
  18. package/lib/features/downtime/useDowntime.js +22 -22
  19. package/lib/features/dropdown/useDropdown.d.ts +2 -3
  20. package/lib/features/dropdown/useDropdown.js +1 -2
  21. package/lib/features/dropdown/useDropdown.js.map +1 -1
  22. package/lib/features/global/downtime/useDowntime.d.ts +0 -1
  23. package/lib/features/global/downtime/useDowntime.js +1 -2
  24. package/lib/features/global/downtime/useDowntime.js.map +1 -1
  25. package/lib/features/global/users/useUserFunctions.d.ts +0 -1
  26. package/lib/features/global/users/useUserFunctions.js +7 -8
  27. package/lib/features/global/users/useUserFunctions.js.map +1 -1
  28. package/lib/features/placements/studentPlacements/activePlacement.d.ts +1 -1
  29. package/lib/features/placements/studentPlacements/completedStudentPlacementsSlice.d.ts +2 -2
  30. package/lib/features/placements/studentPlacements/studentPlacementsSlice.d.ts +63 -63
  31. package/lib/features/placements/studentPlacements/studentPlacementsSlice.js +81 -81
  32. package/lib/features/placements/studentPlacements/upcomingStudentPlacementsSlice.d.ts +2 -2
  33. package/lib/features/placements/studentPlacements/useStudentPlacements.d.ts +0 -1
  34. package/lib/features/placements/studentPlacements/useStudentPlacements.js +1 -2
  35. package/lib/features/placements/studentPlacements/useStudentPlacements.js.map +1 -1
  36. package/lib/features/providerPlacements/providerPlacementsSlice.d.ts +19 -19
  37. package/lib/features/providerPlacements/providerPlacementsSlice.js +24 -24
  38. package/lib/features/referrals/useReferrals.d.ts +0 -1
  39. package/lib/features/referrals/useReferrals.js +1 -2
  40. package/lib/features/referrals/useReferrals.js.map +1 -1
  41. package/lib/features/studentPlacements/studentPlacementsSlice.d.ts +62 -62
  42. package/lib/features/studentPlacements/studentPlacementsSlice.js +87 -87
  43. package/lib/features/studentPlacements/useStudentPlacements.d.ts +6 -6
  44. package/lib/features/studentPlacements/useStudentPlacements.js +18 -18
  45. package/lib/features/updates/useUpdates.js +1 -2
  46. package/lib/features/updates/useUpdates.js.map +1 -1
  47. package/lib/features/userSlice.d.ts +26 -26
  48. package/lib/features/userSlice.js +23 -23
  49. package/lib/features/users/useUserFunctions.d.ts +25 -25
  50. package/lib/features/users/useUserFunctions.js +124 -124
  51. package/lib/features/users/userSlice.d.ts +46 -46
  52. package/lib/features/users/userSlice.js +48 -48
  53. package/lib/firebase/firebase.d.ts +3 -1
  54. package/lib/firebase/firebase.js +9 -3
  55. package/lib/firebase/firebase.js.map +1 -1
  56. package/lib/firebase/firebaseConfig.js +3 -0
  57. package/lib/firebase/firebaseConfig.js.map +1 -1
  58. package/lib/firebase/firebaseQuery.d.ts +3 -1
  59. package/lib/firebase/firebaseQuery.js +11 -1
  60. package/lib/firebase/firebaseQuery.js.map +1 -1
  61. package/lib/firebase/persistence.js +2 -2
  62. package/lib/firebase/persistence.js.map +1 -1
  63. package/lib/firebase/readDatabase.d.ts +8 -7
  64. package/lib/firebase/readDatabase.js +41 -8
  65. package/lib/firebase/readDatabase.js.map +1 -1
  66. package/lib/firebase/util.d.ts +3 -4
  67. package/lib/firebase/util.js +49 -4
  68. package/lib/firebase/util.js.map +1 -1
  69. package/lib/firebase/writeDatabase.d.ts +7 -3
  70. package/lib/firebase/writeDatabase.js +9 -2
  71. package/lib/firebase/writeDatabase.js.map +1 -1
  72. package/lib/hooks.d.ts +476 -20
  73. package/lib/hooks.js +1855 -237
  74. package/lib/hooks.js.map +1 -1
  75. package/lib/images/GatsbyBenchmarks.d.ts +0 -1
  76. package/lib/images/GatsbyBenchmarks.js +1 -1
  77. package/lib/images/GatsbyBenchmarks.js.map +1 -1
  78. package/lib/reduxHooks.d.ts +9 -2
  79. package/lib/reduxHooks.js +36 -9
  80. package/lib/reduxHooks.js.map +1 -1
  81. package/lib/tasksAndTips.d.ts +25 -5
  82. package/lib/tasksAndTips.js +517 -48
  83. package/lib/tasksAndTips.js.map +1 -1
  84. package/lib/typeDefinitions.d.ts +472 -55
  85. package/lib/util.d.ts +1 -0
  86. package/lib/util.js +85 -7
  87. package/lib/util.js.map +1 -1
  88. package/package.json +52 -49
  89. package/src/DatabaseDefinitions.ts +18 -18
  90. package/src/apiCalls.ts +128 -128
  91. package/src/config.ts +50 -50
  92. package/src/constants.ts +714 -707
  93. package/src/databaseTypes.ts +42 -42
  94. package/src/features/analytics/useAnalytics.tsx +64 -64
  95. package/src/features/contacts/contactsSlice.ts +147 -147
  96. package/src/features/contacts/useContacts.tsx +73 -73
  97. package/src/features/dropdown/useDropdown.tsx +52 -52
  98. package/src/features/global/downtime/useDowntime.tsx +23 -23
  99. package/src/features/global/users/useUserFunctions.tsx +132 -132
  100. package/src/features/jobs/jobsSlice.ts +65 -65
  101. package/src/features/placements/studentPlacements/activePlacement.ts +68 -68
  102. package/src/features/placements/studentPlacements/completedStudentPlacementsSlice.ts +97 -97
  103. package/src/features/placements/studentPlacements/upcomingStudentPlacementsSlice.ts +108 -108
  104. package/src/features/placements/studentPlacements/useStudentPlacements.tsx +9 -9
  105. package/src/features/placements/types.ts +10 -10
  106. package/src/features/referrals/useReferrals.tsx +56 -56
  107. package/src/features/updates/useUpdates.tsx +38 -38
  108. package/src/firebase/firebase.tsx +144 -138
  109. package/src/firebase/firebaseConfig.tsx +45 -42
  110. package/src/firebase/firebaseQuery.tsx +150 -140
  111. package/src/firebase/persistence.ts +84 -84
  112. package/src/firebase/readDatabase.tsx +235 -197
  113. package/src/firebase/util.tsx +352 -308
  114. package/src/firebase/writeDatabase.tsx +77 -68
  115. package/src/hooks.tsx +4029 -1928
  116. package/src/images/GatsbyBenchmarks.tsx +711 -711
  117. package/src/images/LogFuturePlacement.jsx +64 -64
  118. package/src/images/LogPreviousPlacement.jsx +228 -228
  119. package/src/images/gatsby_benchmarks.svg +466 -466
  120. package/src/images/log_future_placement.svg +114 -114
  121. package/src/images/log_previous_placement.svg +199 -199
  122. package/src/index.ts +34 -34
  123. package/src/readDatabase.tsx +3 -3
  124. package/src/reduxHooks.ts +231 -200
  125. package/src/tasksAndTips.ts +917 -410
  126. package/src/tutorialTips.ts +58 -58
  127. package/src/typeDefinitions.ts +893 -503
  128. package/src/util.ts +137 -47
  129. package/tsconfig.dev.json +5 -5
  130. package/tsconfig.json +21 -21
@@ -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,24 +1,24 @@
1
- import {where} from "firebase/firestore";
2
- import FirebaseQuery from "../../../firebase/firebaseQuery";
3
- import {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
- const fetchDownTime = async () => {
11
- try {
12
- const docs = await firebaseQuery.getDocsWhere("downtime", [where("products", "array-contains", user?.product), where("active", "==", true)])
13
- const downtimeDocs = { ...docs as {[key: string]: {title: string, body: string}}};
14
- setDowntime(downtimeDocs[Object.keys(downtimeDocs)[0]] || false);
15
-
16
- } catch(error) {
17
- console.log(error)
18
- }
19
-
20
- }
21
-
22
- return ({...{downtime, setDowntime, fetchDownTime}})
23
-
1
+ import {where} from "firebase/firestore";
2
+ import FirebaseQuery from "../../../firebase/firebaseQuery";
3
+ import {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
+ const fetchDownTime = async () => {
11
+ try {
12
+ const docs = await firebaseQuery.getDocsWhere("downtime", [where("products", "array-contains", user?.product), where("active", "==", true)])
13
+ const downtimeDocs = { ...docs as {[key: string]: {title: string, body: string}}};
14
+ setDowntime(downtimeDocs[Object.keys(downtimeDocs)[0]] || false);
15
+
16
+ } catch(error) {
17
+ console.log(error)
18
+ }
19
+
20
+ }
21
+
22
+ return ({...{downtime, setDowntime, fetchDownTime}})
23
+
24
24
  }
@@ -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
+ contactProviderConsentDate: (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;