'use server' import { createClient } from '@/lib/supabase/server' import { revalidatePath } from 'next/cache' import { Order } from '../types' export async function submitOrder(orderData: { product_id: string; selected_modules: string[]; total_amount: number; customer_details: any; }) { const supabase = await createClient() const { data: { user } } = await supabase.auth.getUser() if (!user) throw new Error('Not authenticated') const { data, error } = await supabase .from('orders') .insert([{ user_id: user.id, total_amount: orderData.total_amount, items: { product_id: orderData.product_id, modules: orderData.selected_modules }, billing_details: orderData.customer_details, status: 'pending' }]) .select() .single() if (error) throw error revalidatePath('/admin/orders') // If there was an admin orders page return data }