import { Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Input, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, ToggleGroup, ToggleGroupItem, } from "@/components/ui"; import { useLoginMutation } from "@/services/db"; import { useSessionStore } from "@/state/db-session-store"; import { createFileRoute } from "@tanstack/react-router"; import { type FormEventHandler, useState } from "react"; import { toast } from "sonner"; export const Route = createFileRoute("/auth/login")({ component: LoginForm, }); function DatabaseTypeSelector() { return (
); } function LoginForm() { const [connectionMethod, setConnectionMethod] = useState("connectionString"); const { mutateAsync } = useLoginMutation(); const addSession = useSessionStore.use.addSession(); const handleSubmit: FormEventHandler = async (e) => { e.preventDefault(); const formData = new FormData(e.currentTarget); const connectionString = formData.get("connectionString"); const type = formData.get("type"); if (connectionMethod === "connectionString") { if ( connectionString != null && typeof connectionString === "string" && type != null && typeof type === "string" ) { try { await mutateAsync({ connectionString, type }); addSession({ connectionString, type }); } catch (error) { console.log(error); toast.error("Invalid connection string"); return; } } else { toast.error("Please fill all fields"); } return; } const username = formData.get("username"); const password = formData.get("password"); const host = formData.get("host"); const port = formData.get("port"); const database = formData.get("database"); const ssl = formData.get("ssl"); if ( database == null || host == null || password == null || port == null || ssl == null || type == null || username == null ) { toast.error("Please fill all fields"); return; } if ( typeof database !== "string" || typeof host !== "string" || typeof password !== "string" || typeof port !== "string" || typeof ssl !== "string" || typeof type !== "string" || typeof username !== "string" ) { return; } try { await mutateAsync({ username, password, host, type, port, database, ssl, }); addSession({ username, password, host, type, port, database, ssl }); } catch (error) { console.log(error); toast.error("Invalid connection string"); return; } }; return (
Login Enter your database credentials below.
Fields Connection string {connectionMethod === "fields" ? ( <>
) : (
)}
); }