Files
Fastchat/app/(auth)/rooms/add-member-form.tsx
T

44 lines
1.5 KiB
TypeScript

"use client";
import { useActionState } from "react";
import { addMemberAction, type AddMemberState } from "./actions";
const initialState: AddMemberState = null;
export function AddMemberForm({ roomId }: Readonly<{ roomId: string }>) {
const boundAction = addMemberAction.bind(null, roomId);
const [state, action, pending] = useActionState(boundAction, initialState);
return (
<form action={action} className="space-y-3">
<label
htmlFor="addMemberId"
className="block text-sm font-medium text-neutral-700"
>
Add Member
</label>
<div className="flex gap-2">
<input
id="addMemberId"
name="userId"
type="text"
placeholder="User ID (UUID)"
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 ? "Adding..." : "Add"}
</button>
</div>
{state?.error && <p className="text-sm text-red-600">{state.error}</p>}
{state?.success && (
<p className="text-sm text-emerald-600">Member added!</p>
)}
</form>
);
}