2024-05-01 02:22:02 -04:00
|
|
|
"use client"
|
|
|
|
|
|
|
|
import Avatar from "@/components/ui/avatar"
|
|
|
|
import { Button } from "@/components/ui/button"
|
|
|
|
import { unshareSandbox } from "@/lib/actions"
|
|
|
|
import { Loader2, X } from "lucide-react"
|
|
|
|
import { useState } from "react"
|
|
|
|
|
|
|
|
export default function SharedUser({
|
|
|
|
user,
|
|
|
|
sandboxId,
|
|
|
|
}: {
|
2024-11-10 23:40:10 -05:00
|
|
|
user: { id: string; name: string; avatarUrl: string }
|
2024-05-01 02:22:02 -04:00
|
|
|
sandboxId: string
|
|
|
|
}) {
|
|
|
|
const [loading, setLoading] = useState(false)
|
|
|
|
|
|
|
|
async function handleUnshare(id: string) {
|
|
|
|
setLoading(true)
|
|
|
|
|
|
|
|
await unshareSandbox(sandboxId, user.id)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
<div className="flex items-center">
|
2024-11-10 23:40:10 -05:00
|
|
|
<Avatar name={user.name} avatarUrl={user.avatarUrl} className="mr-2" />
|
2024-05-01 02:22:02 -04:00
|
|
|
{user.name}
|
|
|
|
</div>
|
|
|
|
<Button
|
|
|
|
disabled={loading}
|
|
|
|
onClick={() => handleUnshare(user.id)}
|
|
|
|
variant="ghost"
|
|
|
|
size="smIcon"
|
|
|
|
>
|
|
|
|
{loading ? (
|
|
|
|
<Loader2 className="animate-spin w-4 h-4" />
|
|
|
|
) : (
|
|
|
|
<X className="w-4 h-4" />
|
|
|
|
)}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|