feat: allow premium+ users to manage costs
Build & Push Docker Image / build (push) Successful in 2m19s
Build & Push Docker Image / build (push) Successful in 2m19s
- costs routes drop requireAdmin, keep auth + costs feature check
- useAuth exposes hasFeature(feature) based on entitlements
- tool-detail costs section gated by hasFeature('costs') instead of isAdmin
This commit is contained in:
@@ -22,6 +22,12 @@ export function useAuth() {
|
||||
const isLocalMode = authMode?.mode === "local";
|
||||
const tier = isAuthenticated ? user?.tier ?? "free" : "free";
|
||||
|
||||
function hasFeature(feature: string): boolean {
|
||||
if (!isAuthenticated) return false;
|
||||
if (user?.role === "admin") return true;
|
||||
return !!user?.entitlements?.includes(feature);
|
||||
}
|
||||
|
||||
function login(returnTo?: string) {
|
||||
if (isLocalMode) {
|
||||
const path = returnTo
|
||||
@@ -47,6 +53,7 @@ export function useAuth() {
|
||||
isAdmin,
|
||||
isLocalMode,
|
||||
tier,
|
||||
hasFeature,
|
||||
login,
|
||||
logout,
|
||||
};
|
||||
|
||||
@@ -74,7 +74,8 @@ export default function ToolDetail() {
|
||||
const [isReviewFormOpen, setIsReviewFormOpen] = useState(false);
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
|
||||
const { user, isAdmin } = useAuth();
|
||||
const { user, isAdmin, hasFeature } = useAuth();
|
||||
const canManageCosts = hasFeature("costs");
|
||||
const deleteTool = useDeleteTool();
|
||||
|
||||
const [similarData, setSimilarData] = useState<{ manual: any[]; auto: any[] } | null>(null);
|
||||
@@ -535,7 +536,7 @@ export default function ToolDetail() {
|
||||
<div className="space-y-4 mt-8">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-xl font-bold">Costs</h3>
|
||||
{isAdmin && (
|
||||
{canManageCosts && (
|
||||
<Button variant="outline" size="sm" onClick={() => { resetCostForm(); setCostDialogOpen(true); }} className="gap-2">
|
||||
<Plus className="w-4 h-4" /> Add Cost
|
||||
</Button>
|
||||
@@ -560,16 +561,16 @@ export default function ToolDetail() {
|
||||
</div>
|
||||
{c.notes && <p className="text-xs text-muted-foreground mt-1 italic">{c.notes}</p>}
|
||||
</div>
|
||||
{isAdmin && (
|
||||
<div className="flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => openEditCost(c)}>
|
||||
<Pencil className="w-3.5 h-3.5" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7 text-destructive" onClick={() => handleDeleteCost(c.id)}>
|
||||
<Trash2 className="w-3.5 h-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{canManageCosts && (
|
||||
<div className="flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => openEditCost(c)}>
|
||||
<Pencil className="w-3.5 h-3.5" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="icon" className="h-7 w-7 text-destructive" onClick={() => handleDeleteCost(c.id)}>
|
||||
<Trash2 className="w-3.5 h-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user