You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

89 lines
1.8 KiB

  1. import { serverFetchJson } from "@/app/utils/fetchUtil";
  2. import { BASE_API_URL } from "@/config/api";
  3. import { cache } from "react";
  4. import "server-only";
  5. export interface Customer {
  6. id: number;
  7. code: string;
  8. name: string;
  9. brNo: string | null;
  10. address: string | null;
  11. district: string | null;
  12. customerType: CustomerType;
  13. contacts: Contact[];
  14. }
  15. export interface SaveCustomerResponse {
  16. customer: Customer;
  17. message: string;
  18. }
  19. export interface CustomerType {
  20. id: number;
  21. name: string;
  22. }
  23. export interface SubsidiaryType {
  24. id: number;
  25. name: string;
  26. }
  27. export interface Subsidiary {
  28. id: number;
  29. code: string;
  30. name: string;
  31. description: string | null;
  32. brNo: string | null;
  33. contactName: string | null;
  34. phone: string | null;
  35. address: string | null;
  36. district: string | null;
  37. email: string | null;
  38. subsidiaryType: SubsidiaryType;
  39. subsidiaryContacts: Contact[];
  40. }
  41. export interface SubsidiaryTable {
  42. id: number;
  43. code: string;
  44. name: string;
  45. description: string | null;
  46. brNo: string | null;
  47. contactName: string | null;
  48. phone: string | null;
  49. address: string | null;
  50. district: string | null;
  51. email: string | null;
  52. subsidiaryType: string;
  53. }
  54. export interface Contact {
  55. id: number;
  56. name: string;
  57. phone: string;
  58. email: string;
  59. isNew: boolean;
  60. }
  61. export const preloadAllCustomers = () => {
  62. fetchAllCustomers();
  63. };
  64. export const fetchAllCustomers = cache(async () => {
  65. return serverFetchJson<Customer[]>(`${BASE_API_URL}/customer`);
  66. });
  67. export const fetchAllSubsidiaries = cache(async () => {
  68. return serverFetchJson<Subsidiary[]>(`${BASE_API_URL}/subsidiary`, {
  69. next: { tags: ["subsidiary"] },
  70. });
  71. });
  72. export const fetchCustomerTypes = cache(async () => {
  73. return serverFetchJson<CustomerType[]>(`${BASE_API_URL}/customer/types`, {
  74. next: { tags: ["customerTypes"] },
  75. });
  76. });