Skip to content

Commit 46cdcff

Browse files
authored
Add payout all reels button to admin dashboard (#228)
1 parent c6ab01c commit 46cdcff

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

app/controllers/admin/reel_payouts_controller.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ def index
1212
}
1313
end
1414

15+
def payout_all
16+
requests = ReelPayoutRequest.pending.includes(reel: :user)
17+
approved_count = 0
18+
requests.each do |req|
19+
if req.approve!(current_user)
20+
audit!("reel_payout.approved", target: req.reel, label: "##{req.reel_id}", metadata: { amount: req.amount.to_f, request_id: req.id })
21+
approved_count += 1
22+
end
23+
end
24+
redirect_to admin_reel_payouts_path, notice: "Approved #{approved_count} payout#{"s" if approved_count != 1}."
25+
end
26+
1527
def approve
1628
if @request.approve!(current_user)
1729
audit!("reel_payout.approved", target: @request.reel, label: "##{@request.reel_id}", metadata: { amount: @request.amount.to_f, request_id: @request.id })

app/javascript/pages/Admin/StaticPages/Index.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Link } from '@inertiajs/react'
1+
import { Link, useForm } from '@inertiajs/react'
22
import {
33
ArrowLeft,
44
Hammer,
@@ -21,6 +21,7 @@ import {
2121
DollarSign,
2222
TableProperties,
2323
Activity,
24+
Coins,
2425
} from 'lucide-react'
2526
import type { LucideIcon } from 'lucide-react'
2627
import { Card, CardContent } from '@/components/admin/ui/card'
@@ -106,6 +107,12 @@ export default function AdminStaticPagesIndex({
106107
is_superadmin,
107108
}: AdminDashboardProps) {
108109
const can = (perm: string) => permissions[perm]
110+
const payoutAllForm = useForm({})
111+
112+
function handlePayoutAll() {
113+
if (!confirm('Are you sure you want to approve all pending reel payouts? This cannot be undone.')) return
114+
payoutAllForm.post('/admin/reel_payouts/payout_all')
115+
}
109116

110117
return (
111118
<div className="max-w-6xl mx-auto space-y-8">
@@ -182,6 +189,27 @@ export default function AdminStaticPagesIndex({
182189
{is_superadmin && (
183190
<Section title="Superadmin">
184191
<Tile href="/admin/airtable_queue" label="Airtable Queue" icon={TableProperties} />
192+
<button
193+
type="button"
194+
onClick={handlePayoutAll}
195+
disabled={payoutAllForm.processing}
196+
className="w-full text-left"
197+
>
198+
<Card className="hover:bg-accent transition-colors cursor-pointer">
199+
<CardContent className="p-4">
200+
<div className="flex items-center gap-3">
201+
<div className="rounded-md bg-muted p-2 text-foreground inline-flex items-center justify-center">
202+
<Coins className="size-5" />
203+
</div>
204+
<div className="flex-1 min-w-0">
205+
<div className="text-sm font-medium truncate">
206+
{payoutAllForm.processing ? 'Processing…' : 'Payout All Reels'}
207+
</div>
208+
</div>
209+
</div>
210+
</CardContent>
211+
</Card>
212+
</button>
185213
</Section>
186214
)}
187215
</div>

config/routes.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@
287287
end
288288
end
289289
resources :reel_payouts, only: [ :index ] do
290+
collection do
291+
post :payout_all
292+
end
290293
member do
291294
post :approve
292295
post :reject

0 commit comments

Comments
 (0)