From 566a2598967282b96dee716387918044c9d8cb95 Mon Sep 17 00:00:00 2001 From: taskylizard <75871323+taskylizard@users.noreply.github.com> Date: Sun, 19 Nov 2023 11:27:54 +0000 Subject: [PATCH] final feedback fixes --- .vitepress/routes/index.post.ts | 28 ++++++------------------ .vitepress/theme/components/Feedback.vue | 6 ++++- .vitepress/types/Feedback.ts | 2 +- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/.vitepress/routes/index.post.ts b/.vitepress/routes/index.post.ts index 38164174d..1af6f4707 100644 --- a/.vitepress/routes/index.post.ts +++ b/.vitepress/routes/index.post.ts @@ -1,32 +1,18 @@ import { fetcher } from "itty-fetcher"; -import { FeedbackSchema } from "../types/Feedback"; - -const feedbackOptions = [ - { label: "🐞 Bug", value: "bug" }, - { - label: "♻️ Suggestion", - value: "suggestion", - }, - { label: "📂 Other", value: "other" }, - { - label: "❤️ Appreciation", - value: "appreciate", - }, -]; - -function getFeedbackOption(value: string): string { - return feedbackOptions.find((option) => option.value === value).label; -} +import { FeedbackSchema, getFeedbackOption } from "../types/Feedback"; export default defineEventHandler(async (event) => { - const { message, page, contact, type } = await readValidatedBody(event, FeedbackSchema.parse); + const { message, page, contact, type } = await readValidatedBody( + event, + FeedbackSchema.parseAsync, + ); const env = useRuntimeConfig(event); if (!["bug", "suggestion", "other", "appreciate"].includes(type!) || !message) throw new Error("Invalid input."); let description = `${message}\n\n`; - if (contact) description += `**Contact:** ${contact}\n`; + if (contact) description += `**Contact:** ${contact} • `; if (page) description += `**Page:** \`${page}\``; await fetcher() @@ -36,7 +22,7 @@ export default defineEventHandler(async (event) => { embeds: [ { color: 3447003, - title: getFeedbackOption(type), + title: getFeedbackOption(type).label, description, }, ], diff --git a/.vitepress/theme/components/Feedback.vue b/.vitepress/theme/components/Feedback.vue index 05e047776..726fea320 100644 --- a/.vitepress/theme/components/Feedback.vue +++ b/.vitepress/theme/components/Feedback.vue @@ -82,7 +82,11 @@ async function handleSubmit(type?: FeedbackType["type"]) { diff --git a/.vitepress/types/Feedback.ts b/.vitepress/types/Feedback.ts index d250bab82..b0d9408a8 100644 --- a/.vitepress/types/Feedback.ts +++ b/.vitepress/types/Feedback.ts @@ -3,7 +3,7 @@ import z from "zod"; export const FeedbackSchema = z.object({ message: z.string().min(5).max(1000), type: z.enum(["bug", "suggestion", "appreciate", "other"]), - contact: z.string().min(5).max(20).optional(), + contact: z.string().optional(), page: z.string().min(3).max(10), });