55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
"use client";
|
|
|
|
import { useTransition } from "react";
|
|
import { acceptRequestAction } from "./actions";
|
|
|
|
export interface FriendRequest {
|
|
id: string;
|
|
sender_id: string;
|
|
sender_name: string;
|
|
}
|
|
|
|
export function RequestsList({ requests }: Readonly<{ requests: FriendRequest[] }>) {
|
|
if (requests.length === 0) return null;
|
|
|
|
return (
|
|
<div>
|
|
<h2 className="text-sm font-semibold text-neutral-900">
|
|
Incoming Requests
|
|
<span className="ml-2 inline-flex size-5 items-center justify-center rounded-full bg-neutral-900 text-xs text-white">
|
|
{requests.length}
|
|
</span>
|
|
</h2>
|
|
<ul className="mt-3 divide-y divide-neutral-100 rounded-xl border border-neutral-200 bg-white">
|
|
{requests.map((req) => (
|
|
<RequestItem key={req.id} req={req} />
|
|
))}
|
|
</ul>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function RequestItem({ req }: Readonly<{ req: FriendRequest }>) {
|
|
const [pending, startTransition] = useTransition();
|
|
|
|
return (
|
|
<li className="flex items-center justify-between px-4 py-3">
|
|
<div className="flex items-center gap-3">
|
|
<div className="flex size-8 items-center justify-center rounded-full bg-neutral-100 text-xs font-medium text-neutral-600">
|
|
{req.sender_name.charAt(0).toUpperCase()}
|
|
</div>
|
|
<span className="text-sm font-medium text-neutral-900">
|
|
{req.sender_name}
|
|
</span>
|
|
</div>
|
|
<button
|
|
disabled={pending}
|
|
onClick={() => startTransition(() => acceptRequestAction(req.sender_id))}
|
|
className="rounded-lg bg-neutral-900 px-3 py-1.5 text-xs font-medium text-white transition hover:bg-neutral-800 disabled:cursor-not-allowed disabled:bg-neutral-400"
|
|
>
|
|
{pending ? "Accepting..." : "Accept"}
|
|
</button>
|
|
</li>
|
|
);
|
|
}
|