From ac104662f1ad3e435ff3bd2e5e2852015e224ab4 Mon Sep 17 00:00:00 2001 From: Ludovic Mermod Date: Tue, 7 Nov 2023 18:01:56 +0100 Subject: [PATCH] feat: improve user feedback --- backend/src/routes/participants.rs | 3 +- frontend/src/pages/events/[eventId]/index.tsx | 68 ++++++++++++++----- 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/backend/src/routes/participants.rs b/backend/src/routes/participants.rs index d8257bf..a572622 100644 --- a/backend/src/routes/participants.rs +++ b/backend/src/routes/participants.rs @@ -2,11 +2,12 @@ use rocket::{delete, get, post, put, serde::json::Json}; use serde::{Deserialize, Serialize}; use uuid::Uuid; -use crate::{models::Participant, DB, error::Error}; +use crate::{error::Error, models::Participant, DB}; use super::login::RequireLogin; #[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct ParticipantForm { pub sciper: String, pub email: String, diff --git a/frontend/src/pages/events/[eventId]/index.tsx b/frontend/src/pages/events/[eventId]/index.tsx index 404d813..46d2f95 100644 --- a/frontend/src/pages/events/[eventId]/index.tsx +++ b/frontend/src/pages/events/[eventId]/index.tsx @@ -9,7 +9,7 @@ import { import { Event, EventForm } from "@/models"; import Link from "next/link"; import { useRouter } from "next/router"; -import { ChangeEvent, InputHTMLAttributes, useState } from "react"; +import { ChangeEvent, InputHTMLAttributes, useEffect, useState } from "react"; import * as yup from "yup"; import Editor from "@monaco-editor/react"; @@ -37,6 +37,16 @@ export default function Event({ date: event?.date, mailTemplate: event?.mailTemplate, } as Partial); + const [eventState, setEventState] = useState(event as Event | undefined); + const [hasChanged, setHasChanged] = useState(false); + + useEffect(() => { + setHasChanged( + eventForm.date !== eventState?.date || + eventForm.name !== eventState?.name || + eventForm.mailTemplate !== eventState?.mailTemplate + ); + }, [eventForm, eventState]); async function saveEvent() { setError(null); @@ -44,11 +54,13 @@ export default function Event({ try { let form = await validationSchema.validate(eventForm); - if (event) { - const res = await updateEvent(event?.uid, form, session); + if (eventState) { + const res = await updateEvent(eventState?.uid, form, session); if (!("uid" in res)) { setError(res.description || "An unknown error occurred"); + } else { + setEventState(res); } } else { const res = await createEvent(form, session); @@ -95,7 +107,7 @@ export default function Event({ @@ -105,14 +117,14 @@ export default function Event({ height="70vh" loading="Loading Mail Template..." defaultLanguage="html" - defaultValue={event?.mailTemplate} + defaultValue={eventState?.mailTemplate} onChange={updateField("mailTemplate")} />

The mail should be in HTML. To display the ticket, add an img tag with the ”qrcode” class.

- {event ? ( + {eventState ? (