final feedback fixes
This commit is contained in:
parent
ae179550bf
commit
566a259896
@ -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,
|
||||
},
|
||||
],
|
||||
|
@ -82,7 +82,11 @@ async function handleSubmit(type?: FeedbackType["type"]) {
|
||||
<button
|
||||
type="submit"
|
||||
class="btn btn-primary"
|
||||
:disabled="feedback.message.length > 1000 || feedback.contact.length > 100"
|
||||
:disabled="
|
||||
feedback.message.length < 5 ||
|
||||
feedback.message.length > 1000 ||
|
||||
feedback.contact.length > 100
|
||||
"
|
||||
@click="handleSubmit()">
|
||||
Submit
|
||||
</button>
|
||||
|
@ -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),
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user