toask on 400

This commit is contained in:
phact 2025-09-18 16:03:37 -04:00
parent 028ea1506a
commit 0468740f3e
3 changed files with 76 additions and 0 deletions

View file

@ -11,6 +11,7 @@ import {
} from "lucide-react";
import { useRouter } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import {
Dialog,
@ -294,6 +295,11 @@ export function KnowledgeDropdown({
window.dispatchEvent(new CustomEvent("knowledgeUpdated"));
} else {
console.error("Folder upload failed:", result.error);
if (response.status === 400) {
toast.error("Upload failed", {
description: result.error || "Bad request",
});
}
}
} catch (error) {
console.error("Folder upload error:", error);
@ -333,6 +339,11 @@ export function KnowledgeDropdown({
window.dispatchEvent(new CustomEvent("knowledgeUpdated"));
} else {
console.error("S3 upload failed:", result.error);
if (response.status === 400) {
toast.error("Upload failed", {
description: result.error || "Bad request",
});
}
}
} catch (error) {
console.error("S3 upload error:", error);

View file

@ -0,0 +1,43 @@
"use client";
import React from "react";
// Type-safe wrapper that bypasses react-markdown typing issues
interface MarkdownWrapperProps {
children: string;
remarkPlugins?: any[];
rehypePlugins?: any[];
linkTarget?: string;
components?: any;
}
const MarkdownWrapper: React.FC<MarkdownWrapperProps> = ({
children,
remarkPlugins,
rehypePlugins,
linkTarget,
components
}) => {
const [MarkdownComponent, setMarkdownComponent] = React.useState<any>(null);
React.useEffect(() => {
// Dynamically import react-markdown at runtime to avoid build-time type issues
import("react-markdown").then((mod) => {
setMarkdownComponent(() => mod.default);
});
}, []);
if (!MarkdownComponent) {
return <div>Loading markdown...</div>;
}
return React.createElement(MarkdownComponent, {
remarkPlugins,
rehypePlugins,
linkTarget,
components,
children,
});
};
export default MarkdownWrapper;

22
frontend/types/jsx.d.ts vendored Normal file
View file

@ -0,0 +1,22 @@
import React from 'react';
declare global {
namespace JSX {
interface IntrinsicElements {
[elemName: string]: any;
}
}
}
declare module 'react-markdown' {
interface ReactMarkdownProps {
children: string;
remarkPlugins?: any[];
rehypePlugins?: any[];
linkTarget?: string;
components?: any;
}
const ReactMarkdown: React.FC<ReactMarkdownProps>;
export default ReactMarkdown;
}