|
| 1 | +import React, { useState } from "react"; |
| 2 | +import DeliveryTimeline from "./deliveryTimeline"; |
| 3 | +import CloseIcon from "@material-ui/icons/Close"; |
| 4 | +import LinkIcon from "@material-ui/icons/Link"; |
| 5 | +import RefreshIcon from "@material-ui/icons/Refresh"; |
| 6 | +import { |
| 7 | + Button, |
| 8 | + Card, |
| 9 | + CardActions, |
| 10 | + CardContent, |
| 11 | + CardHeader, |
| 12 | + Chip, |
| 13 | + Collapse, |
| 14 | + Grid, |
| 15 | + IconButton, |
| 16 | + LinearProgress, |
| 17 | + Link, |
| 18 | + makeStyles, |
| 19 | + Typography, |
| 20 | +} from "@material-ui/core"; |
| 21 | + |
| 22 | +const LINEAR_PROGRESS_HEIGHT = "4px"; |
| 23 | + |
| 24 | +const useStyles = makeStyles((theme) => ({ |
| 25 | + showMore: { |
| 26 | + marginLeft: "auto", |
| 27 | + }, |
| 28 | +})); |
| 29 | + |
| 30 | +export default function PackageInfoCard({ info, onDelete, onRefresh }) { |
| 31 | + const classes = useStyles(); |
| 32 | + const [expanded, setExpanded] = useState(false); |
| 33 | + const handleExpandClick = () => { |
| 34 | + setExpanded(!expanded); |
| 35 | + }; |
| 36 | + |
| 37 | + const title = ( |
| 38 | + <Grid container spacing={2}> |
| 39 | + <Grid item> |
| 40 | + <Typography variant="h5">{info.shipment.idShip}</Typography> |
| 41 | + </Grid> |
| 42 | + <Grid item> |
| 43 | + <Chip |
| 44 | + color="secondary" |
| 45 | + label={info.shipment.product} |
| 46 | + variant="outlined" |
| 47 | + /> |
| 48 | + </Grid> |
| 49 | + </Grid> |
| 50 | + ); |
| 51 | + const subheader = `${info.shipment.event[0].label}`; |
| 52 | + |
| 53 | + return ( |
| 54 | + <Card> |
| 55 | + <CardHeader |
| 56 | + action={ |
| 57 | + <IconButton aria-label="remove" onClick={onDelete}> |
| 58 | + <CloseIcon /> |
| 59 | + </IconButton> |
| 60 | + } |
| 61 | + subheader={subheader} |
| 62 | + title={title} |
| 63 | + /> |
| 64 | + <CardActions disableSpacing> |
| 65 | + <IconButton aria-label="refresh information" onClick={onRefresh}> |
| 66 | + <RefreshIcon /> |
| 67 | + </IconButton> |
| 68 | + <Link href={info.shipment.url} rel="noopener" target="_blank"> |
| 69 | + <IconButton aria-label="view on carrier website"> |
| 70 | + <LinkIcon /> |
| 71 | + </IconButton> |
| 72 | + </Link> |
| 73 | + <Button |
| 74 | + className={classes.showMore} |
| 75 | + onClick={handleExpandClick} |
| 76 | + size="small" |
| 77 | + > |
| 78 | + {expanded ? "Show Less" : "Show More"} |
| 79 | + </Button> |
| 80 | + </CardActions> |
| 81 | + <Collapse in={expanded} timeout="auto" unmountOnExit> |
| 82 | + <CardContent> |
| 83 | + <DeliveryTimeline events={info.shipment.event} /> |
| 84 | + </CardContent> |
| 85 | + </Collapse> |
| 86 | + {info.isRefreshing ? ( |
| 87 | + <LinearProgress color="secondary" /> |
| 88 | + ) : ( |
| 89 | + <div style={{ height: LINEAR_PROGRESS_HEIGHT }} /> |
| 90 | + )} |
| 91 | + </Card> |
| 92 | + ); |
| 93 | +} |
0 commit comments