From 2ea15c2acf3df1e44de80b4bb0845bbb17a868d5 Mon Sep 17 00:00:00 2001 From: gom-by Date: Wed, 29 Jan 2025 18:53:38 +0100 Subject: [PATCH 1/3] merging with dev/ceddric --- backend/api/blogs/delete.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/backend/api/blogs/delete.go b/backend/api/blogs/delete.go index 6e364c7..aa1a2c2 100644 --- a/backend/api/blogs/delete.go +++ b/backend/api/blogs/delete.go @@ -1,5 +1,4 @@ package blogs -<<<<<<< HEAD import ( "context" @@ -31,5 +30,3 @@ func HandleDelete(w http.ResponseWriter, r *http.Request) { Message: "Blog deleted.", }.Respond(w, http.StatusOK) } -======= ->>>>>>> dev/cedric From 97dc0b80225aa1f748bb90f35b7dc8c502b15b3a Mon Sep 17 00:00:00 2001 From: gom-by Date: Mon, 3 Feb 2025 12:37:44 +0100 Subject: [PATCH 2/3] Calendar event creation form (not finished) --- backend/core/models/events.go | 1 + frontend/components/planning.tsx | 188 ++++++++++++++++++++----------- 2 files changed, 123 insertions(+), 66 deletions(-) diff --git a/backend/core/models/events.go b/backend/core/models/events.go index e222922..35f4589 100644 --- a/backend/core/models/events.go +++ b/backend/core/models/events.go @@ -18,6 +18,7 @@ type Event struct { bun.BaseModel `bun:"table:events"` EventID uuid.UUID `bun:"event_id,type:uuid,pk,default:gen_random_uuid()" json:"id"` + Title string `bun:"title,notnull,default:'no title'" json:"title"` CreationDate time.Time `bun:"creation_date,notnull,default:current_timestamp" json:"creationDate"` ScheduleStart time.Time `bun:"schedule_start,notnull" json:"start"` ScheduleEnd time.Time `bun:"schedule_end,notnull" json:"end"` diff --git a/frontend/components/planning.tsx b/frontend/components/planning.tsx index 772aca8..3805fe3 100644 --- a/frontend/components/planning.tsx +++ b/frontend/components/planning.tsx @@ -28,6 +28,11 @@ import { Button } from "@/components/ui/button"; import { KeyedMutator } from "swr"; import { getCookie } from "cookies-next"; import { useTheme } from "next-themes"; +import { Checkbox } from "@radix-ui/react-checkbox"; + +interface CalendarEventExternalDB extends CalendarEventExternal { + status: "Active" | "Inactive" +} const Planning: React.FC<{ events: CalendarEventExternal[]; @@ -38,14 +43,15 @@ const Planning: React.FC<{ const isConnected = getCookie("auth_token"); const plugins = isConnected ? [ - createEventsServicePlugin(), - createDragAndDropPlugin(), - createResizePlugin(), - createEventRecurrencePlugin(), - ] + createEventsServicePlugin(), + createDragAndDropPlugin(), + createResizePlugin(), + createEventRecurrencePlugin(), + ] : []; const [eventSelected, setEventSelected] = useState(null); + const [eventStatus, setEventStatus] = useState("Active") const [newEvent, setNewEvent] = useState { + const val = e.currentTarget.value; + setNewEvent((ev) => { + if (ev) + return { + ...ev, + title: val, + }; + return ev; + }); + }} + onActiveStateChange={(e) => { + e ? setEventStatus("Active") + : setEventStatus("Inactive") + }} onAdd={async () => { try { const event: Omit = { ...newEvent, start: `${new Date(newEvent.start).toISOString()}`, end: `${new Date(newEvent.end).toISOString()}`, - }; + title: newEvent.title, + status: eventStatus + } const res = await request( `/events/new`, { @@ -252,6 +275,8 @@ const EventDialog: React.FC< onDelete?: () => void; onUpdate?: () => void; onAdd?: () => void; + onTitleChange?: React.ChangeEventHandler; + onActiveStateChange?: (status: boolean) => void; event: CalendarEventExternal | Omit; } & DialogProps > = ({ @@ -262,22 +287,37 @@ const EventDialog: React.FC< onDelete, onUpdate, onAdd, + onTitleChange, + onActiveStateChange, event, }) => { - return ( - - - - {event.title} - {event.description} - + return ( + + + + {event.title} + {event.description} + -
-
- - {/* +
+
+ + +
+ +
+ + {/*
+
+ + +
+
+ + { + const isChecked = typeof e === "boolean" ? e : false; + if (onActiveStateChange != undefined) { + onActiveStateChange(isChecked) + } + }} + /> +
-
- - -
-
- - {onUpdate && ( - - )} - {onDelete && ( - - )} - {onAdd && !onUpdate && !onDelete && ( - - )} - - -
- ); -}; + + {onUpdate && ( + + )} + {onDelete && ( + + )} + {onAdd && !onUpdate && !onDelete && ( + + )} + +
+
+ ); + }; export default Planning; From 83e6d145b29c7b03828465eef0ffa1eae6c5f8cd Mon Sep 17 00:00:00 2001 From: gom-by Date: Mon, 3 Feb 2025 16:11:10 +0100 Subject: [PATCH 3/3] checkbox for status visibility in frontend --- backend/core/models/events.go | 2 +- frontend/components/planning.tsx | 27 +++++++++++----- frontend/components/ui/checkbox.tsx | 48 ++++++++++++++--------------- frontend/package-lock.json | 6 ++-- 4 files changed, 47 insertions(+), 36 deletions(-) diff --git a/backend/core/models/events.go b/backend/core/models/events.go index 35f4589..f350f13 100644 --- a/backend/core/models/events.go +++ b/backend/core/models/events.go @@ -18,7 +18,7 @@ type Event struct { bun.BaseModel `bun:"table:events"` EventID uuid.UUID `bun:"event_id,type:uuid,pk,default:gen_random_uuid()" json:"id"` - Title string `bun:"title,notnull,default:'no title'" json:"title"` + Title string `bun:"title,notnull" json:"title"` CreationDate time.Time `bun:"creation_date,notnull,default:current_timestamp" json:"creationDate"` ScheduleStart time.Time `bun:"schedule_start,notnull" json:"start"` ScheduleEnd time.Time `bun:"schedule_end,notnull" json:"end"` diff --git a/frontend/components/planning.tsx b/frontend/components/planning.tsx index 3805fe3..067e209 100644 --- a/frontend/components/planning.tsx +++ b/frontend/components/planning.tsx @@ -28,10 +28,13 @@ import { Button } from "@/components/ui/button"; import { KeyedMutator } from "swr"; import { getCookie } from "cookies-next"; import { useTheme } from "next-themes"; -import { Checkbox } from "@radix-ui/react-checkbox"; +import { Checkbox } from "@/components/ui/checkbox"; +import { eventNames } from "process"; +import { useSearchParams } from "next/navigation"; +import { CheckedState } from "@radix-ui/react-checkbox"; interface CalendarEventExternalDB extends CalendarEventExternal { - status: "Active" | "Inactive" + status: "Active" | "Inactive" } const Planning: React.FC<{ @@ -183,7 +186,7 @@ const Planning: React.FC<{ end: `${new Date(newEvent.end).toISOString()}`, title: newEvent.title, status: eventStatus - } + } const res = await request( `/events/new`, { @@ -291,6 +294,9 @@ const EventDialog: React.FC< onActiveStateChange, event, }) => { + + const [checked, setChecked] = useState(event.status === "Active") + return ( @@ -379,18 +385,23 @@ const EventDialog: React.FC< Rendre cette évènement actif ? { - const isChecked = typeof e === "boolean" ? e : false; - if (onActiveStateChange != undefined) { - onActiveStateChange(isChecked) + const booleanCheck = !!e + setChecked(prev => { return !prev }) + if (onActiveStateChange) { + onActiveStateChange(booleanCheck) } }} /> +
+ Date syntax : yyyy-MM-dd HH:mm +
{onUpdate && (