Spaces:
Runtime error
Runtime error
| 'use server'; | |
| import { db } from '@/lib/db'; | |
| import { affiliateProposals } from '@/lib/db/schema'; | |
| import { revalidatePath } from 'next/cache'; | |
| export async function submitAffiliateProposal(data: { | |
| videoId: string; | |
| creatorId: string; | |
| objectId?: string; | |
| submitterName?: string; | |
| submitterEmail?: string; | |
| productUrl: string; | |
| affiliateUrl: string; | |
| productName: string; | |
| price?: number; | |
| imageUrl?: string; | |
| note?: string; | |
| }) { | |
| try { | |
| const [proposal] = await db.insert(affiliateProposals).values({ | |
| videoId: data.videoId, | |
| creatorId: data.creatorId, | |
| objectId: data.objectId, | |
| submitterName: data.submitterName, | |
| submitterEmail: data.submitterEmail, | |
| productUrl: data.productUrl, | |
| affiliateUrl: data.affiliateUrl, | |
| productName: data.productName, | |
| price: data.price, | |
| imageUrl: data.imageUrl, | |
| note: data.note, | |
| status: 'PENDING', | |
| }).returning(); | |
| revalidatePath('/dashboard/requests'); | |
| return { success: true, id: proposal.id }; | |
| } catch (error: any) { | |
| console.error('Failed to submit affiliate proposal:', error); | |
| return { success: false, error: error.message || 'Failed to submit proposal' }; | |
| } | |
| } | |