diff --git a/src/lib/companyHelpers.ts b/src/lib/companyHelpers.ts index 1f3b5db5..bee6e59c 100644 --- a/src/lib/companyHelpers.ts +++ b/src/lib/companyHelpers.ts @@ -22,8 +22,9 @@ export async function submitCompanyCreation( .from('content_submissions') .insert([{ user_id: userId, - submission_type: 'company_create', + submission_type: companyType, // Use entity-specific type: 'manufacturer', 'designer', 'operator', or 'property_owner' content: { + action: 'create', name: data.name, slug: data.slug, description: data.description, @@ -46,13 +47,24 @@ export async function submitCompanyUpdate( data: CompanyFormData, userId: string ) { + // Fetch existing company to get its type + const { data: existingCompany, error: fetchError } = await supabase + .from('companies') + .select('company_type') + .eq('id', companyId) + .single(); + + if (fetchError) throw fetchError; + if (!existingCompany) throw new Error('Company not found'); + // All users submit for moderation const { error } = await supabase .from('content_submissions') .insert([{ user_id: userId, - submission_type: 'company_edit', + submission_type: existingCompany.company_type, // Use entity-specific type from existing company content: { + action: 'edit', company_id: companyId, name: data.name, slug: data.slug,