- 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.
25 lines
729 B
TypeScript
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);
|
|
}
|