1
+ import React , { useEffect , useState } from 'react' ;
2
+ import PropTypes from 'prop-types' ;
3
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
4
+ import { faAngleRight , faAngleLeft } from '@fortawesome/free-solid-svg-icons' ;
5
+
6
+ const ViewCalendar = ( { display, handleView } ) => {
7
+ const [ calendarDate , setCalendarDate ] = useState ( null ) ;
8
+ const [ currMonthCalendar , setCurrMonthCalendar ] = useState ( null ) ;
9
+ const [ currYearCalendar , setCurrYearCalendar ] = useState ( null ) ;
10
+ console . log ( calendarDate , currMonthCalendar , currYearCalendar )
11
+
12
+ useEffect ( ( ) => {
13
+ setCalendarDate ( new Date ( ) ) ;
14
+ setCurrMonthCalendar ( new Date ( ) . getMonth ( ) ) ;
15
+ setCurrYearCalendar ( new Date ( ) . getFullYear ( ) ) ;
16
+ } , [ display ] )
17
+
18
+ const handleCancel = ( ) => handleView ( ) ;
19
+
20
+ const renderCalendarMonthHeader = ( ) => {
21
+ const text = [
22
+ 'Январь' ,
23
+ 'Февраль' ,
24
+ 'Март' ,
25
+ 'Апрель' ,
26
+ 'Май' ,
27
+ 'Июнь' ,
28
+ 'Июль' ,
29
+ 'Август' ,
30
+ 'Сентябрь' ,
31
+ 'Октябрь' ,
32
+ 'Ноябрь' ,
33
+ 'Декабрь'
34
+ ] ;
35
+ return text [ currMonthCalendar ] + ' ' + currYearCalendar ;
36
+ }
37
+
38
+ const handleChangePage = ( e ) => {
39
+ const { currentTarget : target } = e ;
40
+ if ( target . getAttribute ( 'data-id' ) === 'nextButton' ) {
41
+ if ( currMonthCalendar === 11 ) {
42
+ setCurrMonthCalendar ( 0 ) ;
43
+ setCurrYearCalendar ( state => state + 1 ) ;
44
+ return false ;
45
+ }
46
+ setCurrMonthCalendar ( state => state + 1 ) ;
47
+ } else {
48
+ if ( currMonthCalendar === 0 ) {
49
+ setCurrMonthCalendar ( 11 ) ;
50
+ setCurrYearCalendar ( state => state - 1 ) ;
51
+ return false ;
52
+ }
53
+ setCurrMonthCalendar ( state => state - 1 ) ;
54
+ }
55
+
56
+ }
57
+
58
+ const renderCells = ( ) => {
59
+ return (
60
+ < tr >
61
+
62
+ </ tr >
63
+ )
64
+ }
65
+
66
+ return (
67
+ < >
68
+ { display && < div className = "micalendar"
69
+ style = { { display : 'block' , position : 'absolute' } } >
70
+ < div className = "header_wrap" >
71
+ < div className = "header" >
72
+ < p > { renderCalendarMonthHeader ( ) } </ p >
73
+ </ div >
74
+ < div class = "arrows" >
75
+ < div
76
+ data-id = "prevButton"
77
+ onClick = { handleChangePage }
78
+ className = "arrows_left" >
79
+ < FontAwesomeIcon icon = { faAngleLeft } />
80
+ </ div >
81
+ < div
82
+ data-id = "nextButton"
83
+ onClick = { handleChangePage }
84
+ className = "arrows_right" >
85
+ < FontAwesomeIcon icon = { faAngleRight } />
86
+ </ div >
87
+ </ div >
88
+ </ div >
89
+ < table >
90
+ < thead >
91
+ < tr >
92
+ < th > Пн</ th >
93
+ < th > Вт</ th >
94
+ < th > Ср</ th >
95
+ < th > Чт</ th >
96
+ < th > Пт</ th >
97
+ < th > Сб</ th >
98
+ < th > Вс</ th >
99
+ </ tr >
100
+ </ thead >
101
+ < tbody >
102
+ < tr > < td class = "not_current" > 30</ td > </ tr >
103
+ </ tbody >
104
+ </ table >
105
+ < hr />
106
+ < div className = "btn-group" >
107
+ < input
108
+ type = "button"
109
+ onClick = { handleCancel }
110
+ value = "Отмена"
111
+ className = "btn btn-sm btn-outline-secondary" />
112
+ </ div >
113
+ </ div >
114
+
115
+ }
116
+ </ >
117
+ ) ;
118
+ } ;
119
+
120
+ ViewCalendar . propTypes = {
121
+ display : PropTypes . bool ,
122
+ handleView : PropTypes . func
123
+ } ;
124
+
125
+ export default React . memo ( ViewCalendar ) ;
0 commit comments