|
| 1 | +import { useAtomValue } from "jotai"; |
| 2 | +import { useParams } from "react-router-dom"; |
| 3 | +import { format } from "date-fns"; |
| 4 | +import { Row, Col, Icon } from "@canonical/react-components"; |
| 5 | + |
| 6 | +import { useSerialLog } from "../../hooks"; |
| 7 | +import { brandIdState, brandStoreState } from "../../state/brandStoreState"; |
| 8 | +import { setPageTitle } from "../../utils"; |
| 9 | + |
| 10 | +import type { UseQueryResult } from "react-query"; |
| 11 | +import type { SerialLog as SerialLogType } from "../../types/shared"; |
| 12 | + |
1 | 13 | function SerialLog() { |
2 | | - return <h1>Hi</h1>; |
| 14 | + const { id, modelId, serial } = useParams(); |
| 15 | + const brandId = useAtomValue(brandIdState); |
| 16 | + const { isLoading, isError, data }: UseQueryResult<SerialLogType[], Error> = |
| 17 | + useSerialLog(brandId, modelId, serial); |
| 18 | + const brandStore = useAtomValue(brandStoreState(id)); |
| 19 | + |
| 20 | + brandStore |
| 21 | + ? setPageTitle(`Serial logs for ${modelId} in ${brandStore.name}`) |
| 22 | + : setPageTitle("Serial logs"); |
| 23 | + |
| 24 | + return ( |
| 25 | + <> |
| 26 | + <h1>{serial}</h1> |
| 27 | + {isLoading && ( |
| 28 | + <p> |
| 29 | + <Icon name="spinner" className="u-animation--spin" /> |
| 30 | + Fetching serial logs... |
| 31 | + </p> |
| 32 | + )} |
| 33 | + {!isLoading && !isError && data && ( |
| 34 | + <> |
| 35 | + <Row> |
| 36 | + <Col size={4}> |
| 37 | + <p>Serial:</p> |
| 38 | + </Col> |
| 39 | + <Col size={8}> |
| 40 | + <p>{data[0].serial}</p> |
| 41 | + </Col> |
| 42 | + </Row> |
| 43 | + <Row> |
| 44 | + <Col size={4}> |
| 45 | + <p>Created at:</p> |
| 46 | + </Col> |
| 47 | + <Col size={8}> |
| 48 | + <p> |
| 49 | + {format( |
| 50 | + new Date(data[0]["created-at"]), |
| 51 | + "dd/MM/yyyy 'at' HH:mm", |
| 52 | + )} |
| 53 | + </p> |
| 54 | + </Col> |
| 55 | + </Row> |
| 56 | + <Row> |
| 57 | + <Col size={4}> |
| 58 | + <p>serial-sign-key-sha3-384:</p> |
| 59 | + </Col> |
| 60 | + <Col size={8}> |
| 61 | + <p>{data[0]["serial-sign-key-sha3-384"]}</p> |
| 62 | + </Col> |
| 63 | + </Row> |
| 64 | + <Row> |
| 65 | + <Col size={4}> |
| 66 | + <p>Serial assertion:</p> |
| 67 | + </Col> |
| 68 | + </Row> |
| 69 | + <pre>{data[0]["serial-assertion"]}</pre> |
| 70 | + </> |
| 71 | + )} |
| 72 | + </> |
| 73 | + ); |
3 | 74 | } |
4 | 75 |
|
5 | 76 | export default SerialLog; |
0 commit comments