see comments

This commit is contained in:
Rajpreet0 2026-06-15 12:27:54 +02:00
parent e54c0103df
commit 211637f1fe
2 changed files with 33 additions and 23 deletions

View file

@ -26,11 +26,13 @@ export async function updateBusinessInfo(data: {
return { success: false, error: "Nicht berechtigt." };
}
if (!data.address.trim() || !data.email.trim() || !data.title.trim()) {
const email = data.email.trim();
if (!data.address.trim() || !email || !data.title.trim()) {
return { success: false, error: "Bitte alle Pflichtfelder ausfüllen." };
}
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email)) {
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
return { success: false, error: "Ungültige E-Mail-Adresse." };
}
@ -38,14 +40,14 @@ export async function updateBusinessInfo(data: {
where: { id: data.businessId },
data: {
address: data.address.trim(),
email: data.email.trim(),
email,
title: data.title.trim(),
ustId: data.ustId?.trim() || null,
banking: data.banking?.trim() || null,
},
});
revalidateTag(`user-data-${manager.email}`);
(revalidateTag as (tag: string, type: "max") => void)(`user-data-${manager.email}`, "max");
return { success: true };
} catch {
return { success: false, error: "Fehler beim Speichern der Business-Daten." };

View file

@ -1,6 +1,6 @@
"use client";
import { useState, useTransition } from "react";
import { type ReactNode, useState, useTransition } from "react";
import InputComponent from "@/src/components/layout/InputComponent";
import { Button } from "@/src/components/ui/button";
import { updateBusinessInfo } from "../../actions/business-settings-actions";
@ -25,7 +25,7 @@ function Card({
}: {
title: string;
subtitle?: string;
children: React.ReactNode;
children: ReactNode;
}) {
return (
<div className="border border-white/60 bg-white/55 backdrop-blur-xl rounded-2xl shadow-sm p-6 space-y-5">
@ -59,29 +59,37 @@ const BusinessSettingsForm = ({
const handleBusinessSave = () => {
startTransition(async () => {
const result = await updateBusinessInfo({
businessId,
address,
email,
title,
ustId,
banking,
});
if (result.success) {
toast.success("Business-Daten erfolgreich gespeichert.");
} else {
toast.error(result.error ?? "Fehler beim Speichern.");
try {
const result = await updateBusinessInfo({
businessId,
address,
email,
title,
ustId,
banking,
});
if (result.success) {
toast.success("Business-Daten erfolgreich gespeichert.");
} else {
toast.error(result.error ?? "Fehler beim Speichern.");
}
} catch {
toast.error("Fehler beim Speichern.");
}
});
};
const handleTelSave = () => {
startTransition(async () => {
const result = await updateProfileInfo({ tel });
if (result.success) {
toast.success("Geschäftsnummer erfolgreich gespeichert.");
} else {
toast.error(result.error ?? "Fehler beim Speichern.");
try {
const result = await updateProfileInfo({ tel });
if (result.success) {
toast.success("Geschäftsnummer erfolgreich gespeichert.");
} else {
toast.error(result.error ?? "Fehler beim Speichern.");
}
} catch {
toast.error("Fehler beim Speichern.");
}
});
};