diff --git a/backend/cmd/migrate/migrations/20250213101006_remove_status_events.go b/backend/cmd/migrate/migrations/20250213101006_remove_status_events.go new file mode 100644 index 0000000..31b4343 --- /dev/null +++ b/backend/cmd/migrate/migrations/20250213101006_remove_status_events.go @@ -0,0 +1,23 @@ +package migrations + +import ( + "context" + "fmt" + + "fr.latosa-escrima/core/models" + "github.com/uptrace/bun" +) + +func init() { + Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error { + fmt.Print(" [up migration] ") + _, err := db.NewDropColumn(). + Model((*models.Event)(nil)). + ColumnExpr("status"). + Exec(ctx) + return err + }, func(ctx context.Context, db *bun.DB) error { + fmt.Print(" [down migration] ") + return nil + }) +} diff --git a/frontend/components/event-dialog.tsx b/frontend/components/event-dialog.tsx index 34ad52a..ff7fbbe 100644 --- a/frontend/components/event-dialog.tsx +++ b/frontend/components/event-dialog.tsx @@ -73,8 +73,10 @@ const isCalendarEventExternal = ( export const EventForm: React.FC<{ event: ICalendarEvent | Omit; - onSubmit: (data: EventFormValues) => any; -}> = ({ event, onSubmit }) => { + setForm: React.Dispatch< + React.SetStateAction | undefined> + >; +}> = ({ event, setForm }) => { const _start = new Date(event.start ?? Date.now()); const _end = new Date(event.end ?? Date.now()); const form = useForm({ @@ -91,56 +93,15 @@ export const EventForm: React.FC<{ }, }); + useEffect(() => { + setForm(form); + }, []); + const frequency = form.watch("frequency"); - // async function onSubmit(data: EventFormValues) { - // try { - // const validatedData = eventFormSchema.parse(data); - // onSubmitEvent(validatedData); - // } catch (error) { - // console.error("On submit error : ", error); - // } - // } - - // useEffect(() => { - // try { - // const validatedData = eventFormSchema.parse(form); - // setEvent((old) => { - // const rrule = mapFrequencyToRrule( - // validatedData.frequency, - // validatedData.frequencyEndDate, - // ); - // const [sHours, sMinutes] = validatedData.startTime.split(":"); - // validatedData.startDate.setHours( - // parseInt(sHours), - // parseInt(sMinutes), - // ); - // const [eHours, eMinutes] = validatedData.endTime.split(":"); - // validatedData.endDate.setHours( - // parseInt(eHours), - // parseInt(eMinutes), - // ); - // return { - // ...old, - // start: validatedData.startDate.toISOString(), - // end: validatedData.endDate.toISOString(), - // title: `${validatedData.title}`, - // fullDay: validatedData.fullDay, - // rrule: rrule, - // isVisible: validatedData.isVisible, - // }; - // }); - // } catch (e) { - // console.log(e); - // } - // }, [form]); - return (
- + = { ...newEvent, start: formValues.startDate.toISOString(), @@ -185,7 +188,7 @@ const Planning: React.FC<{ `/events/${id}/delete`, { method: "DELETE", - requiresAuth: false, + requiresAuth: true, csrfToken: false, }, ); @@ -245,17 +248,9 @@ const EventDialog: React.FC< > = ({ open, onOpenChange, onDelete, onUpdate, onAdd, event }) => { const [form, setForm] = useState>(); - const handleOnAdd = (data: EventFormValues) => { - onAdd?.(data); - }; - - const onSubmit = (data: EventFormValues) => { - try { - const validatedData = eventFormSchema.parse(data); - handleOnAdd(data); - } catch (e) { - console.error(e); - } + const submitForm = (event: "add" | "update") => { + const callback = event === "add" ? onAdd : onUpdate; + if (callback) form?.handleSubmit(callback)(); }; return ( @@ -265,24 +260,12 @@ const EventDialog: React.FC< {event.title} {event.description} - + {onUpdate && ( )} {onAdd && !onUpdate && !onDelete && ( - )}