mirror of https://github.com/kortix-ai/suna.git
remove adjustment form from frontend
This commit is contained in:
parent
87d0eeb62f
commit
db6953b4dc
|
@ -55,7 +55,19 @@ async def adjust_user_credits(
|
|||
description=f"Admin adjustment: {request.reason}",
|
||||
expires_at=datetime.now(timezone.utc) + timedelta(days=30) if request.is_expiring else None
|
||||
)
|
||||
new_balance = result['total_balance']
|
||||
if result.get('duplicate_prevented'):
|
||||
logger.info(f"[ADMIN] Duplicate credit adjustment prevented for {request.account_id}")
|
||||
balance_info = await credit_manager.get_balance(request.account_id)
|
||||
return {
|
||||
'success': True,
|
||||
'message': 'Credit adjustment already processed (duplicate prevented)',
|
||||
'new_balance': float(balance_info.get('total', 0)),
|
||||
'adjustment_amount': float(request.amount),
|
||||
'is_expiring': request.is_expiring,
|
||||
'duplicate_prevented': True
|
||||
}
|
||||
else:
|
||||
new_balance = result.get('total_balance', 0)
|
||||
else:
|
||||
result = await credit_manager.use_credits(
|
||||
account_id=request.account_id,
|
||||
|
@ -113,10 +125,15 @@ async def grant_credits_to_users(
|
|||
description=f"Admin grant: {request.reason}",
|
||||
expires_at=datetime.now(timezone.utc) + timedelta(days=30) if request.is_expiring else None
|
||||
)
|
||||
if result.get('duplicate_prevented'):
|
||||
balance_info = await credit_manager.get_balance(account_id)
|
||||
new_balance = balance_info.get('total', 0)
|
||||
else:
|
||||
new_balance = result.get('total_balance', 0)
|
||||
results.append({
|
||||
'account_id': account_id,
|
||||
'success': True,
|
||||
'new_balance': result['total_balance']
|
||||
'new_balance': new_balance
|
||||
})
|
||||
except Exception as e:
|
||||
results.append({
|
||||
|
@ -150,6 +167,12 @@ async def process_refund(
|
|||
type='admin_grant'
|
||||
)
|
||||
|
||||
if result.get('duplicate_prevented'):
|
||||
balance_info = await credit_manager.get_balance(request.account_id)
|
||||
new_balance = balance_info.get('total_balance', 0)
|
||||
else:
|
||||
new_balance = result.get('total_balance', 0)
|
||||
|
||||
refund_id = None
|
||||
if request.stripe_refund and request.payment_intent_id:
|
||||
try:
|
||||
|
@ -168,7 +191,7 @@ async def process_refund(
|
|||
|
||||
return {
|
||||
'success': True,
|
||||
'new_balance': float(result['total_balance']),
|
||||
'new_balance': float(new_balance),
|
||||
'refund_amount': float(request.amount),
|
||||
'stripe_refund_id': refund_id,
|
||||
'is_expiring': request.is_expiring
|
||||
|
|
|
@ -361,85 +361,7 @@ export function AdminUserDetailsDialog({
|
|||
</TabsContent>
|
||||
|
||||
<TabsContent value="actions" className="space-y-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<DollarSign className="h-4 w-4" />
|
||||
Adjust Credits
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="p-3 border border-amber-200 bg-amber-50 rounded-lg">
|
||||
<div className="flex items-start gap-2">
|
||||
<AlertCircle className="h-4 w-4 text-amber-600 mt-0.5" />
|
||||
<p className="text-sm text-amber-700">
|
||||
Use positive amounts to add credits, negative to deduct.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="adjust-amount">Amount (USD)</Label>
|
||||
<Input
|
||||
id="adjust-amount"
|
||||
type="number"
|
||||
step="0.01"
|
||||
placeholder="10.00"
|
||||
value={adjustAmount}
|
||||
onChange={(e) => setAdjustAmount(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="adjust-reason">Reason</Label>
|
||||
<Textarea
|
||||
id="adjust-reason"
|
||||
placeholder="Customer support ticket #123 - Billing dispute resolution"
|
||||
value={adjustReason}
|
||||
onChange={(e) => setAdjustReason(e.target.value)}
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center justify-between p-3 border rounded-lg bg-muted/50">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label htmlFor="adjust-expiring" className="cursor-pointer flex items-center gap-2">
|
||||
{adjustIsExpiring ? (
|
||||
<Clock className="h-4 w-4 text-orange-500" />
|
||||
) : (
|
||||
<Infinity className="h-4 w-4 text-blue-500" />
|
||||
)}
|
||||
<span className="font-medium">
|
||||
{adjustIsExpiring ? 'Expiring Credits' : 'Non-Expiring Credits'}
|
||||
</span>
|
||||
</Label>
|
||||
</div>
|
||||
<Switch
|
||||
id="adjust-expiring"
|
||||
checked={!adjustIsExpiring}
|
||||
onCheckedChange={(checked) => setAdjustIsExpiring(!checked)}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground -mt-2">
|
||||
{adjustIsExpiring
|
||||
? 'Credits will expire at the end of the billing cycle (30 days)'
|
||||
: 'Credits will never expire and remain until used'}
|
||||
</p>
|
||||
|
||||
<Button
|
||||
onClick={handleAdjustCredits}
|
||||
disabled={adjustCreditsMutation.isPending}
|
||||
className="w-full"
|
||||
>
|
||||
{adjustCreditsMutation.isPending ? (
|
||||
<>
|
||||
<RefreshCw className="w-4 h-4 animate-spin" />
|
||||
Processing...
|
||||
</>
|
||||
) : (
|
||||
'Apply Adjustment'
|
||||
)}
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<div className="grid grid-cols-1 gap-4">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
|
@ -448,7 +370,7 @@ export function AdminUserDetailsDialog({
|
|||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="p-3 border border-red-200 bg-red-50 rounded-lg">
|
||||
<div className="p-3 border border-red-200 dark:border-red-950 bg-red-50 dark:bg-red-950/20 rounded-lg">
|
||||
<div className="flex items-start gap-2">
|
||||
<AlertCircle className="h-4 w-4 text-red-600 mt-0.5" />
|
||||
<p className="text-sm text-red-700">
|
||||
|
@ -468,7 +390,7 @@ export function AdminUserDetailsDialog({
|
|||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="refund-reason">Refund Reason</Label>
|
||||
<Label htmlFor="refund-reason mb-2">Refund Reason</Label>
|
||||
<Textarea
|
||||
id="refund-reason"
|
||||
placeholder="Service outage compensation"
|
||||
|
|
Loading…
Reference in New Issue