1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-23 13:34:19 +00:00
pds-2021-g2-nest/nest_frontend/routes/PageRepositoryAlerts.js

74 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2021-05-25 15:06:53 +00:00
import React, { useCallback, useContext } from "react"
2021-05-18 00:04:06 +00:00
import ContextLanguage from "../contexts/ContextLanguage"
2021-05-24 01:42:30 +00:00
import BoxHeader from "../components/base/BoxHeader"
2021-05-25 02:06:14 +00:00
import { useHistory, useParams } from "react-router"
import { faBell, faPlus } from "@fortawesome/free-solid-svg-icons"
import PageWithHeader from "../components/base/layout/PageWithHeader"
import ButtonHeader from "../components/base/ButtonHeader"
import makeIcon from "../utils/makeIcon"
2021-05-25 15:06:53 +00:00
import useBackendViewset from "../hooks/useBackendViewset"
import BoxAlerts from "../components/interactive/BoxAlerts"
2021-04-21 16:21:30 +00:00
2021-05-25 02:28:51 +00:00
export default function PageRepositoryAlerts() {
2021-05-18 00:48:34 +00:00
const { strings } = useContext(ContextLanguage)
2021-05-24 01:42:30 +00:00
const { id } = useParams()
2021-05-25 02:06:14 +00:00
const history = useHistory()
2021-05-25 15:06:53 +00:00
const {resources, running: repoRunning, listResources} = useBackendViewset(
`/api/v1/repositories/${id}/alerts/`,
"id",
{
list: true,
create: false,
retrieve: false,
edit: false,
destroy: false,
command: false,
action: false,
}
)
const {destroyResource, running: alertRunning} = useBackendViewset(
`/api/v1/alert/`,
"id",
{
list: false,
create: false,
retrieve: false,
edit: false,
destroy: true,
command: false,
action: false,
}
)
// FIXME: A bit of an hack but it works for small amounts of repositories
const destroyAndRefresh = useCallback(
async (id) => {
await destroyResource(id)
await listResources()
},
[destroyResource, listResources]
)
2021-05-18 00:04:06 +00:00
2021-04-21 16:21:30 +00:00
return (
2021-05-25 02:06:14 +00:00
<PageWithHeader
header={
2021-05-25 02:09:47 +00:00
<BoxHeader>
2021-05-25 02:06:14 +00:00
{makeIcon(faBell)} {strings.alerts}
</BoxHeader>
}
buttons={
<ButtonHeader
icon={faPlus}
color={"Green"}
onClick={() => history.push(`/repositories/${id}/alerts/create`)}
>
{strings.alertCreate}
</ButtonHeader>
}
>
2021-05-25 15:06:53 +00:00
<BoxAlerts alerts={resources} destroy={destroyAndRefresh} running={repoRunning || alertRunning}/>
2021-05-25 02:06:14 +00:00
</PageWithHeader>
2021-04-21 16:21:30 +00:00
)
}