1
1
/** @jsxImportSource @emotion /react */
2
2
import React , { useMemo } from 'react' ;
3
+ import { SerializedStyles } from '@emotion/react' ;
3
4
import Paper from '@mui/material/Paper' ;
4
5
import Grid from '@mui/material/Grid' ;
5
6
import Typography from '@mui/material/Typography' ;
6
7
7
8
import { useTranslation } from 'translation' ;
8
- import { Icon } from '../Icon' ;
9
- import { ProgressBar } from '../ProgressBar' ;
9
+ import { Icon , IconName } from '../Icon' ;
10
+ import { Spinner } from '../Spinner' ;
11
+ import { ActiveVotingProgress } from './ActiveVotingProgress' ;
10
12
import { useStyles } from './styles' ;
11
13
12
- type ProposalStatus = 'active' | 'queued' | 'readyToExecute' | 'executed' | 'cancelled' ;
14
+ type ProposalCardStatus = 'queued' | 'readyToExecute' | 'executed' | 'cancelled' ;
15
+ type ProposalStatus = 'active' | ProposalCardStatus ;
13
16
14
17
interface IStatusCard {
15
- status : ProposalStatus ;
16
- votedFor ?: string ;
17
- votedAgainst ?: string ;
18
- abstain ?: string ;
18
+ status : ProposalCardStatus ;
19
19
}
20
20
21
- const StatusCard : React . FC < IStatusCard > = ( { status, votedFor , votedAgainst , abstain } ) => {
21
+ const StatusCard : React . FC < IStatusCard > = ( { status } ) => {
22
22
const styles = useStyles ( ) ;
23
23
const { t } = useTranslation ( ) ;
24
24
25
- switch ( status ) {
26
- case 'active' :
27
- return (
28
- < >
29
- < div css = { styles . voteRow } >
30
- < Typography variant = "small2" color = "textPrimary" >
31
- { t ( 'voteProposalUi.statusCard.for' ) }
32
- </ Typography >
33
-
34
- < Typography variant = "small2" color = "textPrimary" >
35
- { votedFor }
36
- </ Typography >
37
- </ div >
38
- < ProgressBar value = { 20 } step = { 1 } ariaLabel = "progress" min = { 1 } max = { 100 } />
39
-
40
- < div css = { styles . voteRow } >
41
- < Typography variant = "small2" color = "textPrimary" >
42
- { t ( 'voteProposalUi.statusCard.against' ) }
43
- </ Typography >
44
-
45
- < Typography variant = "small2" color = "textPrimary" >
46
- { votedAgainst }
47
- </ Typography >
48
- </ div >
49
- < ProgressBar value = { 20 } step = { 1 } ariaLabel = "progress" min = { 1 } max = { 100 } />
50
-
51
- < div css = { styles . voteRow } >
52
- < Typography variant = "small2" color = "textPrimary" >
53
- { t ( 'voteProposalUi.statusCard.abstain' ) }
54
- </ Typography >
25
+ const statusContent : Record <
26
+ ProposalCardStatus ,
27
+ {
28
+ iconWrapperCss : SerializedStyles | SerializedStyles [ ] ;
29
+ iconName : IconName ;
30
+ iconCss : SerializedStyles | SerializedStyles [ ] ;
31
+ label : string ;
32
+ }
33
+ > = useMemo (
34
+ ( ) => ( {
35
+ queued : {
36
+ iconWrapperCss : [ styles . iconWrapper , styles . iconDotsWrapper ] ,
37
+ iconName : 'dots' ,
38
+ iconCss : styles . icon ,
39
+ label : t ( 'voteProposalUi.statusCard.queued' ) ,
40
+ } ,
41
+ readyToExecute : {
42
+ iconWrapperCss : [ styles . iconWrapper , styles . iconInfoWrapper ] ,
43
+ iconName : 'exclamation' ,
44
+ iconCss : styles . icon ,
45
+ label : t ( 'voteProposalUi.statusCard.readyToExecute' ) ,
46
+ } ,
47
+ executed : {
48
+ iconWrapperCss : [ styles . iconWrapper , styles . iconMarkWrapper ] ,
49
+ iconName : 'mark' ,
50
+ iconCss : [ styles . icon , styles . iconCheck ] ,
51
+ label : t ( 'voteProposalUi.statusCard.executed' ) ,
52
+ } ,
53
+ cancelled : {
54
+ iconWrapperCss : [ styles . iconWrapper , styles . iconCloseWrapper ] ,
55
+ iconName : 'close' ,
56
+ iconCss : styles . icon ,
57
+ label : t ( 'voteProposalUi.statusCard.cancelled' ) ,
58
+ } ,
59
+ } ) ,
60
+ [ ] ,
61
+ ) ;
55
62
56
- < Typography variant = "small2" color = "textPrimary" >
57
- { abstain }
58
- </ Typography >
59
- </ div >
60
- < ProgressBar value = { 5 } step = { 1 } ariaLabel = "progress" min = { 1 } max = { 100 } />
61
- </ >
62
- ) ;
63
+ switch ( status ) {
63
64
case 'queued' :
64
- return (
65
- < >
66
- < div css = { [ styles . iconWrapper , styles . iconDotsWrapper ] } >
67
- < Icon css = { styles . icon } name = "dots" />
68
- </ div >
69
- < Typography css = { styles . statusText } variant = "body2" >
70
- { t ( 'voteProposalUi.statusCard.queued' ) }
71
- </ Typography >
72
- </ >
73
- ) ;
74
65
case 'readyToExecute' :
75
- return (
76
- < >
77
- < div css = { [ styles . iconWrapper , styles . iconInfoWrapper ] } >
78
- < Icon css = { styles . icon } name = "exclamation" />
79
- </ div >
80
- < Typography css = { styles . statusText } variant = "body2" >
81
- { t ( 'voteProposalUi.statusCard.readyToExecute' ) }
82
- </ Typography >
83
- </ >
84
- ) ;
85
66
case 'executed' :
86
- return (
87
- < >
88
- < div css = { [ styles . iconWrapper , styles . iconMarkWrapper ] } >
89
- < Icon css = { [ styles . icon , styles . iconCheck ] } name = "mark" />
90
- </ div >
91
- < Typography css = { styles . statusText } variant = "body2" >
92
- { t ( 'voteProposalUi.statusCard.executed' ) }
93
- </ Typography >
94
- </ >
95
- ) ;
96
- default :
97
67
case 'cancelled' :
98
68
return (
99
69
< >
100
- < div css = { [ styles . iconWrapper , styles . iconCloseWrapper ] } >
101
- < Icon css = { styles . icon } name = "close" />
70
+ < div css = { statusContent [ status ] . iconWrapperCss } >
71
+ < Icon css = { statusContent [ status ] . iconCss } name = { statusContent [ status ] . iconName } />
102
72
</ div >
103
73
< Typography css = { styles . statusText } variant = "body2" >
104
- { t ( 'voteProposalUi.statusCard.cancelled' ) }
74
+ { statusContent [ status ] . label }
105
75
</ Typography >
106
76
</ >
107
77
) ;
78
+ default :
79
+ return < Spinner variant = "small" /> ;
108
80
}
109
81
} ;
110
82
@@ -115,6 +87,7 @@ interface IVoteProposalUiProps {
115
87
proposalNumber : number ;
116
88
proposalText : string ;
117
89
proposalStatus : ProposalStatus ;
90
+ cancelDate ?: string ;
118
91
voteStatus ?: VoteStatus ;
119
92
votedFor ?: string ;
120
93
votedAgainst ?: string ;
@@ -126,6 +99,7 @@ export const VoteProposalUi: React.FC<IVoteProposalUiProps> = ({
126
99
proposalNumber,
127
100
proposalText,
128
101
proposalStatus,
102
+ cancelDate,
129
103
voteStatus,
130
104
votedFor,
131
105
votedAgainst,
@@ -179,25 +153,30 @@ export const VoteProposalUi: React.FC<IVoteProposalUiProps> = ({
179
153
</ Typography >
180
154
181
155
< div css = { styles . cardFooter } >
182
- < Typography variant = "small2" >
183
- { t ( 'voteProposalUi.activeUntil' ) }
184
- < Typography variant = "small2" color = "textPrimary" >
185
- 27 Jun 13:54
156
+ { cancelDate && (
157
+ < Typography variant = "small2" >
158
+ { t ( 'voteProposalUi.activeUntil' ) }
159
+ < Typography css = { styles . activeUntilDate } variant = "small2" color = "textPrimary" >
160
+ { cancelDate }
161
+ </ Typography >
186
162
</ Typography >
187
- </ Typography >
163
+ ) }
188
164
189
165
< Typography color = "textPrimary" variant = "small2" >
190
- 27h : 13m : 54s
166
+ 27h : 13m : 54s { /* // TODO: countdown calculating */ }
191
167
</ Typography >
192
168
</ div >
193
169
</ Grid >
194
170
< Grid css = { [ styles . gridItem , styles . gridItemRight ] } item xs = { 12 } sm = { 4 } >
195
- < StatusCard
196
- status = { proposalStatus }
197
- votedFor = { votedFor }
198
- votedAgainst = { votedAgainst }
199
- abstain = { abstain }
200
- />
171
+ { proposalStatus === 'active' ? (
172
+ < ActiveVotingProgress
173
+ votedFor = { votedFor }
174
+ votedAgainst = { votedAgainst }
175
+ abstain = { abstain }
176
+ />
177
+ ) : (
178
+ < StatusCard status = { proposalStatus } />
179
+ ) }
201
180
</ Grid >
202
181
</ Grid >
203
182
</ Paper >
0 commit comments