|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useState } from "react"; |
| 4 | +import { useMutation } from "@tanstack/react-query"; |
| 5 | +import { Button } from "@clawe/ui/components/button"; |
| 6 | +import { Input } from "@clawe/ui/components/input"; |
| 7 | +import { Label } from "@clawe/ui/components/label"; |
| 8 | +import { Progress } from "@clawe/ui/components/progress"; |
| 9 | +import { Spinner } from "@clawe/ui/components/spinner"; |
| 10 | +import { saveConfig } from "@/lib/api/config"; |
| 11 | + |
| 12 | +const TOTAL_STEPS = 5; |
| 13 | +const CURRENT_STEP = 2; |
| 14 | + |
| 15 | +export default function ConvexSetupPage() { |
| 16 | + const [convexUrl, setConvexUrl] = useState(""); |
| 17 | + |
| 18 | + const mutation = useMutation({ |
| 19 | + mutationFn: saveConfig, |
| 20 | + onSuccess: (data) => { |
| 21 | + if (data.ok) { |
| 22 | + // Hard redirect to reinitialize ConvexProvider with new URL |
| 23 | + window.location.href = "/setup/provider"; |
| 24 | + } |
| 25 | + }, |
| 26 | + }); |
| 27 | + |
| 28 | + const handleSubmit = (e: React.FormEvent) => { |
| 29 | + e.preventDefault(); |
| 30 | + mutation.mutate(convexUrl); |
| 31 | + }; |
| 32 | + |
| 33 | + const error = |
| 34 | + mutation.error?.message ?? |
| 35 | + (mutation.data && !mutation.data.ok ? mutation.data.error : null); |
| 36 | + |
| 37 | + return ( |
| 38 | + <div className="flex flex-col"> |
| 39 | + {/* Progress indicator */} |
| 40 | + <div className="mb-12"> |
| 41 | + <Progress |
| 42 | + value={(CURRENT_STEP / TOTAL_STEPS) * 100} |
| 43 | + className="h-1 w-64" |
| 44 | + indicatorClassName="bg-brand" |
| 45 | + /> |
| 46 | + </div> |
| 47 | + |
| 48 | + {/* Header */} |
| 49 | + <h1 className="mb-3 text-3xl font-semibold tracking-tight"> |
| 50 | + Connect to Convex |
| 51 | + </h1> |
| 52 | + <p className="text-muted-foreground mb-8"> |
| 53 | + Enter your Convex deployment URL to store your data. |
| 54 | + </p> |
| 55 | + |
| 56 | + {/* Form */} |
| 57 | + <form onSubmit={handleSubmit} className="space-y-6"> |
| 58 | + <div className="space-y-2"> |
| 59 | + <Label htmlFor="convex-url">Deployment URL</Label> |
| 60 | + <Input |
| 61 | + id="convex-url" |
| 62 | + type="url" |
| 63 | + placeholder="https://your-project.convex.cloud" |
| 64 | + value={convexUrl} |
| 65 | + onChange={(e) => setConvexUrl(e.target.value)} |
| 66 | + required |
| 67 | + /> |
| 68 | + <p className="text-muted-foreground text-sm"> |
| 69 | + Find this in your{" "} |
| 70 | + <a |
| 71 | + href="https://dashboard.convex.dev" |
| 72 | + target="_blank" |
| 73 | + rel="noopener noreferrer" |
| 74 | + className="underline" |
| 75 | + > |
| 76 | + Convex dashboard |
| 77 | + </a>{" "} |
| 78 | + under Settings → URL & Deploy Key |
| 79 | + </p> |
| 80 | + </div> |
| 81 | + |
| 82 | + {error && <p className="text-destructive text-sm">{error}</p>} |
| 83 | + |
| 84 | + <Button |
| 85 | + type="submit" |
| 86 | + size="lg" |
| 87 | + variant="brand" |
| 88 | + className="w-full sm:w-auto" |
| 89 | + disabled={!convexUrl || mutation.isPending} |
| 90 | + > |
| 91 | + {mutation.isPending ? ( |
| 92 | + <> |
| 93 | + <Spinner /> |
| 94 | + Connecting... |
| 95 | + </> |
| 96 | + ) : ( |
| 97 | + "Continue" |
| 98 | + )} |
| 99 | + </Button> |
| 100 | + </form> |
| 101 | + </div> |
| 102 | + ); |
| 103 | +} |
0 commit comments