diff --git a/backend/server/src/main/java/dev/rheinsw/server/customer/controller/CustomerController.java b/backend/server/src/main/java/dev/rheinsw/server/customer/controller/CustomerController.java index 4beccd1..67106c9 100644 --- a/backend/server/src/main/java/dev/rheinsw/server/customer/controller/CustomerController.java +++ b/backend/server/src/main/java/dev/rheinsw/server/customer/controller/CustomerController.java @@ -16,7 +16,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.Collections; import java.util.List; import java.util.UUID; diff --git a/internal_frontend/app/customers/page.tsx b/internal_frontend/app/customers/page.tsx index 04c3db6..a82c389 100644 --- a/internal_frontend/app/customers/page.tsx +++ b/internal_frontend/app/customers/page.tsx @@ -35,28 +35,28 @@ export default function CustomersPage() { const pageSize = 15; const handleError = useErrorHandler(); - useEffect(() => { + const loadCustomers = async () => { setLoading(true); - fetch('/api/customers') - .then(async (response) => { - if (!response.ok) { - showError("Failed to fetch customers data") - throw new Error(`Failed to fetch customers: ${response.statusText}`); - } - return response.json(); - }) - .then((data) => { - showInfoToast("Customers data loaded") - setCustomers(data); - }) - .catch((error) => { - showError("Failed to fetch customers data (1)") - handleError(error); - setCustomers([]); - }) - .finally(() => { - setLoading(false); - }); + try { + const response = await fetch('/api/customers'); + if (!response.ok) { + showError("Failed to fetch customers data"); + throw new Error(`Failed to fetch customers: ${response.statusText}`); + } + const data = await response.json(); + showInfoToast("Customers data loaded"); + setCustomers(data); + } catch (error) { + showError("Failed to fetch customers data (1)"); + handleError(error); + setCustomers([]); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + loadCustomers(); }, [handleError]); const filtered = useMemo(() => { @@ -114,7 +114,7 @@ export default function CustomersPage() {
setSearch(e.target.value)}/> - +
{customers.length === 0 && loading ? ( diff --git a/internal_frontend/components/customers/modal/NewCustomerModal.tsx b/internal_frontend/components/customers/modal/NewCustomerModal.tsx index c09ddcd..c9d369b 100644 --- a/internal_frontend/components/customers/modal/NewCustomerModal.tsx +++ b/internal_frontend/components/customers/modal/NewCustomerModal.tsx @@ -14,8 +14,13 @@ import {CreateCustomerDto, NoteDto, PhoneNumberDto} from "@/services/customers/d import {addCustomer} from "@/services/customers/usecases/addCustomer"; import {validateCustomer} from "@/services/customers/usecases/validateCustomer"; import {useErrorHandler} from "@/components/error-boundary"; +import {showInfoToast, showSuccessToast} from "@/lib/ui/showToast"; -export function NewCustomerModal() { +interface NewCustomerModalProps { + onCustomerCreated?: () => void; +} + +export function NewCustomerModal({ onCustomerCreated }: NewCustomerModalProps) { const [step, setStep] = useState(1); const [open, setOpen] = useState(false); const [email, setEmail] = useState(""); @@ -53,6 +58,7 @@ export function NewCustomerModal() { try { const result = await validateCustomer({email, companyName, street, zip, city}); setMatches(result); + showInfoToast("Datenvalidierung abgeschlossen"); } catch (err) { handleError(err); } @@ -63,7 +69,11 @@ export function NewCustomerModal() { try { const payload: CreateCustomerDto = {email, name, companyName, street, zip, city, phoneNumbers, notes}; await addCustomer(payload); - location.reload(); + showSuccessToast("Kunde erfolgreich erstellt"); + setOpen(false); + if (onCustomerCreated) { + onCustomerCreated(); + } } catch (err) { handleError(err); } @@ -215,14 +225,16 @@ export function NewCustomerModal() { return ( <> - + { + // Prevent closing on backdrop click - modal can only be closed explicitly + }}> - + Neuen Kunden anlegen
Schritt {step} von 2
@@ -233,9 +245,14 @@ export function NewCustomerModal() { {matches.length > 0 && renderDuplicationCard()}
- +
+ + +
{step === 1 ? (