From 0b043e8eb500a3e89e0b92a16bdbaf7a580c911a Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 27 Aug 2025 19:42:15 +0200 Subject: [PATCH] [feat] Adds description field to event editor Introduces a new description field to the event editor, allowing users to provide an optional description of up to 500 characters. Updates the validation logic and integrates the description into the event submission process, enhancing the overall event management functionality. --- src/Components/Event/EventEditor.tsx | 12 +++++++++++- src/Components/Event/useEditForm.ts | 26 +++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/Components/Event/EventEditor.tsx b/src/Components/Event/EventEditor.tsx index ea9d198..0bea011 100644 --- a/src/Components/Event/EventEditor.tsx +++ b/src/Components/Event/EventEditor.tsx @@ -20,7 +20,7 @@ import { useEditForm } from "./useEditForm"; * * @author Aloento * @since 1.0.0 - * @version 0.2.1 + * @version 0.3.0 */ export function EventEditor({ Event }: { Event: Models.IEvent }) { const { State, Actions, Validation, OnSubmit, Loading } = useEditForm(Event); @@ -115,6 +115,16 @@ export function EventEditor({ Event }: { Event: Models.IEvent }) { helperText={Validation.updateAt} /> + Actions.setDescription(e.target.value as string)} + invalid={!!Validation.description} + helperText={Validation.description} + /> + (); + function setDescription(value = description) { + let err: boolean = false; + + if (value && value.length > 500) { + setValDescription("Description must be less than 500 characters."); + err = true; + } + + _setDescription(value); + !err && setValDescription(undefined); + + return !err; + } + const [status, _setStatus] = useState(); const [valStatus, setValStatus] = useState(); function setStatus(value = status) { @@ -172,10 +188,9 @@ export function useEditForm(event: Models.IEvent) { const { DB, Update } = useStatus(); const { runAsync, loading } = useRequest(async () => { - if (![setTitle(), setType(), setUpdate(), setStatus(), setStart(), setEnd(), setUpdateAt()].every(Boolean)) { + if (![setTitle(), setType(), setUpdate(), setDescription(), setStatus(), setStart(), setEnd(), setUpdateAt()].every(Boolean)) { throw new Error("Validation failed."); } - const url = process.env.SD_BACKEND_URL!; const body: Record = { @@ -184,6 +199,7 @@ export function useEditForm(event: Models.IEvent) { impact: GetEventImpact(type), message: update, update_date: updateAt.toISOString(), + description, }; if (event.Type !== type) { @@ -229,6 +245,7 @@ export function useEditForm(event: Models.IEvent) { updatedEvent.Status = status!; updatedEvent.Start = start; updatedEvent.End = end; + updatedEvent.Description = description; const newHistory: Models.IHistory = { Id: Math.max(...Array.from(updatedEvent.Histories).map(h => h.Id), 0) + 1, @@ -255,6 +272,7 @@ export function useEditForm(event: Models.IEvent) { title, type, update, + description, status, start, end, @@ -264,6 +282,7 @@ export function useEditForm(event: Models.IEvent) { setTitle, setType, setUpdate, + setDescription, setStatus, setStart, setEnd, @@ -273,6 +292,7 @@ export function useEditForm(event: Models.IEvent) { title: valTitle, type: valType, update: valUpdate, + description: valDescription, status: valStatus, start: valStart, end: valEnd,