Migrate to local PG & Update Solana Checkout
This commit is contained in:
@@ -28,10 +28,8 @@ export default function AdminLayout({
|
||||
}) {
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
const supabase = createClient();
|
||||
|
||||
const handleSignOut = async () => {
|
||||
await supabase.auth.signOut();
|
||||
await fetch('/api/auth/logout', { method: 'POST' });
|
||||
router.push('/login');
|
||||
router.refresh();
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { supabaseAdmin } from '@/lib/supabase-admin';
|
||||
import { db } from '@/lib/db';
|
||||
import {
|
||||
Search,
|
||||
Filter,
|
||||
@@ -13,49 +13,45 @@ import TransactionSearch from '@/components/admin/TransactionSearch';
|
||||
import TransactionStatusFilter from '@/components/admin/TransactionStatusFilter';
|
||||
|
||||
async function getTransactions(filters: { merchant_id?: string; q?: string; status?: string }) {
|
||||
let query = supabaseAdmin
|
||||
.from('transactions')
|
||||
.select('*, merchants(name)')
|
||||
.order('created_at', { ascending: false });
|
||||
let sql = `
|
||||
SELECT t.*, m.name as merchant_name
|
||||
FROM transactions t
|
||||
LEFT JOIN merchants m ON t.merchant_id = m.id
|
||||
WHERE 1=1
|
||||
`;
|
||||
let params: any[] = [];
|
||||
let paramIndex = 1;
|
||||
|
||||
if (filters.merchant_id) {
|
||||
query = query.eq('merchant_id', filters.merchant_id);
|
||||
sql += ` AND t.merchant_id = $${paramIndex++}`;
|
||||
params.push(filters.merchant_id);
|
||||
}
|
||||
|
||||
if (filters.status) {
|
||||
query = query.eq('status', filters.status);
|
||||
sql += ` AND t.status = $${paramIndex++}`;
|
||||
params.push(filters.status);
|
||||
}
|
||||
|
||||
if (filters.q) {
|
||||
// First, search for merchants matching the name to get their IDs
|
||||
const { data: matchedMerchants } = await supabaseAdmin
|
||||
.from('merchants')
|
||||
.select('id')
|
||||
.ilike('name', `%${filters.q}%`);
|
||||
|
||||
const merchantIds = matchedMerchants?.map(m => m.id) || [];
|
||||
|
||||
// Construct OR query parts
|
||||
let orParts = [
|
||||
`stripe_pi_id.ilike.%${filters.q}%`,
|
||||
`source_ref_id.ilike.%${filters.q}%`,
|
||||
`customer_name.ilike.%${filters.q}%`
|
||||
];
|
||||
|
||||
if (merchantIds.length > 0) {
|
||||
orParts.push(`merchant_id.in.(${merchantIds.join(',')})`);
|
||||
}
|
||||
|
||||
query = query.or(orParts.join(','));
|
||||
sql += ` AND (
|
||||
t.stripe_pi_id ILIKE $${paramIndex} OR
|
||||
t.source_ref_id ILIKE $${paramIndex} OR
|
||||
t.customer_name ILIKE $${paramIndex} OR
|
||||
m.name ILIKE $${paramIndex}
|
||||
)`;
|
||||
params.push(`%${filters.q}%`);
|
||||
paramIndex++;
|
||||
}
|
||||
|
||||
const { data, error } = await query;
|
||||
sql += ` ORDER BY t.created_at DESC`;
|
||||
|
||||
if (error) {
|
||||
try {
|
||||
const { rows } = await db.query(sql, params);
|
||||
return rows.map(r => ({ ...r, merchants: r.merchant_name ? { name: r.merchant_name } : null }));
|
||||
} catch (error) {
|
||||
console.error('Fetch error:', error);
|
||||
return [];
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
export default async function TransactionsPage(props: {
|
||||
|
||||
Reference in New Issue
Block a user