@@ -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 */
2828export 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 . Detected ) ;
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 ) {
@@ -156,7 +152,7 @@ export function useEditForm(event: Models.IEvent) {
156152 function setUpdateAt ( value = updateAt ) {
157153 let err : boolean = false ;
158154
159- if ( value && value < start ) {
155+ if ( IsIncident ( type ) && value && value < start ) {
160156 setValUpdateAt ( "Update Date cannot be earlier than Start Date." ) ;
161157 err = true ;
162158 }
@@ -184,7 +180,7 @@ export function useEditForm(event: Models.IEvent) {
184180
185181 const body : Record < string , any > = {
186182 title,
187- status : GetStatusString ( status ) ,
183+ status : GetStatusString ( status ! ) ,
188184 impact : GetEventImpact ( type ) ,
189185 message : update ,
190186 update_date : updateAt . toISOString ( ) ,
@@ -230,15 +226,15 @@ export function useEditForm(event: Models.IEvent) {
230226 const updatedEvent = { ...DB . Events [ eventIndex ] } ;
231227 updatedEvent . Title = title ;
232228 updatedEvent . Type = type ;
233- updatedEvent . Status = status ;
229+ updatedEvent . Status = status ! ;
234230 updatedEvent . Start = start ;
235231 updatedEvent . End = end ;
236232
237233 const newHistory : Models . IHistory = {
238234 Id : Math . max ( ...Array . from ( updatedEvent . Histories ) . map ( h => h . Id ) , 0 ) + 1 ,
239235 Message : update ,
240236 Created : updateAt ,
241- Status : status ,
237+ Status : status ! ,
242238 Event : updatedEvent
243239 } ;
244240 updatedEvent . Histories . add ( newHistory ) ;
0 commit comments