2026-02-04 02:28:51 +05:30
|
|
|
"use client";
|
|
|
|
|
|
2026-02-06 22:51:58 +00:00
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
import { useMemo, useState } from "react";
|
2026-02-05 00:08:18 +05:30
|
|
|
import Link from "next/link";
|
2026-02-04 02:28:51 +05:30
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
|
2026-02-06 22:49:54 +00:00
|
|
|
import { SignInButton, SignedIn, SignedOut, useAuth } from "@/auth/clerk";
|
2026-02-04 02:28:51 +05:30
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
import { ApiError } from "@/api/mutator";
|
|
|
|
|
import { useCreateBoardApiV1BoardsPost } from "@/api/generated/boards/boards";
|
|
|
|
|
import {
|
|
|
|
|
type listGatewaysApiV1GatewaysGetResponse,
|
|
|
|
|
useListGatewaysApiV1GatewaysGet,
|
|
|
|
|
} from "@/api/generated/gateways/gateways";
|
2026-02-04 02:28:51 +05:30
|
|
|
import { DashboardSidebar } from "@/components/organisms/DashboardSidebar";
|
|
|
|
|
import { DashboardShell } from "@/components/templates/DashboardShell";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
2026-02-05 00:08:18 +05:30
|
|
|
import SearchableSelect from "@/components/ui/searchable-select";
|
2026-02-04 21:44:21 +05:30
|
|
|
|
2026-02-04 02:28:51 +05:30
|
|
|
const slugify = (value: string) =>
|
|
|
|
|
value
|
|
|
|
|
.toLowerCase()
|
|
|
|
|
.trim()
|
|
|
|
|
.replace(/[^a-z0-9]+/g, "-")
|
|
|
|
|
.replace(/(^-|-$)/g, "") || "board";
|
|
|
|
|
|
|
|
|
|
export default function NewBoardPage() {
|
|
|
|
|
const router = useRouter();
|
2026-02-06 16:12:04 +05:30
|
|
|
const { isSignedIn } = useAuth();
|
2026-02-04 23:07:22 +05:30
|
|
|
|
2026-02-04 02:28:51 +05:30
|
|
|
const [name, setName] = useState("");
|
2026-02-04 23:07:22 +05:30
|
|
|
const [gatewayId, setGatewayId] = useState<string>("");
|
2026-02-04 21:44:21 +05:30
|
|
|
|
2026-02-04 23:07:22 +05:30
|
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
const gatewaysQuery = useListGatewaysApiV1GatewaysGet<
|
|
|
|
|
listGatewaysApiV1GatewaysGetResponse,
|
|
|
|
|
ApiError
|
2026-02-06 19:11:11 +05:30
|
|
|
>(undefined, {
|
2026-02-06 16:12:04 +05:30
|
|
|
query: {
|
|
|
|
|
enabled: Boolean(isSignedIn),
|
|
|
|
|
refetchOnMount: "always",
|
|
|
|
|
retry: false,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const createBoardMutation = useCreateBoardApiV1BoardsPost<ApiError>({
|
|
|
|
|
mutation: {
|
|
|
|
|
onSuccess: (result) => {
|
|
|
|
|
if (result.status === 200) {
|
2026-02-06 20:23:17 +05:30
|
|
|
router.push(`/boards/${result.data.id}/edit?onboarding=1`);
|
2026-02-06 16:12:04 +05:30
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onError: (err) => {
|
|
|
|
|
setError(err.message || "Something went wrong.");
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const gateways =
|
2026-02-06 19:11:11 +05:30
|
|
|
gatewaysQuery.data?.status === 200
|
|
|
|
|
? gatewaysQuery.data.data.items ?? []
|
|
|
|
|
: [];
|
2026-02-06 16:12:04 +05:30
|
|
|
const displayGatewayId = gatewayId || gateways[0]?.id || "";
|
|
|
|
|
const isLoading = gatewaysQuery.isLoading || createBoardMutation.isPending;
|
|
|
|
|
const errorMessage = error ?? gatewaysQuery.error?.message ?? null;
|
|
|
|
|
|
|
|
|
|
const isFormReady = Boolean(name.trim() && displayGatewayId);
|
2026-02-05 00:08:18 +05:30
|
|
|
|
|
|
|
|
const gatewayOptions = useMemo(
|
|
|
|
|
() => gateways.map((gateway) => ({ value: gateway.id, label: gateway.name })),
|
|
|
|
|
[gateways]
|
|
|
|
|
);
|
2026-02-04 23:07:22 +05:30
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
2026-02-04 02:28:51 +05:30
|
|
|
event.preventDefault();
|
|
|
|
|
if (!isSignedIn) return;
|
2026-02-04 23:07:22 +05:30
|
|
|
const trimmedName = name.trim();
|
2026-02-06 16:12:04 +05:30
|
|
|
const resolvedGatewayId = displayGatewayId;
|
2026-02-04 23:07:22 +05:30
|
|
|
if (!trimmedName) {
|
|
|
|
|
setError("Board name is required.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-06 16:12:04 +05:30
|
|
|
if (!resolvedGatewayId) {
|
2026-02-04 23:07:22 +05:30
|
|
|
setError("Select a gateway before creating a board.");
|
2026-02-04 21:44:21 +05:30
|
|
|
return;
|
|
|
|
|
}
|
2026-02-04 23:07:22 +05:30
|
|
|
|
2026-02-04 02:28:51 +05:30
|
|
|
setError(null);
|
2026-02-04 23:07:22 +05:30
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
createBoardMutation.mutate({
|
|
|
|
|
data: {
|
2026-02-04 23:07:22 +05:30
|
|
|
name: trimmedName,
|
|
|
|
|
slug: slugify(trimmedName),
|
2026-02-06 16:12:04 +05:30
|
|
|
gateway_id: resolvedGatewayId,
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-02-04 02:28:51 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<DashboardShell>
|
|
|
|
|
<SignedOut>
|
2026-02-04 21:44:21 +05:30
|
|
|
<div className="col-span-2 flex min-h-[calc(100vh-64px)] items-center justify-center bg-slate-50 p-10 text-center">
|
|
|
|
|
<div className="rounded-xl border border-slate-200 bg-white px-8 py-6 shadow-sm">
|
|
|
|
|
<p className="text-sm text-slate-600">Sign in to create a board.</p>
|
|
|
|
|
<SignInButton
|
|
|
|
|
mode="modal"
|
|
|
|
|
forceRedirectUrl="/boards/new"
|
|
|
|
|
signUpForceRedirectUrl="/boards/new"
|
|
|
|
|
>
|
|
|
|
|
<Button className="mt-4">Sign in</Button>
|
|
|
|
|
</SignInButton>
|
|
|
|
|
</div>
|
2026-02-04 02:28:51 +05:30
|
|
|
</div>
|
|
|
|
|
</SignedOut>
|
|
|
|
|
<SignedIn>
|
|
|
|
|
<DashboardSidebar />
|
2026-02-04 21:44:21 +05:30
|
|
|
<main className="flex-1 overflow-y-auto bg-slate-50">
|
|
|
|
|
<div className="border-b border-slate-200 bg-white px-8 py-6">
|
|
|
|
|
<div>
|
|
|
|
|
<h1 className="font-heading text-2xl font-semibold text-slate-900 tracking-tight">
|
|
|
|
|
Create board
|
|
|
|
|
</h1>
|
|
|
|
|
<p className="mt-1 text-sm text-slate-500">
|
2026-02-04 23:07:22 +05:30
|
|
|
Boards organize tasks and agents by mission context.
|
2026-02-04 16:04:52 +05:30
|
|
|
</p>
|
|
|
|
|
</div>
|
2026-02-04 21:44:21 +05:30
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="p-8">
|
|
|
|
|
<form
|
|
|
|
|
onSubmit={handleSubmit}
|
2026-02-04 23:07:22 +05:30
|
|
|
className="space-y-6 rounded-xl border border-slate-200 bg-white p-6 shadow-sm"
|
2026-02-04 02:28:51 +05:30
|
|
|
>
|
2026-02-04 23:07:22 +05:30
|
|
|
<div className="space-y-4">
|
|
|
|
|
<div className="grid gap-6 md:grid-cols-2">
|
2026-02-04 21:44:21 +05:30
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label className="text-sm font-medium text-slate-900">
|
2026-02-04 23:07:22 +05:30
|
|
|
Board name <span className="text-red-500">*</span>
|
2026-02-04 21:44:21 +05:30
|
|
|
</label>
|
|
|
|
|
<Input
|
2026-02-04 23:07:22 +05:30
|
|
|
value={name}
|
|
|
|
|
onChange={(event) => setName(event.target.value)}
|
|
|
|
|
placeholder="e.g. Release operations"
|
2026-02-04 21:44:21 +05:30
|
|
|
disabled={isLoading}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label className="text-sm font-medium text-slate-900">
|
2026-02-04 23:07:22 +05:30
|
|
|
Gateway <span className="text-red-500">*</span>
|
2026-02-04 21:44:21 +05:30
|
|
|
</label>
|
2026-02-05 00:08:18 +05:30
|
|
|
<SearchableSelect
|
|
|
|
|
ariaLabel="Select gateway"
|
2026-02-06 16:12:04 +05:30
|
|
|
value={displayGatewayId}
|
2026-02-05 00:08:18 +05:30
|
|
|
onValueChange={setGatewayId}
|
|
|
|
|
options={gatewayOptions}
|
|
|
|
|
placeholder="Select gateway"
|
|
|
|
|
searchPlaceholder="Search gateways..."
|
|
|
|
|
emptyMessage="No gateways found."
|
|
|
|
|
triggerClassName="w-full h-11 rounded-xl border border-slate-300 bg-white px-3 py-2 text-sm font-medium text-slate-900 shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-200"
|
|
|
|
|
contentClassName="rounded-xl border border-slate-200 shadow-lg"
|
|
|
|
|
itemClassName="px-4 py-3 text-sm text-slate-700 data-[selected=true]:bg-slate-50 data-[selected=true]:text-slate-900"
|
|
|
|
|
/>
|
2026-02-04 21:44:21 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-04 23:07:22 +05:30
|
|
|
|
2026-02-04 21:44:21 +05:30
|
|
|
</div>
|
|
|
|
|
|
2026-02-05 00:08:18 +05:30
|
|
|
{gateways.length === 0 ? (
|
|
|
|
|
<div className="rounded-lg border border-slate-200 bg-slate-50 px-4 py-3 text-sm text-slate-600">
|
|
|
|
|
<p>
|
|
|
|
|
No gateways available. Create one in{" "}
|
|
|
|
|
<Link
|
|
|
|
|
href="/gateways"
|
|
|
|
|
className="font-medium text-blue-600 hover:text-blue-700"
|
|
|
|
|
>
|
|
|
|
|
Gateways
|
|
|
|
|
</Link>{" "}
|
|
|
|
|
to continue.
|
2026-02-04 23:07:22 +05:30
|
|
|
</p>
|
|
|
|
|
</div>
|
2026-02-05 00:08:18 +05:30
|
|
|
) : null}
|
2026-02-04 21:44:21 +05:30
|
|
|
|
2026-02-06 16:12:04 +05:30
|
|
|
{errorMessage ? (
|
|
|
|
|
<p className="text-sm text-red-500">{errorMessage}</p>
|
|
|
|
|
) : null}
|
2026-02-04 21:44:21 +05:30
|
|
|
|
2026-02-04 23:07:22 +05:30
|
|
|
<div className="flex justify-end gap-3">
|
2026-02-04 21:44:21 +05:30
|
|
|
<Button
|
|
|
|
|
type="button"
|
2026-02-04 23:07:22 +05:30
|
|
|
variant="ghost"
|
|
|
|
|
onClick={() => router.push("/boards")}
|
|
|
|
|
disabled={isLoading}
|
2026-02-04 21:44:21 +05:30
|
|
|
>
|
2026-02-04 23:07:22 +05:30
|
|
|
Cancel
|
|
|
|
|
</Button>
|
2026-02-05 00:08:18 +05:30
|
|
|
<Button type="submit" disabled={isLoading || !isFormReady}>
|
2026-02-04 23:07:22 +05:30
|
|
|
{isLoading ? "Creating…" : "Create board"}
|
2026-02-04 21:44:21 +05:30
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
2026-02-04 02:28:51 +05:30
|
|
|
</SignedIn>
|
|
|
|
|
</DashboardShell>
|
|
|
|
|
);
|
|
|
|
|
}
|