42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useActionState } from "react";
|
|
import { addFriendAction, type AddFriendState } from "./actions";
|
|
|
|
const initialState: AddFriendState = null;
|
|
|
|
export function AddFriendForm() {
|
|
const [state, action, pending] = useActionState(addFriendAction, initialState);
|
|
|
|
return (
|
|
<form action={action} className="space-y-3">
|
|
<label htmlFor="userId" className="block text-sm font-medium text-neutral-700">
|
|
Add by User ID
|
|
</label>
|
|
<div className="flex gap-2">
|
|
<input
|
|
id="userId"
|
|
name="userId"
|
|
type="text"
|
|
placeholder="e.g. 3b241101-e2bb-..."
|
|
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 ? "Sending..." : "Add"}
|
|
</button>
|
|
</div>
|
|
{state?.error && (
|
|
<p className="text-sm text-red-600">{state.error}</p>
|
|
)}
|
|
{state?.success && (
|
|
<p className="text-sm text-emerald-600">Friend request sent!</p>
|
|
)}
|
|
</form>
|
|
);
|
|
}
|