import { serverFetchJson } from "@/app/utils/fetchUtil"; import { BASE_API_URL } from "@/config/api"; import { cache } from "react"; import "server-only"; export interface Customer { id: number; code: string; name: string; brNo: string | null; address: string | null; district: string | null; customerType: CustomerType; contacts: Contact[]; } export interface SaveCustomerResponse { customer: Customer; message: string; } export interface CustomerType { id: number; name: string; } export interface SubsidiaryType { id: number; name: string; } export interface Subsidiary { id: number; code: string; name: string; description: string | null; brNo: string | null; contactName: string | null; phone: string | null; address: string | null; district: string | null; email: string | null; subsidiaryType: SubsidiaryType; subsidiaryContacts: Contact[]; } export interface SubsidiaryTable { id: number; code: string; name: string; description: string | null; brNo: string | null; contactName: string | null; phone: string | null; address: string | null; district: string | null; email: string | null; subsidiaryType: string; } export interface Contact { id: number; name: string; phone: string; email: string; isNew: boolean; } export const preloadAllCustomers = () => { fetchAllCustomers(); }; export const fetchAllCustomers = cache(async () => { return serverFetchJson(`${BASE_API_URL}/customer`); }); export const fetchAllSubsidiaries = cache(async () => { return serverFetchJson(`${BASE_API_URL}/subsidiary`, { next: { tags: ["subsidiary"] }, }); }); export const fetchCustomerTypes = cache(async () => { return serverFetchJson(`${BASE_API_URL}/customer/types`, { next: { tags: ["customerTypes"] }, }); });