feat: Implement a new dashboard layout with sidebar, introduce project and data source management, and add various UI components.
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
import { useAuthActions } from "@convex-dev/auth/react";
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
|
||||
export function SignIn() {
|
||||
const { signIn } = useAuthActions();
|
||||
const router = useRouter();
|
||||
const [step, setStep] = useState<"signIn" | "signUp">("signIn");
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
@@ -14,45 +21,87 @@ export function SignIn() {
|
||||
try {
|
||||
const flow = step === "signIn" ? "signIn" : "signUp";
|
||||
await signIn("password", { email, password, flow });
|
||||
} catch (err) {
|
||||
setError("Error signing in");
|
||||
if (flow === "signIn") {
|
||||
router.push("/dashboard");
|
||||
} else {
|
||||
router.push("/onboarding");
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
const errorMessage = err.message || "Error signing in. Please check your credentials.";
|
||||
if (errorMessage.includes("Account") && errorMessage.includes("already exists")) {
|
||||
setError("Account already exists. Please sign in instead.");
|
||||
} else {
|
||||
setError(errorMessage);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 p-4 border rounded-lg max-w-sm mx-auto mt-10 bg-white shadow-sm text-black">
|
||||
<h2 className="text-xl font-bold text-center">{step === "signIn" ? "Sign In" : "Sign Up"}</h2>
|
||||
{error && <div className="text-red-500 text-sm text-center">{error}</div>}
|
||||
<form onSubmit={handleSubmit} className="flex flex-col gap-3">
|
||||
<input
|
||||
type="email"
|
||||
placeholder="Email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
className="border p-2 rounded outline-none focus:ring-2 focus:ring-blue-500"
|
||||
required
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
className="border p-2 rounded outline-none focus:ring-2 focus:ring-blue-500"
|
||||
required
|
||||
minLength={8}
|
||||
/>
|
||||
<button type="submit" className="bg-blue-600 hover:bg-blue-700 text-white p-2 rounded font-medium transition-colors">
|
||||
{step === "signIn" ? "Sign In" : "Sign Up"}
|
||||
</button>
|
||||
</form>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setStep(step === "signIn" ? "signUp" : "signIn")}
|
||||
className="text-sm text-gray-500 hover:text-gray-700 hover:underline text-center"
|
||||
>
|
||||
{step === "signIn" ? "Don't have an account? Sign up" : "Already have an account? Sign in"}
|
||||
</button>
|
||||
</div>
|
||||
<Card className="w-full max-w-md mx-auto mt-20 shadow-lg">
|
||||
<CardHeader className="space-y-1">
|
||||
<CardTitle className="text-2xl font-bold text-center">
|
||||
{step === "signIn" ? "Welcome back" : "Create an account"}
|
||||
</CardTitle>
|
||||
<CardDescription className="text-center">
|
||||
{step === "signIn"
|
||||
? "Enter your email to sign in to your account"
|
||||
: "Enter your email below to create your account"}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{error && (
|
||||
<div className="bg-destructive/15 text-destructive text-sm p-3 rounded-md text-center">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="email">Email</Label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
placeholder="m@example.com"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="password">Password</Label>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
required
|
||||
minLength={8}
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" className="w-full">
|
||||
{step === "signIn" ? "Sign In" : "Sign Up"}
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
<CardFooter className="flex flex-col gap-4">
|
||||
<div className="relative w-full">
|
||||
<div className="absolute inset-0 flex items-center">
|
||||
<span className="w-full border-t" />
|
||||
</div>
|
||||
<div className="relative flex justify-center text-xs uppercase">
|
||||
<span className="bg-background px-2 text-muted-foreground">
|
||||
Or
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
variant="link"
|
||||
onClick={() => setStep(step === "signIn" ? "signUp" : "signIn")}
|
||||
className="w-full"
|
||||
>
|
||||
{step === "signIn" ? "Don't have an account? Sign up" : "Already have an account? Sign in"}
|
||||
</Button>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user