Skip to content

Commit 759dce8

Browse files
committed
[feat] Update EventType and EventStatus enums; Add IsIncident function and integrate into useNewForm hook
1 parent 4874373 commit 759dce8

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

src/Components/Event/Enums.ts

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ import { StatusEnum } from "~/Services/Status.Entities";
33
/**
44
* @author Aloento
55
* @since 1.0.0
6-
* @version 0.1.0
6+
* @version 0.2.0
77
*/
88
export enum EventType {
99
Operational = "Operational",
1010
Maintenance = "Maintenance",
1111
Minor = "Minor Incident",
1212
Major = "Major Incident",
1313
Outage = "Service Outage",
14+
Information = "Information",
1415
}
1516

1617
/**
1718
* @author Aloento
1819
* @since 1.0.0
19-
* @version 0.1.0
20+
* @version 0.2.0
2021
*/
2122
export function GetEventType(impact: number): EventType {
2223
switch (impact) {
@@ -26,15 +27,17 @@ export function GetEventType(impact: number): EventType {
2627
return EventType.Minor;
2728
case 2:
2829
return EventType.Major;
29-
default:
30+
case 3:
3031
return EventType.Outage;
32+
default:
33+
return EventType.Information;
3134
}
3235
}
3336

3437
/**
3538
* @author Aloento
3639
* @since 1.0.0
37-
* @version 0.1.0
40+
* @version 0.2.0
3841
*/
3942
export function GetEventImpact(type: EventType): number {
4043
switch (type) {
@@ -44,16 +47,27 @@ export function GetEventImpact(type: EventType): number {
4447
return 1;
4548
case EventType.Major:
4649
return 2;
47-
default:
50+
case EventType.Outage:
4851
return 3;
52+
default:
53+
return 4;
4954
}
5055
}
5156

5257
/**
5358
* @author Aloento
54-
* @since 1.0.0
59+
* @since 1.1.0
5560
* @version 0.1.0
5661
*/
62+
export function IsIncident(type: EventType): boolean {
63+
return [EventType.Minor, EventType.Major, EventType.Outage].includes(type);
64+
}
65+
66+
/**
67+
* @author Aloento
68+
* @since 1.0.0
69+
* @version 0.2.0
70+
*/
5771
export enum EventStatus {
5872
Analysing = "Analysing",
5973
Fixing = "Fixing",
@@ -70,6 +84,22 @@ export enum EventStatus {
7084
Changed = "Changed",
7185
}
7286

87+
/**
88+
* @author Aloento
89+
* @since 1.1.0
90+
* @version 0.1.0
91+
*/
92+
export function GetStatusList(type: EventType): EventStatus[] {
93+
switch (type) {
94+
case EventType.Maintenance:
95+
return Object.values(EventStatus).slice(4, 9);
96+
case EventType.Information:
97+
return [EventStatus.Planned, EventStatus.Completed, EventStatus.Cancelled];
98+
default:
99+
return Object.values(EventStatus).slice(0, 4);
100+
}
101+
}
102+
73103
/**
74104
* @author Aloento
75105
* @since 1.0.0
@@ -82,7 +112,7 @@ export function IsOpenStatus(status: EventStatus): boolean {
82112
/**
83113
* @author Aloento
84114
* @since 1.0.0
85-
* @version 0.1.0
115+
* @version 0.2.0
86116
*/
87117
export function GetStatusString(status: EventStatus): string {
88118
switch (status) {

src/Components/New/useNewForm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useEffect, useState } from "react";
33
import { useStatus } from "~/Services/Status";
44
import { Models } from "~/Services/Status.Models";
55
import { useAccessToken } from "../Auth/useAccessToken";
6-
import { EventStatus, EventType, GetEventImpact } from "../Event/Enums";
6+
import { EventStatus, EventType, GetEventImpact, IsIncident } from "../Event/Enums";
77
import { useRouter } from "../Router";
88

99
/**
@@ -184,6 +184,7 @@ export function useNewForm() {
184184
const body: Record<string, any> = {
185185
title,
186186
description,
187+
type: IsIncident(type) ? "incident" : type === EventType.Maintenance ? "maintenance" : "info",
187188
impact: GetEventImpact(type),
188189
components: services.map(s => s.Id),
189190
start_date: start.toISOString()

0 commit comments

Comments
 (0)