|
| 1 | +/** @jsxImportSource @emotion/react */ |
| 2 | +import React, { useMemo } from 'react'; |
| 3 | +import Paper from '@mui/material/Paper'; |
| 4 | +import Grid from '@mui/material/Grid'; |
| 5 | +import Typography from '@mui/material/Typography'; |
| 6 | + |
| 7 | +import { useTranslation } from 'translation'; |
| 8 | +import { Icon } from '../Icon'; |
| 9 | +import { ProgressBar } from '../ProgressBar'; |
| 10 | +import { useStyles } from './styles'; |
| 11 | + |
| 12 | +type ProposalStatus = 'active' | 'queued' | 'readyToExecute' | 'executed' | 'cancelled'; |
| 13 | + |
| 14 | +interface IStatusCard { |
| 15 | + status: ProposalStatus; |
| 16 | + votedFor?: string; |
| 17 | + votedAgainst?: string; |
| 18 | + abstain?: string; |
| 19 | +} |
| 20 | + |
| 21 | +const StatusCard: React.FC<IStatusCard> = ({ status, votedFor, votedAgainst, abstain }) => { |
| 22 | + const styles = useStyles(); |
| 23 | + const { t } = useTranslation(); |
| 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> |
| 55 | + |
| 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 | + 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 | + 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 | + 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 | + case 'cancelled': |
| 98 | + return ( |
| 99 | + <> |
| 100 | + <div css={[styles.iconWrapper, styles.iconCloseWrapper]}> |
| 101 | + <Icon css={styles.icon} name="close" /> |
| 102 | + </div> |
| 103 | + <Typography css={styles.statusText} variant="body2"> |
| 104 | + {t('voteProposalUi.statusCard.cancelled')} |
| 105 | + </Typography> |
| 106 | + </> |
| 107 | + ); |
| 108 | + } |
| 109 | +}; |
| 110 | + |
| 111 | +type VoteStatus = 'votedFor' | 'votedAgainst' | 'abstained'; |
| 112 | + |
| 113 | +interface IVoteProposalUiProps { |
| 114 | + className?: string; |
| 115 | + proposalNumber: number; |
| 116 | + proposalText: string; |
| 117 | + proposalStatus: ProposalStatus; |
| 118 | + voteStatus?: VoteStatus; |
| 119 | + votedFor?: string; |
| 120 | + votedAgainst?: string; |
| 121 | + abstain?: string; |
| 122 | +} |
| 123 | + |
| 124 | +export const VoteProposalUi: React.FC<IVoteProposalUiProps> = ({ |
| 125 | + className, |
| 126 | + proposalNumber, |
| 127 | + proposalText, |
| 128 | + proposalStatus, |
| 129 | + voteStatus, |
| 130 | + votedFor, |
| 131 | + votedAgainst, |
| 132 | + abstain, |
| 133 | +}) => { |
| 134 | + const styles = useStyles(); |
| 135 | + const { t } = useTranslation(); |
| 136 | + |
| 137 | + const voteStatusText = useMemo(() => { |
| 138 | + switch (voteStatus) { |
| 139 | + case 'votedFor': |
| 140 | + return t('voteProposalUi.voteStatus.votedFor'); |
| 141 | + case 'votedAgainst': |
| 142 | + return t('voteProposalUi.voteStatus.votedAgainst'); |
| 143 | + case 'abstained': |
| 144 | + return t('voteProposalUi.voteStatus.abstained'); |
| 145 | + default: |
| 146 | + return t('voteProposalUi.voteStatus.notVoted'); |
| 147 | + } |
| 148 | + }, [voteStatus]); |
| 149 | + |
| 150 | + return ( |
| 151 | + <Paper className={className} css={styles.root}> |
| 152 | + <Grid container> |
| 153 | + <Grid css={[styles.gridItem, styles.gridItemLeft]} item xs={12} sm={8}> |
| 154 | + <div css={styles.cardHeader}> |
| 155 | + <div css={styles.cardBadges}> |
| 156 | + <Typography |
| 157 | + variant="small2" |
| 158 | + color="textPrimary" |
| 159 | + css={[styles.cardBadgeItem, styles.cardBadgeNumber]} |
| 160 | + > |
| 161 | + #{proposalNumber} |
| 162 | + </Typography> |
| 163 | + {proposalStatus === 'active' && ( |
| 164 | + <Typography |
| 165 | + variant="small2" |
| 166 | + color="textPrimary" |
| 167 | + css={[styles.cardBadgeItem, styles.cardBadgeActive]} |
| 168 | + > |
| 169 | + {t('voteProposalUi.proposalStatus.active')} |
| 170 | + </Typography> |
| 171 | + )} |
| 172 | + </div> |
| 173 | + |
| 174 | + <Typography variant="small2">{voteStatusText}</Typography> |
| 175 | + </div> |
| 176 | + |
| 177 | + <Typography variant="h4" css={styles.cardTitle}> |
| 178 | + {proposalText} |
| 179 | + </Typography> |
| 180 | + |
| 181 | + <div css={styles.cardFooter}> |
| 182 | + <Typography variant="small2"> |
| 183 | + {t('voteProposalUi.activeUntil')} |
| 184 | + <Typography variant="small2" color="textPrimary"> |
| 185 | + 27 Jun 13:54 |
| 186 | + </Typography> |
| 187 | + </Typography> |
| 188 | + |
| 189 | + <Typography color="textPrimary" variant="small2"> |
| 190 | + 27h : 13m : 54s |
| 191 | + </Typography> |
| 192 | + </div> |
| 193 | + </Grid> |
| 194 | + <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 | + /> |
| 201 | + </Grid> |
| 202 | + </Grid> |
| 203 | + </Paper> |
| 204 | + ); |
| 205 | +}; |
0 commit comments