feat: Add partner account settings page under /account-kunden
All checks were successful
Staging Build / build (push) Successful in 3m33s

This commit is contained in:
DanielS
2026-07-04 21:06:46 +02:00
parent 060aa97ce5
commit a64b6790c6
3 changed files with 523 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
'use server';
import { createAdminClient } from '@/lib/supabase/admin';
import { createClient } from '@/lib/supabase/server';
import { revalidatePath, unstable_noStore as noStore } from 'next/cache';
import { sendMail } from '@/utils/mail';
@@ -262,6 +263,51 @@ export async function updateUserProfile(id: string, data: { first_name: string |
}
}
export async function updateCompanyDetails(companyId: string, data: { street: string | null; zip: string | null; city: string | null; email: string | null }) {
try {
const supabase = await createClient();
const { data: { user } } = await supabase.auth.getUser();
if (!user) {
return { success: false, error: 'Nicht authentifiziert.' };
}
// Berechtigung prüfen: Ist der User Mitglied dieser Company oder Admin?
const { data: dbUser } = await supabase
.from('users')
.select('role, company_id')
.eq('id', user.id)
.single();
if (!dbUser) {
return { success: false, error: 'Benutzer nicht gefunden.' };
}
if (dbUser.role !== 'admin' && dbUser.company_id !== companyId) {
return { success: false, error: 'Keine Berechtigung zur Bearbeitung dieses Unternehmens.' };
}
const admin = createAdminClient();
const { error } = await admin
.from('companies')
.update({
street: data.street,
zip: data.zip,
city: data.city,
email: data.email
})
.eq('id', companyId);
if (error) {
return { success: false, error: error.message };
}
return { success: true };
} catch (err: any) {
console.error('updateCompanyDetails Server Action failed:', err);
return { success: false, error: err.message || 'Unternehmen konnte nicht aktualisiert werden.' };
}
}
function getBeautifulEmailHtml(title: string, messageHtml: string, buttonText?: string, buttonUrl?: string) {
return `
<div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: #f8fafc; padding: 40px 10px; margin: 0; width: 100%;">