1
1
import PropTypes from 'prop-types' ;
2
- import { Box , Flex , Text , Grid , Button , Spacer } from '@chakra-ui/react' ;
2
+ import { Box , Flex , Text , Grid , Button , Spacer , Badge , VStack } from '@chakra-ui/react' ;
3
3
import { useState } from 'react' ;
4
4
import { NPOBackend } from '../../utils/auth_utils.js' ;
5
5
import AUTH_ROLES from '../../utils/auth_config.js' ;
6
6
import { useAuthContext } from '../../common/AuthContext.jsx' ;
7
7
const { USER_ROLE } = AUTH_ROLES . AUTH_ROLES ;
8
8
9
- const DailyEvent = ( { id, startTime, endTime, eventTitle, confirmed, description } ) => {
9
+ const DailyEvent = ( { id, startTime, endTime, eventTitle, confirmed, description, eventId } ) => {
10
10
const [ confirmEvent , setConfirmEvent ] = useState ( confirmed ) ;
11
+ const [ cohort , setCohort ] = useState ( undefined ) ;
12
+ const [ cohortBadgeColor , setCohortBadgeColor ] = useState ( undefined ) ;
13
+ const [ cohortTextColor , setCohortTextColor ] = useState ( undefined ) ;
14
+ const [ cohortBorderColor , setCohortBorderColor ] = useState ( undefined ) ;
15
+ const [ cohortBorder , setCohortBorder ] = useState ( undefined ) ;
11
16
const { currentUser} = useAuthContext ( ) ;
12
17
13
18
let border_color = '#2B93D1' ;
@@ -17,6 +22,42 @@ const DailyEvent = ({ id, startTime, endTime, eventTitle, confirmed, description
17
22
background_color = '#FEF1DC' ;
18
23
}
19
24
25
+ const getCohort = async ( ) => {
26
+ if ( eventId ) {
27
+ try {
28
+ const { data } = await NPOBackend . get ( `/catalog/${ eventId } ` ) ;
29
+ let year = data [ 0 ] . year ;
30
+ if ( year . length == 2 )
31
+ {
32
+ setCohort ( 'Both' ) ;
33
+ setCohortBadgeColor ( "#FFFFFF" ) ;
34
+ setCohortTextColor ( "#4A5568" ) ;
35
+ setCohortBorderColor ( "#4A5568" ) ;
36
+ setCohortBorder ( "outline" ) ;
37
+ }
38
+ else if ( year [ 0 ] == 'junior' )
39
+ {
40
+ setCohort ( 'Junior' ) ;
41
+ setCohortBadgeColor ( "#CBD5E0" ) ;
42
+ setCohortTextColor ( "#171923" ) ;
43
+ setCohortBorderColor ( "#CBD5E0" ) ;
44
+ setCohortBorder ( "simple" ) ;
45
+ }
46
+ else {
47
+ setCohort ( 'Senior' ) ;
48
+ setCohortBadgeColor ( "#4A5568" ) ;
49
+ setCohortTextColor ( "#FFFFFF" ) ;
50
+ setCohortBorderColor ( "#4A5568" ) ;
51
+ setCohortBorder ( "simple" ) ;
52
+ }
53
+ } catch ( error ) {
54
+ console . error ( 'Error fetching data:' , error ) ;
55
+ }
56
+ }
57
+ }
58
+
59
+ getCohort ( ) ;
60
+
20
61
const handleConfirm = async ( ) => {
21
62
const date = new Date ( ) ;
22
63
try {
@@ -54,17 +95,43 @@ const DailyEvent = ({ id, startTime, endTime, eventTitle, confirmed, description
54
95
55
96
< Spacer />
56
97
98
+ < VStack align = "flex-end" >
99
+ < Badge
100
+ key = { eventId }
101
+ variant = { cohortBorder }
102
+ backgroundColor = { cohortBadgeColor }
103
+ color = { cohortTextColor }
104
+ textTransform = "capitalize"
105
+ borderRadius = "10rem"
106
+ borderColor = { cohortBorderColor }
107
+ fontWeight = "normal"
108
+ px = "0.5rem"
109
+ mr = "0.125rem"
110
+ >
111
+ { cohort }
112
+ </ Badge >
113
+
57
114
{ ! confirmEvent && (
58
- < Box w = "15vh " alignItems = "top" >
115
+ < Box w = "4rem " alignItems = "top" >
59
116
< Grid gap = { 2 } >
60
117
< div > </ div >
61
118
< div > </ div >
62
- < Button bg = "#FBD38D" textColor = "#2D3748" size = "sm" onClick = { handleConfirm } visibility = { currentUser . type == USER_ROLE ? 'hidden' : 'visible' } >
119
+ < Button
120
+ variant = "outline"
121
+ bg = "#FEF1DC"
122
+ textColor = "#F69052"
123
+ borderColor = "#F69052"
124
+ _hover = { { bg : "#F6AD55" , color : "#2D3748" } }
125
+ size = "xs"
126
+ onClick = { handleConfirm }
127
+ visibility = { currentUser . type == USER_ROLE ? 'hidden' : 'visible' }
128
+ >
63
129
Confirm
64
130
</ Button >
65
- </ Grid >
66
- </ Box >
131
+ </ Grid >
132
+ </ Box >
67
133
) }
134
+ </ VStack >
68
135
</ Flex >
69
136
</ Box >
70
137
) ;
@@ -77,6 +144,7 @@ DailyEvent.propTypes = {
77
144
eventTitle : PropTypes . string . isRequired ,
78
145
description : PropTypes . string ,
79
146
confirmed : PropTypes . bool . isRequired ,
147
+ eventId : PropTypes . number . isRequired ,
80
148
} ;
81
149
82
150
export default DailyEvent ;
0 commit comments