Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/controllers/admin/reel_payouts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ def index
}
end

def payout_all
requests = ReelPayoutRequest.pending.includes(reel: :user)
approved_count = 0
requests.each do |req|
if req.approve!(current_user)
audit!("reel_payout.approved", target: req.reel, label: "##{req.reel_id}", metadata: { amount: req.amount.to_f, request_id: req.id })
approved_count += 1
end
end
redirect_to admin_reel_payouts_path, notice: "Approved #{approved_count} payout#{"s" if approved_count != 1}."
end

def approve
if @request.approve!(current_user)
audit!("reel_payout.approved", target: @request.reel, label: "##{@request.reel_id}", metadata: { amount: @request.amount.to_f, request_id: @request.id })
Expand Down
30 changes: 29 additions & 1 deletion app/javascript/pages/Admin/StaticPages/Index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link } from '@inertiajs/react'
import { Link, useForm } from '@inertiajs/react'
import {
ArrowLeft,
Hammer,
Expand All @@ -21,6 +21,7 @@ import {
DollarSign,
TableProperties,
Activity,
Coins,
} from 'lucide-react'
import type { LucideIcon } from 'lucide-react'
import { Card, CardContent } from '@/components/admin/ui/card'
Expand Down Expand Up @@ -106,6 +107,12 @@ export default function AdminStaticPagesIndex({
is_superadmin,
}: AdminDashboardProps) {
const can = (perm: string) => permissions[perm]
const payoutAllForm = useForm({})

function handlePayoutAll() {
if (!confirm('Are you sure you want to approve all pending reel payouts? This cannot be undone.')) return
payoutAllForm.post('/admin/reel_payouts/payout_all')
}

return (
<div className="max-w-6xl mx-auto space-y-8">
Expand Down Expand Up @@ -182,6 +189,27 @@ export default function AdminStaticPagesIndex({
{is_superadmin && (
<Section title="Superadmin">
<Tile href="/admin/airtable_queue" label="Airtable Queue" icon={TableProperties} />
<button
type="button"
onClick={handlePayoutAll}
disabled={payoutAllForm.processing}
className="w-full text-left"
>
<Card className="hover:bg-accent transition-colors cursor-pointer">
<CardContent className="p-4">
<div className="flex items-center gap-3">
<div className="rounded-md bg-muted p-2 text-foreground inline-flex items-center justify-center">
<Coins className="size-5" />
</div>
<div className="flex-1 min-w-0">
<div className="text-sm font-medium truncate">
{payoutAllForm.processing ? 'Processing…' : 'Payout All Reels'}
</div>
</div>
</div>
</CardContent>
</Card>
</button>
</Section>
)}
</div>
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@
end
end
resources :reel_payouts, only: [ :index ] do
collection do
post :payout_all
end
member do
post :approve
post :reject
Expand Down
Loading