Skip to content

Commit b634791

Browse files
committed
feat: add EventApprove component and integrate it into EventCard for event approval functionality
1 parent 1f91a46 commit b634791

3 files changed

Lines changed: 53 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "statusdashboard",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"type": "module",
55
"scripts": {
66
"dev": "farm start",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { ScaleButton, ScaleIconActionCheckmark } from "@telekom/scale-components-react";
2+
import { useRequest } from "ahooks";
3+
import { useAccessToken } from "../Auth/useAccessToken";
4+
5+
/**
6+
* @author Aloento
7+
* @since 1.5.0
8+
* @version 0.1.0
9+
*/
10+
export function EventApprove({ EventId }: { EventId: number }) {
11+
const getToken = useAccessToken();
12+
13+
const { runAsync, loading } = useRequest(async () => {
14+
const url = process.env.SD_BACKEND_URL!;
15+
const raw = await fetch(`${url}/v2/events/${EventId}`, {
16+
method: "PATCH",
17+
headers: {
18+
"Content-Type": "application/json",
19+
"Authorization": `Bearer ${getToken()}`,
20+
},
21+
body: JSON.stringify({
22+
status: "reviewed",
23+
message: "Approved by operator",
24+
update_date: new Date().toISOString(),
25+
}),
26+
});
27+
28+
if (!raw.ok) {
29+
throw new Error("Failed to approve event: " + await raw.text());
30+
}
31+
32+
window.location.reload();
33+
}, {
34+
manual: true,
35+
});
36+
37+
return (
38+
<ScaleButton
39+
size="small"
40+
variant="secondary"
41+
disabled={loading}
42+
onClick={() => runAsync()}
43+
>
44+
<ScaleIconActionCheckmark />
45+
&nbsp;Approve
46+
</ScaleButton>
47+
);
48+
}

src/Components/Event/EventCard.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { ScaleButton, ScaleIconActionCheckmark } from "@telekom/scale-components-react";
21
import dayjs from "dayjs";
32
import { Dic } from "~/Helpers/Entities";
43
import { Models } from "~/Services/Status.Models";
54
import { Authorized } from "../Auth/With";
65
import { Indicator } from "../Home/Indicator";
76
import { EventStatus, EventType, IsIncident } from "./Enums";
87
import { EventAffected } from "./EventAffected";
8+
import { EventApprove } from "./EventApprove";
99
import { EventEditor } from "./EventEditor";
1010
import { EventExtract } from "./EventExtract";
1111

@@ -40,10 +40,9 @@ export function EventCard({ Event }: { Event: Models.IEvent }) {
4040

4141
<Authorized>
4242
<div className="flex gap-x-3">
43-
<ScaleButton size="small" variant="secondary">
44-
<ScaleIconActionCheckmark />
45-
&nbsp;Approve
46-
</ScaleButton>
43+
{Event.Status === EventStatus.PendingReview && (
44+
<EventApprove EventId={Event.Id} />
45+
)}
4746

4847
{
4948
Event.RegionServices.size > 1 &&

0 commit comments

Comments
 (0)