mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
94 lines
3.1 KiB
React
94 lines
3.1 KiB
React
// ─── components/Dialogs/UnbanDialog.jsx ───────────────────────────────────────
|
|
import { useState } from "react";
|
|
import {
|
|
Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter,
|
|
} from "@/components/ui/dialog";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Label } from "@/components/ui/label";
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
import { Spinner } from "@/components/ui/spinner";
|
|
|
|
/**
|
|
* Unban dialog — single or bulk.
|
|
*
|
|
* Single: <UnbanDialog entity={rowObject} getName={(r) => r.name} ... />
|
|
* Bulk: <UnbanDialog ids={[1, 2, 3]} entityLabel="User" ... />
|
|
*
|
|
* @param {Function} onUnban (payload) => Promise — { lift_reason? }
|
|
*/
|
|
export function UnbanDialog({
|
|
open,
|
|
onOpenChange,
|
|
entity,
|
|
ids,
|
|
entityLabel = "User",
|
|
getName,
|
|
onUnban,
|
|
loading,
|
|
onSuccess,
|
|
}) {
|
|
const [liftReason, setLiftReason] = useState("");
|
|
|
|
const isBulk = Array.isArray(ids) && ids.length > 0;
|
|
const count = isBulk ? ids.length : 1;
|
|
const displayName = isBulk
|
|
? `${count} selected ${entityLabel.toLowerCase()}${count !== 1 ? "s" : ""}`
|
|
: (getName?.(entity) ?? entity?.personal_info?.name?.full_name ?? entity?.email ?? "this user");
|
|
|
|
const handleSubmit = async () => {
|
|
const res = await onUnban({ lift_reason: liftReason.trim() || undefined });
|
|
if (res) {
|
|
setLiftReason("");
|
|
onOpenChange(false);
|
|
onSuccess?.();
|
|
}
|
|
};
|
|
|
|
const handleOpenChange = (v) => {
|
|
if (!v) setLiftReason("");
|
|
onOpenChange(v);
|
|
};
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
|
<DialogContent className="sm:max-w-md">
|
|
<DialogHeader>
|
|
<DialogTitle>Unban {isBulk ? `${count} ${entityLabel}${count !== 1 ? "s" : ""}` : entityLabel}</DialogTitle>
|
|
<DialogDescription>
|
|
Remove the ban on{" "}
|
|
<span className="font-medium text-foreground">{displayName}</span>.
|
|
They will regain access to the platform immediately.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<div className="flex flex-col gap-1.5 py-2">
|
|
<Label htmlFor="lift-reason">
|
|
Lift Reason <span className="text-muted-foreground text-xs">(optional)</span>
|
|
</Label>
|
|
<Textarea
|
|
id="lift-reason"
|
|
placeholder="Reason for lifting this ban…"
|
|
rows={3}
|
|
value={liftReason}
|
|
onChange={(e) => setLiftReason(e.target.value)}
|
|
/>
|
|
</div>
|
|
|
|
<DialogFooter>
|
|
<Button variant="outline" onClick={() => handleOpenChange(false)} disabled={loading}>
|
|
Cancel
|
|
</Button>
|
|
<Button
|
|
className="bg-emerald-600 text-white hover:bg-emerald-700"
|
|
onClick={handleSubmit}
|
|
disabled={loading}
|
|
>
|
|
{loading && <Spinner className="size-4 mr-2" />}
|
|
Unban {isBulk ? `${count} ${entityLabel}${count !== 1 ? "s" : ""}` : entityLabel}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|