Skip to content

Commit 6a68a12

Browse files
authored
[fix] Refines event status management and validation logic (#208)
1 parent b72d99e commit 6a68a12

2 files changed

Lines changed: 9 additions & 14 deletions

File tree

src/Components/Event/EventEditor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { useEditForm } from "./useEditForm";
2020
*
2121
* @author Aloento
2222
* @since 1.0.0
23-
* @version 0.2.0
23+
* @version 0.2.1
2424
*/
2525
export function EventEditor({ Event }: { Event: Models.IEvent }) {
2626
const { State, Actions, Validation, OnSubmit, Loading } = useEditForm(Event);
@@ -99,7 +99,7 @@ export function EventEditor({ Event }: { Event: Models.IEvent }) {
9999
<ScaleTextField
100100
type="datetime-local"
101101
label="(Plan) End CET"
102-
disabled={!(!IsIncident(State.type) || !IsOpenStatus(State.status))}
102+
disabled={!(!IsIncident(State.type) || (State.status && !IsOpenStatus(State.status)))}
103103
value={State.end ? dayjs(State.end).format(Dic.Picker) : null}
104104
onScale-input={(e) => Actions.setEnd(new Date(e.target.value as string))}
105105
invalid={!!Validation.end}

src/Components/Event/useEditForm.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { EventStatus, EventType, GetEventImpact, GetStatusString, IsIncident, Is
2323
*
2424
* @author Aloento
2525
* @since 1.0.0
26-
* @version 0.2.0
26+
* @version 0.2.1
2727
*/
2828
export function useEditForm(event: Models.IEvent) {
2929
const [title, _setTitle] = useState(event.Title);
@@ -60,12 +60,8 @@ export function useEditForm(event: Models.IEvent) {
6060
return false;
6161
}
6262

63-
if (!IsIncident(type) && IsIncident(value)) {
64-
_setStatus(EventStatus.Analysing);
65-
}
66-
67-
if (IsIncident(type) && !IsIncident(value)) {
68-
_setStatus(EventStatus.Planned);
63+
if (type !== value) {
64+
_setStatus(undefined);
6965
}
7066

7167
_setType(value);
@@ -95,7 +91,7 @@ export function useEditForm(event: Models.IEvent) {
9591
return !err;
9692
}
9793

98-
const [status, _setStatus] = useState(event.Status);
94+
const [status, _setStatus] = useState<EventStatus | undefined>();
9995
const [valStatus, setValStatus] = useState<string>();
10096
function setStatus(value = status) {
10197
if (!value) {
@@ -179,12 +175,11 @@ export function useEditForm(event: Models.IEvent) {
179175
if (![setTitle(), setType(), setUpdate(), setStatus(), setStart(), setEnd(), setUpdateAt()].every(Boolean)) {
180176
throw new Error("Validation failed.");
181177
}
182-
183178
const url = process.env.SD_BACKEND_URL!;
184179

185180
const body: Record<string, any> = {
186181
title,
187-
status: GetStatusString(status),
182+
status: GetStatusString(status!),
188183
impact: GetEventImpact(type),
189184
message: update,
190185
update_date: updateAt.toISOString(),
@@ -230,15 +225,15 @@ export function useEditForm(event: Models.IEvent) {
230225
const updatedEvent = { ...DB.Events[eventIndex] };
231226
updatedEvent.Title = title;
232227
updatedEvent.Type = type;
233-
updatedEvent.Status = status;
228+
updatedEvent.Status = status!;
234229
updatedEvent.Start = start;
235230
updatedEvent.End = end;
236231

237232
const newHistory: Models.IHistory = {
238233
Id: Math.max(...Array.from(updatedEvent.Histories).map(h => h.Id), 0) + 1,
239234
Message: update,
240235
Created: updateAt,
241-
Status: status,
236+
Status: status!,
242237
Event: updatedEvent
243238
};
244239
updatedEvent.Histories.add(newHistory);

0 commit comments

Comments
 (0)