-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add predicted incident detail page (#1573)
- Loading branch information
1 parent
0b287bf
commit 2b0835d
Showing
9 changed files
with
198 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {getApiURL} from "../../utils/apiUrl"; | ||
import {toast} from "react-toastify"; | ||
import {IncidentDto, PaginatedIncidentsDto} from "./model"; | ||
import {Session} from "next-auth"; | ||
|
||
interface Props { | ||
incidentId: string; | ||
mutate: () => void; | ||
session: Session | null; | ||
} | ||
|
||
export const handleConfirmPredictedIncident = async ({incidentId, mutate, session}: Props) => { | ||
const apiUrl = getApiURL(); | ||
const response = await fetch( | ||
`${apiUrl}/incidents/${incidentId}/confirm`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
Authorization: `Bearer ${session?.accessToken}`, | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
); | ||
if (response.ok) { | ||
await mutate(); | ||
toast.success("Predicted incident confirmed successfully"); | ||
} else { | ||
toast.error( | ||
"Failed to confirm predicted incident, please contact us if this issue persists." | ||
); | ||
} | ||
} | ||
|
||
export const deleteIncident = async ({incidentId, mutate, session}: Props) => { | ||
const apiUrl = getApiURL(); | ||
if (confirm("Are you sure you want to delete this incident?")) { | ||
const response = await fetch(`${apiUrl}/incidents/${incidentId}`, { | ||
method: "DELETE", | ||
headers: { | ||
Authorization: `Bearer ${session?.accessToken}`, | ||
}, | ||
}) | ||
|
||
if (response.ok) { | ||
await mutate(); | ||
toast.success("Incident deleted successfully"); | ||
return true | ||
} else { | ||
toast.error("Failed to delete incident, contact us if this persists"); | ||
return false | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import {Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow} from "@tremor/react"; | ||
import { flexRender, Table as ReactTable } from "@tanstack/react-table"; | ||
import React from "react"; | ||
import { IncidentDto } from "./model"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
interface Props { | ||
table: ReactTable<IncidentDto>; | ||
} | ||
|
||
export const IncidentTableComponent = (props: Props) => { | ||
|
||
const { table } = props; | ||
|
||
const router = useRouter(); | ||
|
||
return ( | ||
<Table className="mt-4"> | ||
<TableHead> | ||
{table.getHeaderGroups().map((headerGroup) => ( | ||
<TableRow | ||
className="border-b border-tremor-border dark:border-dark-tremor-border" | ||
key={headerGroup.id} | ||
> | ||
{headerGroup.headers.map((header) => { | ||
return ( | ||
<TableHeaderCell | ||
className="text-tremor-content-strong dark:text-dark-tremor-content-strong" | ||
key={header.id} | ||
> | ||
{flexRender( | ||
header.column.columnDef.header, | ||
header.getContext() | ||
)} | ||
</TableHeaderCell> | ||
); | ||
})} | ||
</TableRow> | ||
))} | ||
</TableHead> | ||
<TableBody> | ||
{table.getRowModel().rows.map((row) => ( | ||
<> | ||
<TableRow | ||
className="even:bg-tremor-background-muted even:dark:bg-dark-tremor-background-muted hover:bg-slate-100 cursor-pointer" | ||
key={row.id} | ||
onClick={() => { | ||
router.push(`/incidents/${row.original.id}`); | ||
}} | ||
> | ||
{row.getVisibleCells().map((cell) => ( | ||
<TableCell key={cell.id}> | ||
{flexRender(cell.column.columnDef.cell, cell.getContext())} | ||
</TableCell> | ||
))} | ||
</TableRow> | ||
</> | ||
))} | ||
</TableBody> | ||
</Table> | ||
) | ||
|
||
} | ||
|
||
export default IncidentTableComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.