From 17790f2d3e8249b6110a2f781f4fad5b53b03d52 Mon Sep 17 00:00:00 2001 From: mcinquin Date: Mon, 14 Sep 2026 10:25:32 +0200 Subject: [PATCH] fix(sentence): fix issue with emoji --- src/app/dashboard/teams/[teamId]/create/page.tsx | 10 +++++++++- src/lib/schemas/phrase.ts | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/dashboard/teams/[teamId]/create/page.tsx b/src/app/dashboard/teams/[teamId]/create/page.tsx index d06fdd9..89d269c 100644 --- a/src/app/dashboard/teams/[teamId]/create/page.tsx +++ b/src/app/dashboard/teams/[teamId]/create/page.tsx @@ -68,10 +68,15 @@ export default function CreateCardPage() { e.preventDefault(); if (!newPhraseText.trim()) return; setAddingPhrase(true); + setError(""); + const trimmedEmoji = newPhraseEmoji.trim(); const res = await fetch(`/api/teams/${teamId}/phrases`, { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ text: newPhraseText.trim(), emoji: newPhraseEmoji.trim() || null }), + body: JSON.stringify({ + text: newPhraseText.trim(), + ...(trimmedEmoji ? { emoji: trimmedEmoji } : {}), + }), }); if (res.ok) { const phrase = await res.json(); @@ -79,6 +84,9 @@ export default function CreateCardPage() { setSelectedIds((prev) => new Set(Array.from(prev).concat(phrase.id))); setNewPhraseText(""); setNewPhraseEmoji(""); + } else { + const data = await res.json().catch(() => ({})); + setError(data.error ?? "Impossible d'ajouter la phrase"); } setAddingPhrase(false); } diff --git a/src/lib/schemas/phrase.ts b/src/lib/schemas/phrase.ts index 29a3a54..429bc31 100644 --- a/src/lib/schemas/phrase.ts +++ b/src/lib/schemas/phrase.ts @@ -6,7 +6,10 @@ export const createPhraseSchema = z.object({ .trim() .min(1, "Texte requis") .max(200, "Texte trop long (max 200 caractères)"), - emoji: z.string().trim().max(4, "Emoji invalide").optional().or(z.literal("")), + emoji: z.preprocess( + (val) => (val === null || val === "" ? undefined : val), + z.string().trim().max(4, "Emoji invalide").optional() + ), }); export const deletePhraseSchema = z.object({