Files
rheinsw-mono-repo/internal_frontend/services/customers/usecases/addCustomer.ts
Thatsaphorn Atchariyaphap 86be1e8920 Enhance NewCustomerModal with callback support and toast notifications
- Add `onCustomerCreated` callback to refresh customer list after creation.
- Integrate `showInfoToast` and `showSuccessToast` for validation and creation feedback.
- Prevent closing modal on backdrop click; add explicit cancel button.
- Refactor `addCustomer` to use `callApi` and centralized routes.
- Simplify customer fetching logic in `CustomersPage` with reusable function.
2025-07-11 19:53:52 +02:00

25 lines
729 B
TypeScript

"use server";
import {CreateCustomerDto} from "@/services/customers/dtos/createCustomer.dto";
import {customerRoutes} from "@/app/api/customers/customerRoutes";
import {callApi} from "@/lib/api/callApi";
import {UUID} from "node:crypto";
export async function addCustomer(params: CreateCustomerDto): Promise<void> {
const {email, name, companyName, street, zip, city, phoneNumbers, notes} = params;
const payload: CreateCustomerDto = {
email,
name,
companyName,
street,
zip,
city,
phoneNumbers,
notes: notes.map(({text}) => ({text})),
};
const response = await callApi<UUID>(customerRoutes.create, "POST", payload);
console.log(response);
}