@vixoniccom/aniversarios 1.2.0-dev.1 → 1.2.1-dev.0
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/CHANGELOG.md +10 -0
- package/build.zip +0 -0
- package/configuration.json +4 -0
- package/package.json +3 -4
- package/src/App.tsx +59 -73
- package/src/components/AnniversaryItem/components/AnniversaryDate/CircleDate/index.tsx +31 -0
- package/src/components/AnniversaryItem/components/AnniversaryDate/FlatDate/index.tsx +47 -0
- package/src/components/{anniversary-item/shared/anniversary-date/outline/OutlineDate.tsx → AnniversaryItem/components/AnniversaryDate/OutlineDate/index.tsx} +7 -25
- package/src/components/{anniversary-item/shared/anniversary-date/text-calendar/TextCalendarDate.tsx → AnniversaryItem/components/AnniversaryDate/TextCalendarDate/index.tsx} +7 -16
- package/src/components/{anniversary-item/shared/anniversary-date/text/TextDate.tsx → AnniversaryItem/components/AnniversaryDate/TextDate/index.tsx} +2 -12
- package/src/components/{anniversary-item/shared/anniversary-date/AnniversaryDate.tsx → AnniversaryItem/components/AnniversaryDate/index.tsx} +7 -11
- package/src/components/AnniversaryItem/components/AnniversaryDate/utils.ts +18 -0
- package/src/components/{anniversary-item/shared/AnniversaryImage.tsx → AnniversaryItem/components/AnniversaryImage/index.tsx} +11 -19
- package/src/components/AnniversaryItem/components/ClassicItem/index.tsx +109 -0
- package/src/components/{anniversary-item/shared/separator → AnniversaryItem/components/Separator}/Separator.tsx +3 -6
- package/src/components/AnniversaryItem/components/index.ts +11 -0
- package/src/components/AnniversaryItem/components/utils.ts +75 -0
- package/src/components/AnniversaryItem/index.tsx +17 -0
- package/src/components/{FontLoader.tsx → FontLoader/index.tsx} +11 -12
- package/src/components/FormattedText/index.tsx +81 -0
- package/src/components/{items-container → ItemsContainer/components}/Item.tsx +2 -10
- package/src/components/ItemsContainer/components/animation.ts +130 -0
- package/src/components/{items-container/ItemsContainer.tsx → ItemsContainer/index.tsx} +52 -61
- package/src/components/{Render.tsx → Render/index.tsx} +9 -11
- package/src/components/index.ts +13 -0
- package/src/context/configureContext/ConfigureContext.tsx +8 -0
- package/src/context/configureContext/ConfigureProvider.tsx +72 -0
- package/src/context/configureContext/configureReducer.ts +62 -0
- package/src/context/dataContext/DataContex.tsx +8 -0
- package/src/context/dataContext/DataProvider.tsx +25 -0
- package/src/context/dataContext/dataReducer.ts +12 -0
- package/src/helpers/filterEmployees.ts +31 -37
- package/src/helpers/getEmployees.ts +18 -22
- package/src/helpers/utils.ts +44 -50
- package/src/main.tsx +2 -2
- package/src/test/parameters.json +97 -97
- package/src/components/FormattedText.tsx +0 -81
- package/src/components/anniversary-item/AnniversaryItem.tsx +0 -22
- package/src/components/anniversary-item/clasic/ClasicItem.tsx +0 -220
- package/src/components/anniversary-item/shared/anniversary-date/DateUtils.ts +0 -33
- package/src/components/anniversary-item/shared/anniversary-date/circle/CircleDate.tsx +0 -39
- package/src/components/anniversary-item/shared/anniversary-date/flat/FlatDate.tsx +0 -79
- package/src/components/anniversary-item/shared/utils.ts +0 -10
- package/src/components/items-container/animation.ts +0 -125
- package/src/contex/configureContext/ConfigureContext.tsx +0 -8
- package/src/contex/configureContext/ConfigureProvider.tsx +0 -77
- package/src/contex/configureContext/configureReducer.ts +0 -67
- package/src/contex/dataContext/DataContex.tsx +0 -8
- package/src/contex/dataContext/DataProvider.tsx +0 -31
- package/src/contex/dataContext/dataReducer.ts +0 -19
- package/src/helpers/parseMonthAndDay.ts +0 -38
- package/src/helpers/setToken.ts +0 -69
- package/src/hooks/useFetch.ts +0 -47
- package/src/model/income.ts +0 -129
- /package/src/components/{anniversary-item/shared → AnniversaryItem/components}/default-profile.png +0 -0
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import React, { useContext, useState, useRef, useEffect } from 'react'
|
|
2
|
-
import { Item } from './Item'
|
|
3
|
-
import { ConfigureContext } from '../../
|
|
4
|
-
import { useStateWithCallbackLazy } from 'use-state-with-callback'
|
|
5
|
-
import { ReactElementLike } from 'prop-types'
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { Item } from './components/Item'
|
|
3
|
+
import { ConfigureContext } from '../../context/configureContext/ConfigureContext'
|
|
4
|
+
import { useStateWithCallbackLazy } from 'use-state-with-callback'
|
|
5
|
+
import { ReactElementLike } from 'prop-types'
|
|
8
6
|
|
|
9
7
|
const stages = {
|
|
10
8
|
idle: 'idle',
|
|
@@ -12,8 +10,6 @@ const stages = {
|
|
|
12
10
|
animating: 'animating'
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
13
|
interface Props {
|
|
18
14
|
items: ReactElementLike[],
|
|
19
15
|
animation: Animation,
|
|
@@ -21,20 +17,17 @@ interface Props {
|
|
|
21
17
|
}
|
|
22
18
|
|
|
23
19
|
interface Animation {
|
|
24
|
-
mode
|
|
25
|
-
duration
|
|
26
|
-
speed
|
|
27
|
-
reverse
|
|
20
|
+
mode?: string
|
|
21
|
+
duration?: number,
|
|
22
|
+
speed?: number,
|
|
23
|
+
reverse?: boolean
|
|
28
24
|
}
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
32
26
|
export const ItemsContainer = ({ animation, items, animate }: Props) => {
|
|
33
|
-
|
|
34
27
|
const { configureState } = useContext(ConfigureContext)
|
|
35
28
|
const { containerColumns, containerRows, containerRowsGap, containerColumnsGap } = configureState.parameters
|
|
36
29
|
const container = useRef<HTMLDivElement>(null)
|
|
37
|
-
const [animations] = useState(new (require('./animation'))())
|
|
30
|
+
const [animations] = useState(new (require('./components/animation'))())
|
|
38
31
|
let itemsCount = Number(containerColumns) * Number(containerRows)
|
|
39
32
|
let columns = Number(containerColumns) || 1
|
|
40
33
|
let rows = Number(containerRows) || 1
|
|
@@ -46,17 +39,6 @@ export const ItemsContainer = ({ animation, items, animate }: Props) => {
|
|
|
46
39
|
const [stage, setStage] = useStateWithCallbackLazy('idle')
|
|
47
40
|
const [lastIndex, setLastIndex] = useState(0)
|
|
48
41
|
|
|
49
|
-
const configure = () => {
|
|
50
|
-
animations.configure(animation)
|
|
51
|
-
itemsCount = Number(containerColumns) * Number(containerRows)
|
|
52
|
-
columns = Number(containerColumns) || 1
|
|
53
|
-
rows = Number(containerRows) || 1
|
|
54
|
-
rowsGap = Number(containerRowsGap) || 0
|
|
55
|
-
columnsGap = Number(containerColumnsGap) || 1
|
|
56
|
-
|
|
57
|
-
if (animate && stage === stages.idle) createItems(lastIndex, items)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
42
|
useEffect(() => {
|
|
61
43
|
configure()
|
|
62
44
|
}, [animation])
|
|
@@ -73,40 +55,53 @@ export const ItemsContainer = ({ animation, items, animate }: Props) => {
|
|
|
73
55
|
}
|
|
74
56
|
}, [item, animate])
|
|
75
57
|
|
|
58
|
+
const configure = () => {
|
|
59
|
+
animations.configure(animation)
|
|
60
|
+
itemsCount = Number(containerColumns) * Number(containerRows)
|
|
61
|
+
columns = Number(containerColumns) || 1
|
|
62
|
+
rows = Number(containerRows) || 1
|
|
63
|
+
rowsGap = Number(containerRowsGap) || 0
|
|
64
|
+
columnsGap = Number(containerColumnsGap) || 1
|
|
65
|
+
|
|
66
|
+
if (animate && stage === stages.idle) createItems(lastIndex, items)
|
|
67
|
+
}
|
|
76
68
|
|
|
77
69
|
const createItems = (lastIndex: number, items: any) => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
if (items.length === 0) {
|
|
71
|
+
setShow(false)
|
|
72
|
+
setStage(stages.idle, () => { })
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let currentIndex = lastIndex % items.length
|
|
77
|
+
const newItems: any = []
|
|
78
|
+
|
|
79
|
+
for (let i = 0; i < Math.min(itemsCount, items.length); i++) {
|
|
80
|
+
const itemIndex = (currentIndex + i) % items.length
|
|
81
|
+
const item = items[itemIndex]
|
|
82
|
+
|
|
83
|
+
newItems.push(
|
|
84
|
+
<Item
|
|
85
|
+
key={`item-${itemIndex}`}
|
|
86
|
+
containerData={{
|
|
87
|
+
ic_index: i,
|
|
88
|
+
ic_rowIndex: Math.floor(i / columns),
|
|
89
|
+
ic_columnIndex: i % columns,
|
|
90
|
+
ic_firstChild: i === 0,
|
|
91
|
+
ic_lastChild: i === (Math.min(itemsCount, items.length) - 1)
|
|
92
|
+
}}
|
|
93
|
+
style={animations.getInitialStyle()}
|
|
94
|
+
width={`${(100 - ((columnsGap * (columns - 1)))) / columns}%`}
|
|
95
|
+
height={`${(100 - ((rowsGap * (rows - 1)))) / rows}%`}
|
|
96
|
+
horizontalGap={columnsGap}
|
|
97
|
+
verticalGap={rowsGap}
|
|
98
|
+
>
|
|
99
|
+
{item}
|
|
100
|
+
</Item>
|
|
101
|
+
)
|
|
81
102
|
}
|
|
82
|
-
let newItems = items.filter((_item: any, index: number) => {
|
|
83
|
-
return index >= lastIndex
|
|
84
|
-
}).map((item: any, index: any, arr: any) => {
|
|
85
|
-
if (count >= itemsCount) return null
|
|
86
|
-
setLastIndex(++lastIndex)
|
|
87
|
-
count++
|
|
88
|
-
return <Item
|
|
89
|
-
key={lastIndex} containerData={{
|
|
90
|
-
ic_index: index,
|
|
91
|
-
ic_rowIndex: index / columns,
|
|
92
|
-
ic_columnIndex: index % columns,
|
|
93
|
-
ic_firstChild: index === 0,
|
|
94
|
-
ic_lastChild: index === (arr.length - 1)
|
|
95
|
-
}} style={animations.getInitialStyle()}
|
|
96
|
-
// Item alignment. By default is center - center.
|
|
97
|
-
// alignment={alignment}
|
|
98
|
-
// Setup item width based on columns count.
|
|
99
|
-
width={`${(100 - ((columnsGap * (columns - 1)))) / columns}%`}
|
|
100
|
-
// Setup item height based on rows count. If 0 set up on auto.
|
|
101
|
-
height={`${(100 - ((rowsGap * (rows - 1)))) / rows}%`}
|
|
102
|
-
// Setup horizontal gap
|
|
103
|
-
horizontalGap={columnsGap}
|
|
104
|
-
// Setup vertical gap
|
|
105
|
-
verticalGap={rowsGap}>
|
|
106
|
-
{item}
|
|
107
|
-
</Item>
|
|
108
|
-
})
|
|
109
103
|
|
|
104
|
+
setLastIndex((currentIndex + itemsCount) % items.length)
|
|
110
105
|
|
|
111
106
|
if (newItems.length > 0) {
|
|
112
107
|
setShow(true)
|
|
@@ -118,7 +113,6 @@ export const ItemsContainer = ({ animation, items, animate }: Props) => {
|
|
|
118
113
|
}
|
|
119
114
|
}
|
|
120
115
|
|
|
121
|
-
|
|
122
116
|
return (
|
|
123
117
|
<div ref={container} style={{
|
|
124
118
|
opacity: show ? 1 : 0,
|
|
@@ -133,6 +127,3 @@ export const ItemsContainer = ({ animation, items, animate }: Props) => {
|
|
|
133
127
|
</div>
|
|
134
128
|
)
|
|
135
129
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import React, { useContext } from 'react'
|
|
2
|
-
import { ConfigureContext } from '
|
|
3
|
-
import { DataContext } from '
|
|
4
|
-
import { FontLoader } from '
|
|
5
|
-
import { FormattedText } from '
|
|
6
|
-
import { AnniversaryItem } from '
|
|
7
|
-
import { ItemsContainer } from '
|
|
2
|
+
import { ConfigureContext } from '../../context/configureContext/ConfigureContext'
|
|
3
|
+
import { DataContext } from '../../context/dataContext/DataContex'
|
|
4
|
+
import { FontLoader } from '../FontLoader'
|
|
5
|
+
import { FormattedText } from '../FormattedText'
|
|
6
|
+
import { AnniversaryItem } from '../AnniversaryItem'
|
|
7
|
+
import { ItemsContainer } from '../ItemsContainer'
|
|
8
8
|
|
|
9
9
|
interface Props {
|
|
10
10
|
start: boolean
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export const Render = ({ start }: Props) => {
|
|
14
|
-
|
|
15
14
|
const { configureState } = useContext(ConfigureContext)
|
|
16
15
|
const { dataEmployee } = useContext(DataContext)
|
|
17
16
|
const { parameters, downloadsPath } = configureState
|
|
@@ -24,11 +23,10 @@ export const Render = ({ start }: Props) => {
|
|
|
24
23
|
animationTime,
|
|
25
24
|
} = parameters
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
? `url("${downloadsPath}/${backgroundImage.filename}")`
|
|
29
|
-
: ''
|
|
26
|
+
const backgroundImageState = backgroundImage && backgroundImage.filename
|
|
27
|
+
? `url("${downloadsPath}/${backgroundImage.filename}")` : ''
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
const anniversaryItems = dataEmployee.dataEmployee.map((anniversary: DataEmployee) => {
|
|
32
30
|
return <AnniversaryItem style={'standard'} anniversary={anniversary} />
|
|
33
31
|
})
|
|
34
32
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AnniversaryItem } from './AnniversaryItem';
|
|
2
|
+
import { FontLoader } from './FontLoader';
|
|
3
|
+
import { FormattedText } from './FormattedText';
|
|
4
|
+
import { ItemsContainer } from './ItemsContainer';
|
|
5
|
+
import { Render } from './Render';
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
AnniversaryItem,
|
|
9
|
+
FontLoader,
|
|
10
|
+
FormattedText,
|
|
11
|
+
ItemsContainer,
|
|
12
|
+
Render
|
|
13
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React, { useReducer } from "react"
|
|
2
|
+
import { ConfigureContext } from './ConfigureContext'
|
|
3
|
+
import { anniversaryReducer } from "./configureReducer"
|
|
4
|
+
|
|
5
|
+
const INITIAL_STATE: VixonicData = {
|
|
6
|
+
downloadsPath: '',
|
|
7
|
+
parameters: {
|
|
8
|
+
abbreviatedMonths: false,
|
|
9
|
+
animationMode: "",
|
|
10
|
+
animationOrder: false,
|
|
11
|
+
animationSpeed: 1.5,
|
|
12
|
+
animationTime: "",
|
|
13
|
+
backgroundImage: { id: "", filename: "", _isAsset: true },
|
|
14
|
+
apiDomain: "",
|
|
15
|
+
containerColumns: "",
|
|
16
|
+
containerRows: "",
|
|
17
|
+
containerRowsGap: "",
|
|
18
|
+
containerColumnsGap: "",
|
|
19
|
+
dataMode: "",
|
|
20
|
+
dateAlignment: "center",
|
|
21
|
+
dateDayFormat: { font: { filename: '', id: '', _isAsset: true }, fontSize: 55, alignment: { horizontal: "center" }, fontColor: "", },
|
|
22
|
+
dateEnabled: true,
|
|
23
|
+
dateMonthFormat: { font: { filename: '', id: '', _isAsset: true }, fontSize: 20, alignment: { horizontal: "center" }, fontColor: "" },
|
|
24
|
+
datePosition: 1,
|
|
25
|
+
datePrimaryColor: "",
|
|
26
|
+
dateStyle: "circle",
|
|
27
|
+
descriptionEnabled: true,
|
|
28
|
+
descriptionFormat: { font: { filename: '', id: '', _isAsset: true }, fontSize: 3.8, alignment: { horizontal: "center" }, fontColor: "" },
|
|
29
|
+
optionalEnabled: true,
|
|
30
|
+
optionalFormat: { font: { filename: '', id: '', _isAsset: true }, fontSize: 3.8, alignment: { horizontal: "center" }, fontColor: "" },
|
|
31
|
+
excludePast: false,
|
|
32
|
+
imageAlignment: "center",
|
|
33
|
+
imageEnabled: true,
|
|
34
|
+
imagePosition: 0,
|
|
35
|
+
imageStyle: "normal",
|
|
36
|
+
imageSize: 50,
|
|
37
|
+
itemMargins: "",
|
|
38
|
+
msj0: "",
|
|
39
|
+
nameFormat: { font: { filename: '', id: '', _isAsset: true }, fontSize: 3.8, alignment: { horizontal: "center" }, fontColor: "" },
|
|
40
|
+
orientation: "",
|
|
41
|
+
padding: "",
|
|
42
|
+
photosMode: "",
|
|
43
|
+
photosZip: { id: "0fb559ec-5da3-4b2d-95c4-d9623754c841", filename: "0fb559ec-5da3-4b2d-95c4-d9623754c841.zip", extension: "zip", _isAsset: true },
|
|
44
|
+
template: "",
|
|
45
|
+
textAlignment: "center",
|
|
46
|
+
textPosition: 0,
|
|
47
|
+
updateTime: 600000,
|
|
48
|
+
urlBaseApi: "",
|
|
49
|
+
imageMargin: "",
|
|
50
|
+
textMargin: "",
|
|
51
|
+
dateMargin: "",
|
|
52
|
+
separator: false
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface props {
|
|
57
|
+
children: JSX.Element | JSX.Element[]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const AnniversaryProvider = ({ children }: props) => {
|
|
61
|
+
const [configureState, dispatch] = useReducer(anniversaryReducer, INITIAL_STATE)
|
|
62
|
+
|
|
63
|
+
const addConfiguration = (configure: VixonicData) => {
|
|
64
|
+
dispatch({ type: "addConfigure", payload: configure })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<ConfigureContext.Provider value={{ configureState, addConfiguration }}>
|
|
69
|
+
{children}
|
|
70
|
+
</ConfigureContext.Provider>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
type ConfigureAction = { type: 'addConfigure', payload: VixonicData }
|
|
2
|
+
|
|
3
|
+
export const anniversaryReducer = (state: VixonicData, action: ConfigureAction) => {
|
|
4
|
+
const { downloadsPath, parameters } = action.payload
|
|
5
|
+
switch (action.type) {
|
|
6
|
+
case 'addConfigure':
|
|
7
|
+
return {
|
|
8
|
+
downloadsPath: downloadsPath,
|
|
9
|
+
parameters: {
|
|
10
|
+
abbreviatedMonths: parameters.abbreviatedMonths,
|
|
11
|
+
animationMode: parameters.animationMode,
|
|
12
|
+
animationOrder: parameters.animationOrder,
|
|
13
|
+
animationSpeed: parameters.animationSpeed,
|
|
14
|
+
animationTime: parameters.animationTime,
|
|
15
|
+
apiDomain: parameters.apiDomain,
|
|
16
|
+
backgroundImage: parameters.backgroundImage,
|
|
17
|
+
containerColumns: parameters.containerColumns,
|
|
18
|
+
containerColumnsGap: parameters.containerColumnsGap,
|
|
19
|
+
containerRows: parameters.containerRows,
|
|
20
|
+
containerRowsGap: parameters.containerRowsGap,
|
|
21
|
+
dataMode: parameters.dataMode,
|
|
22
|
+
dateAlignment: parameters.dateAlignment,
|
|
23
|
+
dateDayFormat: parameters.dateDayFormat,
|
|
24
|
+
dateEnabled: parameters.dateEnabled,
|
|
25
|
+
dateMonthFormat: parameters.dateMonthFormat,
|
|
26
|
+
datePosition: parameters.datePosition,
|
|
27
|
+
datePrimaryColor: parameters.datePrimaryColor,
|
|
28
|
+
dateStyle: parameters.dateStyle,
|
|
29
|
+
descriptionEnabled: parameters.descriptionEnabled,
|
|
30
|
+
descriptionFormat: parameters.descriptionFormat,
|
|
31
|
+
optionalEnabled: parameters.optionalEnabled,
|
|
32
|
+
optionalFormat: parameters.optionalFormat,
|
|
33
|
+
excludePast: parameters.excludePast,
|
|
34
|
+
imageAlignment: parameters.imageAlignment,
|
|
35
|
+
imageEnabled: parameters.imageEnabled,
|
|
36
|
+
imagePosition: parameters.imagePosition,
|
|
37
|
+
imageSize: parameters.imageSize,
|
|
38
|
+
imageStyle: parameters.imageStyle,
|
|
39
|
+
itemMargins: parameters.itemMargins,
|
|
40
|
+
msj0: parameters.msj0,
|
|
41
|
+
nameFormat: parameters.nameFormat,
|
|
42
|
+
orientation: parameters.orientation,
|
|
43
|
+
padding: parameters.padding,
|
|
44
|
+
photosMode: parameters.photosMode,
|
|
45
|
+
photosZip: parameters.photosZip,
|
|
46
|
+
template: parameters.template,
|
|
47
|
+
textAlignment: parameters.textAlignment,
|
|
48
|
+
textPosition: parameters.textPosition,
|
|
49
|
+
updateTime: parameters.updateTime,
|
|
50
|
+
urlBaseApi: parameters.urlBaseApi,
|
|
51
|
+
imageMargin: parameters.imageMargin,
|
|
52
|
+
textMargin: parameters.textMargin,
|
|
53
|
+
dateMargin: parameters.dateMargin,
|
|
54
|
+
separator: parameters.separator,
|
|
55
|
+
nameMaxChar: parameters.nameMaxChar,
|
|
56
|
+
descriptionMaxChar: parameters.descriptionMaxChar
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
default:
|
|
60
|
+
return state;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { useReducer } from 'react'
|
|
2
|
+
import { DataContext } from './DataContex'
|
|
3
|
+
import { dataReducer } from './dataReducer'
|
|
4
|
+
|
|
5
|
+
const INITIAL_STATE: Employees = {
|
|
6
|
+
dataEmployee: []
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface props {
|
|
10
|
+
children: JSX.Element | JSX.Element[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const DataProvider = ({ children }: props) => {
|
|
14
|
+
const [dataEmployee, dispatch] = useReducer(dataReducer, INITIAL_STATE)
|
|
15
|
+
|
|
16
|
+
const addEmployee = (employee: DataEmployee[]) => {
|
|
17
|
+
dispatch({ type: 'addAnniversary', payload: employee })
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<DataContext.Provider value={{ dataEmployee, addEmployee }}>
|
|
22
|
+
{children}
|
|
23
|
+
</DataContext.Provider>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type DataAction = { type: 'addAnniversary', payload: DataEmployee[] }
|
|
2
|
+
|
|
3
|
+
export const dataReducer = (state: Employees, action: DataAction): Employees => {
|
|
4
|
+
switch (action.type) {
|
|
5
|
+
case 'addAnniversary':
|
|
6
|
+
return {
|
|
7
|
+
dataEmployee: action.payload
|
|
8
|
+
}
|
|
9
|
+
default:
|
|
10
|
+
return state
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,44 +1,38 @@
|
|
|
1
|
-
import moment from "moment"
|
|
1
|
+
import moment from "moment"
|
|
2
2
|
|
|
3
3
|
export const filterEmployees = (values: any, dataMode: string = 'month', excludePast: boolean = false, month: number) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
optional: val[4],
|
|
19
|
-
month
|
|
20
|
-
};
|
|
21
|
-
})
|
|
22
|
-
.filter((val: any) => val !== undefined);
|
|
4
|
+
const today = moment()
|
|
5
|
+
const day = moment().format("D")
|
|
6
|
+
const numberMonth = Number(moment().format("M")) - 1
|
|
7
|
+
let employees = values.map((val: any, index: number) => {
|
|
8
|
+
if (index == 0) return
|
|
9
|
+
return {
|
|
10
|
+
day: Number(val[0]),
|
|
11
|
+
name: val[1],
|
|
12
|
+
position: val[2],
|
|
13
|
+
image: val[3],
|
|
14
|
+
optional: val[4],
|
|
15
|
+
month
|
|
16
|
+
}
|
|
17
|
+
}).filter((val: any) => val !== undefined)
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return bdayDate.isoWeek() === today.isoWeek()
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
employee.sort((a: any, b: any) => {
|
|
35
|
-
if (a.day < b.day) return -1
|
|
36
|
-
else if (a.day === b.day) return 0
|
|
37
|
-
else return 1
|
|
19
|
+
if (dataMode === "daily")
|
|
20
|
+
employees = employees.filter((contract: any) => contract.day == day)
|
|
21
|
+
if (dataMode === "weekly") {
|
|
22
|
+
employees = employees.filter((contract: any) => {
|
|
23
|
+
const bdayDate = moment([today.year(), contract.month, contract.day])
|
|
24
|
+
return bdayDate.isoWeek() === today.isoWeek()
|
|
38
25
|
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
employees.sort((a: any, b: any) => {
|
|
29
|
+
if (a.day < b.day) return -1
|
|
30
|
+
else if (a.day === b.day) return 0
|
|
31
|
+
else return 1
|
|
32
|
+
})
|
|
39
33
|
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
if (excludePast && (numberMonth >= month))
|
|
35
|
+
employees = employees.filter((contract: any) => (contract.day >= day && contract.month >= numberMonth))
|
|
42
36
|
|
|
43
|
-
|
|
37
|
+
return employees
|
|
44
38
|
}
|
|
@@ -1,33 +1,29 @@
|
|
|
1
|
-
import axios from "axios"
|
|
1
|
+
import axios from "axios"
|
|
2
|
+
import { getMonth } from "./utils"
|
|
3
|
+
|
|
2
4
|
const API_KEY = 'AIzaSyDQcTlxfd5IyjbeSJooRtNt6OF04DLykqc'
|
|
3
|
-
import { getMonth } from "./utils";
|
|
4
5
|
|
|
5
|
-
export const getEmployees = async(apiDomain: string,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export const getEmployees = async (apiDomain: string, monthTab: string) => {
|
|
7
|
+
const idGoogle = apiDomain.split("/")[5]
|
|
8
|
+
const URL = `https://sheets.googleapis.com/v4/spreadsheets/${idGoogle}/values`
|
|
8
9
|
try {
|
|
9
|
-
const response = await axios({
|
|
10
|
-
|
|
11
|
-
});
|
|
12
|
-
return response;
|
|
10
|
+
const response = await axios({ url: `${URL}/${monthTab}?key=${API_KEY}` })
|
|
11
|
+
return response
|
|
13
12
|
} catch (error) {
|
|
14
|
-
console.error(error)
|
|
15
|
-
return error
|
|
13
|
+
console.error(error)
|
|
14
|
+
return error
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
export const getEmployeesYearly = (apiDomain: string, numberMonth: number) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
export const getEmployeesYearly = async (apiDomain: string, numberMonth: number) => {
|
|
19
|
+
const idGoogle = apiDomain.split("/")[5]
|
|
20
|
+
const URL = `https://sheets.googleapis.com/v4/spreadsheets/${idGoogle}/values`
|
|
21
|
+
const monthTab = getMonth(numberMonth)
|
|
23
22
|
try {
|
|
24
|
-
const response = axios({
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
return response;
|
|
23
|
+
const response = await axios({ url: `${URL}/${monthTab}?key=${API_KEY}` })
|
|
24
|
+
return response
|
|
28
25
|
} catch (error) {
|
|
29
|
-
console.error(error)
|
|
30
|
-
return error
|
|
26
|
+
console.error(error)
|
|
27
|
+
return error
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
|
-
|
package/src/helpers/utils.ts
CHANGED
|
@@ -1,52 +1,46 @@
|
|
|
1
|
-
export const getMonth = (numberMonth:number) => {
|
|
1
|
+
export const getMonth = (numberMonth: number) => {
|
|
2
|
+
let month
|
|
3
|
+
switch (numberMonth) {
|
|
4
|
+
case 0:
|
|
5
|
+
month = 'Enero'
|
|
6
|
+
break
|
|
7
|
+
case 1:
|
|
8
|
+
month = 'Febrero'
|
|
9
|
+
break
|
|
10
|
+
case 2:
|
|
11
|
+
month = 'Marzo'
|
|
12
|
+
break
|
|
13
|
+
case 3:
|
|
14
|
+
month = 'Abril'
|
|
15
|
+
break
|
|
16
|
+
case 4:
|
|
17
|
+
month = 'Mayo'
|
|
18
|
+
break
|
|
19
|
+
case 5:
|
|
20
|
+
month = 'Junio'
|
|
21
|
+
break
|
|
22
|
+
case 6:
|
|
23
|
+
month = 'Julio'
|
|
24
|
+
break
|
|
25
|
+
case 7:
|
|
26
|
+
month = 'Agosto'
|
|
27
|
+
break
|
|
28
|
+
case 8:
|
|
29
|
+
month = 'Septiembre'
|
|
30
|
+
break
|
|
31
|
+
case 9:
|
|
32
|
+
month = 'Octubre'
|
|
33
|
+
break
|
|
34
|
+
case 10:
|
|
35
|
+
month = 'Noviembre'
|
|
36
|
+
break
|
|
37
|
+
case 11:
|
|
38
|
+
month = 'Diciembre'
|
|
39
|
+
break
|
|
40
|
+
default:
|
|
41
|
+
month = 'ENERO'
|
|
42
|
+
break
|
|
43
|
+
}
|
|
2
44
|
|
|
3
|
-
|
|
4
|
-
switch (numberMonth) {
|
|
5
|
-
case 0:
|
|
6
|
-
month = 'Enero'
|
|
7
|
-
break
|
|
8
|
-
case 1:
|
|
9
|
-
month = 'Febrero'
|
|
10
|
-
break
|
|
11
|
-
case 2:
|
|
12
|
-
month = 'Marzo'
|
|
13
|
-
break
|
|
14
|
-
case 3:
|
|
15
|
-
month = 'Abril'
|
|
16
|
-
break
|
|
17
|
-
case 4:
|
|
18
|
-
month = 'Mayo'
|
|
19
|
-
break
|
|
20
|
-
case 5:
|
|
21
|
-
month = 'Junio'
|
|
22
|
-
break
|
|
23
|
-
case 6:
|
|
24
|
-
month = 'Julio'
|
|
25
|
-
break
|
|
26
|
-
case 7:
|
|
27
|
-
month = 'Agosto'
|
|
28
|
-
break
|
|
29
|
-
case 8:
|
|
30
|
-
month = 'Septiembre'
|
|
31
|
-
break
|
|
32
|
-
case 9:
|
|
33
|
-
month = 'Octubre'
|
|
34
|
-
break
|
|
35
|
-
case 10:
|
|
36
|
-
month = 'Noviembre'
|
|
37
|
-
break
|
|
38
|
-
case 11:
|
|
39
|
-
month = 'Diciembre'
|
|
40
|
-
break
|
|
41
|
-
default:
|
|
42
|
-
month = 'ENERO'
|
|
43
|
-
break
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return month
|
|
45
|
+
return month
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
export const getNumberWeek = (day:string) =>{
|
|
50
|
-
const prefixes = [0,1,2,3,4,5]
|
|
51
|
-
return prefixes[0 | Number(day)/7]
|
|
52
|
-
}
|
package/src/main.tsx
CHANGED
|
@@ -2,8 +2,8 @@ import ReactDOM from 'react-dom'
|
|
|
2
2
|
import React from 'react'
|
|
3
3
|
const { ipcRenderer } = require('electron')
|
|
4
4
|
import { App } from './App';
|
|
5
|
-
import { AnniversaryProvider } from './
|
|
6
|
-
import { DataProvider } from './
|
|
5
|
+
import { AnniversaryProvider } from './context/configureContext/ConfigureProvider';
|
|
6
|
+
import { DataProvider } from './context/dataContext/DataProvider';
|
|
7
7
|
|
|
8
8
|
let start: boolean = false
|
|
9
9
|
|