Skip to content

Commit

Permalink
Added Past incident component, stories & example incidents json data …
Browse files Browse the repository at this point in the history
…file.
  • Loading branch information
NikuPAN committed Jul 12, 2024
1 parent 67a81f1 commit 3dd8285
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
21 changes: 21 additions & 0 deletions public/incidents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"last_updated": "2024-07-02T15:53:42+1000",
"incidents": [
{
"datetime_reported": "2024-04-16T10:53:42+1000",
"reason": "PB Server - service disrupted"
},
{
"datetime_reported": "2024-02-12T09:43:42+1000",
"reason": "HPC-FS Scheduled maintenance"
},
{
"datetime_reported": "2023-12-13T06:33:42+1000",
"reason": "PB Server - service disrupted"
},
{
"datetime_reported": "2023-10-19T07:33:32+1000",
"reason": "HPC-FS Scheduled maintenance"
}
]
}
22 changes: 22 additions & 0 deletions src/components/pastIncidents/PastIncidents.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Meta, StoryFn } from "@storybook/react";
import { PastIncidents, PastIncidentsData } from "./PastIncidents";
import jsonData from "../../../public/incidents.json";

const typedJsonData: PastIncidentsData["data"] =
jsonData as PastIncidentsData["data"];

export default {
title: "Component/PastIncidents",
component: PastIncidents,
} as Meta<typeof PastIncidents>;

const Template: StoryFn<typeof PastIncidents> = (args) => (
<PastIncidents {...args} />
);

export const Simple = Template.bind({});
Simple.args = {
title: "Past Incidents",
subTitle: "Showing all past incidents in the last 6 months",
data: typedJsonData,
};
68 changes: 68 additions & 0 deletions src/components/pastIncidents/PastIncidents.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React, { FunctionComponent } from "react";
import {
Text,
Flex,
Box,
Table,
Tbody,
Tr,
Td,
TableContainer,
} from "@chakra-ui/react";

interface Incident {
datetime_reported: string;
reason: string;
}

interface Data extends Incident {
last_updated?: string;
incidents: Incident[];
}

export interface PastIncidentsData extends Data {
title: string;
subTitle: string;
data?: Data;
}

export const PastIncidents: FunctionComponent<PastIncidentsData> = ({
title,
subTitle,
data,
}) => {
return (
<Box>
<Flex direction="column" px={6} py={4}>
<Text as="b" fontSize="3xl">
{title}
</Text>
<Text fontSize="1xl">{subTitle}</Text>
</Flex>
<TableContainer>
<Table>
<Tbody>
{data && data?.incidents.length > 0 ? (
data.incidents.map((incident: any, index: number) => (
<Tr key={index}>
<Td>
<Text fontSize="2xl" as="b">
{incident?.datetime_reported}
</Text>
<Text fontSize="1xl" my={2}>
{incident?.reason}
</Text>
</Td>
</Tr>
))
) : (
<Tr></Tr>
)}
</Tbody>
</Table>
</TableContainer>
</Box>
);
};

export default PastIncidents;
1 change: 1 addition & 0 deletions src/components/pastIncidents/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PastIncidents, type PastIncidentsData } from "./PastIncidents";

0 comments on commit 3dd8285

Please sign in to comment.