|
| 1 | +import { makeStyles } from "@material-ui/core/styles" |
| 2 | +import dayjs from "dayjs" |
| 3 | +import relativeTime from "dayjs/plugin/relativeTime" |
| 4 | +import React from "react" |
| 5 | +import { Template, TemplateVersion } from "../../api/typesGenerated" |
| 6 | +import { CardRadius, MONOSPACE_FONT_FAMILY } from "../../theme/constants" |
| 7 | + |
| 8 | +dayjs.extend(relativeTime) |
| 9 | + |
| 10 | +const Language = { |
| 11 | + usedByLabel: "Used by", |
| 12 | + activeVersionLabel: "Active version", |
| 13 | + lastUpdateLabel: "Last updated", |
| 14 | + userPlural: "users", |
| 15 | + userSingular: "user", |
| 16 | +} |
| 17 | + |
| 18 | +export interface TemplateStatsProps { |
| 19 | + template: Template |
| 20 | + activeVersion: TemplateVersion |
| 21 | +} |
| 22 | + |
| 23 | +export const TemplateStats: React.FC<TemplateStatsProps> = ({ template, activeVersion }) => { |
| 24 | + const styles = useStyles() |
| 25 | + |
| 26 | + return ( |
| 27 | + <div className={styles.stats}> |
| 28 | + <div className={styles.statItem}> |
| 29 | + <span className={styles.statsLabel}>{Language.usedByLabel}</span> |
| 30 | + |
| 31 | + <span className={styles.statsValue}> |
| 32 | + {template.workspace_owner_count}{" "} |
| 33 | + {template.workspace_owner_count === 1 ? Language.userSingular : Language.userPlural} |
| 34 | + </span> |
| 35 | + </div> |
| 36 | + <div className={styles.statsDivider} /> |
| 37 | + <div className={styles.statItem}> |
| 38 | + <span className={styles.statsLabel}>{Language.activeVersionLabel}</span> |
| 39 | + <span className={styles.statsValue}>{activeVersion.name}</span> |
| 40 | + </div> |
| 41 | + <div className={styles.statsDivider} /> |
| 42 | + <div className={styles.statItem}> |
| 43 | + <span className={styles.statsLabel}>{Language.lastUpdateLabel}</span> |
| 44 | + <span className={styles.statsValue} data-chromatic="ignore"> |
| 45 | + {dayjs().to(dayjs(template.updated_at))} |
| 46 | + </span> |
| 47 | + </div> |
| 48 | + </div> |
| 49 | + ) |
| 50 | +} |
| 51 | + |
| 52 | +const useStyles = makeStyles((theme) => ({ |
| 53 | + stats: { |
| 54 | + paddingLeft: theme.spacing(2), |
| 55 | + paddingRight: theme.spacing(2), |
| 56 | + backgroundColor: theme.palette.background.paper, |
| 57 | + borderRadius: CardRadius, |
| 58 | + display: "flex", |
| 59 | + alignItems: "center", |
| 60 | + color: theme.palette.text.secondary, |
| 61 | + fontFamily: MONOSPACE_FONT_FAMILY, |
| 62 | + border: `1px solid ${theme.palette.divider}`, |
| 63 | + }, |
| 64 | + |
| 65 | + statItem: { |
| 66 | + minWidth: theme.spacing(20), |
| 67 | + padding: theme.spacing(2), |
| 68 | + paddingTop: theme.spacing(1.75), |
| 69 | + }, |
| 70 | + |
| 71 | + statsLabel: { |
| 72 | + fontSize: 12, |
| 73 | + textTransform: "uppercase", |
| 74 | + display: "block", |
| 75 | + fontWeight: 600, |
| 76 | + }, |
| 77 | + |
| 78 | + statsValue: { |
| 79 | + fontSize: 16, |
| 80 | + marginTop: theme.spacing(0.25), |
| 81 | + display: "inline-block", |
| 82 | + }, |
| 83 | + |
| 84 | + statsDivider: { |
| 85 | + width: 1, |
| 86 | + height: theme.spacing(5), |
| 87 | + backgroundColor: theme.palette.divider, |
| 88 | + marginRight: theme.spacing(2), |
| 89 | + }, |
| 90 | +})) |
0 commit comments