mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-26 23:51:14 +02:00
- Updated all hooks to import and use AUTH_TOKEN_KEY constant from lib/constants - Updated all components to use AUTH_TOKEN_KEY instead of hardcoded string - Updated all atoms to use AUTH_TOKEN_KEY - Updated all app pages to use AUTH_TOKEN_KEY - Made CORS origin configurable via CORS_ORIGINS environment variable - Added CORS_ORIGINS to .env.example with documentation This improves maintainability by centralizing the auth token key string, preventing typos and making it easier to change the key name if needed.
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { motion } from "motion/react";
|
|
import { useRouter } from "next/navigation";
|
|
import { toast } from "sonner";
|
|
import { SearchSpaceForm } from "@/components/search-space-form";
|
|
import { AUTH_TOKEN_KEY } from "@/lib/constants";
|
|
export default function SearchSpacesPage() {
|
|
const router = useRouter();
|
|
const handleCreateSearchSpace = async (data: { name: string; description: string }) => {
|
|
try {
|
|
const response = await fetch(
|
|
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/searchspaces`,
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
Authorization: `Bearer ${localStorage.getItem(AUTH_TOKEN_KEY)}`,
|
|
},
|
|
body: JSON.stringify(data),
|
|
}
|
|
);
|
|
|
|
if (!response.ok) {
|
|
toast.error("Failed to create search space");
|
|
throw new Error("Failed to create search space");
|
|
}
|
|
|
|
const result = await response.json();
|
|
|
|
toast.success("Search space created successfully", {
|
|
description: `"${data.name}" has been created.`,
|
|
});
|
|
|
|
router.push(`/dashboard`);
|
|
|
|
return result;
|
|
} catch (error) {
|
|
console.error("Error creating search space:", error);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
return (
|
|
<motion.div
|
|
className="container mx-auto py-10"
|
|
initial={{ opacity: 0 }}
|
|
animate={{ opacity: 1 }}
|
|
transition={{ duration: 0.5 }}
|
|
>
|
|
<div className="mx-auto max-w-5xl">
|
|
<SearchSpaceForm onSubmit={handleCreateSearchSpace} />
|
|
</div>
|
|
</motion.div>
|
|
);
|
|
}
|