-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventEditor.tsx
More file actions
161 lines (147 loc) · 5.61 KB
/
EventEditor.tsx
File metadata and controls
161 lines (147 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { ScaleButton, ScaleDropdownSelect, ScaleDropdownSelectItem, ScaleIconActionEdit, ScaleModal, ScaleTextarea, ScaleTextField } from "@telekom/scale-components-react";
import { useBoolean } from "ahooks";
import dayjs from "dayjs";
import { Dic } from "~/Helpers/Entities";
import { Models } from "~/Services/Status.Models";
import { EventStatus, EventType, GetStatusList, IsIncident, IsOpenStatus } from "./Enums";
import { useEditForm } from "./useEditForm";
/**
* The `EventEditor` component is a versatile and dynamic component designed to handle the editing of events.
* It provides a user interface for modifying event details, including title, type, status, and update message.
*
* This component leverages various hooks and state management techniques to ensure a seamless and responsive user experience.
*
* @param {Models.IEvent} props.Event - The event object to be edited.
*
* @remarks
* The `EventEditor` component is highly customizable and can be adapted to various use cases.
* It includes form validation and handles user input efficiently.
*
* @author Aloento
* @since 1.0.0
* @version 0.4.0
*/
export function EventEditor({ Event }: { Event: Models.IEvent }) {
const { State, Actions, Validation, OnSubmit, Loading } = useEditForm(Event);
const [open, { setTrue, setFalse }] = useBoolean();
return <>
<ScaleButton onClick={setTrue} size="small">
<ScaleIconActionEdit />
Edit
</ScaleButton>
<ScaleModal
heading="Edit Event"
opened={open}
omitCloseButton
size="small"
class="absolute"
onScale-before-close={(e) => e.preventDefault()}
>
<form
className="flex flex-col gap-y-6"
autoComplete="off"
onSubmit={(e) => {
e.preventDefault();
OnSubmit().then(() => setFalse());
}}>
<ScaleDropdownSelect
label="Type"
value={State.type}
disabled={!IsIncident(Event.Type)}
onScale-change={(e) => Actions.setType(e.target.value as EventType)}
invalid={!!Validation.type}
helperText={Validation.type}
>
{Object.values(EventType).slice(2, 5).map((type, i) =>
<ScaleDropdownSelectItem value={type} key={i}>
{type}
</ScaleDropdownSelectItem>)}
</ScaleDropdownSelect>
<ScaleTextField
placeholder="Please give the title of event"
required
label="Title"
value={State.title}
onScale-input={(e) => Actions.setTitle(e.target.value as string)}
invalid={!!Validation.title}
helperText={Validation.title}
/>
<ScaleDropdownSelect
label="Status"
value={State.status}
onScale-change={(e) => Actions.setStatus(e.target.value as EventStatus)}
invalid={!!Validation.status}
helperText={Validation.status}
>
{GetStatusList(State.type)
.map((status, i) =>
<ScaleDropdownSelectItem value={status} key={i}>
{status}
</ScaleDropdownSelectItem>)}
</ScaleDropdownSelect>
<ScaleTextField
type="datetime-local"
label="Start CET"
disabled={IsIncident(State.type) && IsOpenStatus(Event.Status)}
value={dayjs(State.start).format(Dic.Picker)}
onScale-input={(e) => Actions.setStart(new Date(e.target.value as string))}
invalid={!!Validation.start}
helperText={Validation.start}
/>
<ScaleTextField
type="datetime-local"
label="(Plan) End CET"
disabled={!(!IsIncident(State.type) || (State.status && !IsOpenStatus(State.status)))}
value={State.end ? dayjs(State.end).format(Dic.Picker) : null}
onScale-input={(e) => Actions.setEnd(new Date(e.target.value as string))}
invalid={!!Validation.end}
helperText={Validation.end}
/>
<ScaleTextField
type="datetime-local"
label="Updated At"
value={dayjs(State.updateAt).format(Dic.Picker)}
onScale-input={(e) => Actions.setUpdateAt(new Date(e.target.value as string))}
invalid={!!Validation.updateAt}
helperText={Validation.updateAt}
/>
<ScaleTextarea
label="Description"
placeholder="Optional description for the event"
resize="vertical"
value={State.description}
onScale-input={(e) => Actions.setDescription(e.target.value as string)}
invalid={!!Validation.description}
helperText={Validation.description}
/>
{State.type === EventType.Maintenance && (
<ScaleTextField
placeholder="e.g. DL-TSI_OTC_Storage_Squad@t-systems.com"
label="Contact Email"
type="email"
value={State.contactEmail || ""}
onScale-input={(e) => Actions.setContactEmail(e.target.value as string)}
invalid={!!Validation.contactEmail}
helperText={Validation.contactEmail}
/>
)}
<ScaleTextarea
label="Update Message"
resize="vertical"
value={State.update}
onScale-input={(e) => Actions.setUpdate(e.target.value as string)}
invalid={!!Validation.update}
helperText={Validation.update}
/>
<div className="flex gap-x-3 self-end">
<ScaleButton onClick={setFalse} variant="secondary" type="button">
Cancel
</ScaleButton>
<ScaleButton type="submit" disabled={Loading}>
Submit
</ScaleButton>
</div>
</form>
</ScaleModal>
</>;
}