Files
Fastchat/app/(auth)/rooms/create-room-form.tsx

43 lines
1.3 KiB
TypeScript

"use client";
import { useActionState } from "react";
import { createRoomAction, type CreateRoomState } from "./actions";
const initialState: CreateRoomState = null;
export function CreateRoomForm() {
const [state, action, pending] = useActionState(
createRoomAction,
initialState,
);
return (
<form action={action} className="space-y-3">
<label
htmlFor="roomName"
className="block text-sm font-medium text-neutral-700"
>
Create a Room
</label>
<div className="flex gap-2">
<input
id="roomName"
name="name"
type="text"
placeholder="Room name"
required
className="flex-1 rounded-lg border border-neutral-300 bg-white px-3 py-2 text-sm text-neutral-900 shadow-sm placeholder:text-neutral-400 focus:border-neutral-900 focus:outline-none"
/>
<button
type="submit"
disabled={pending}
className="rounded-lg bg-neutral-900 px-4 py-2 text-sm font-medium text-white shadow-sm transition hover:bg-neutral-800 disabled:cursor-not-allowed disabled:bg-neutral-400"
>
{pending ? "Creating..." : "Create"}
</button>
</div>
{state?.error && <p className="text-sm text-red-600">{state.error}</p>}
</form>
);
}