Files
tm_panel/src/lib/api/services/customers-service.ts
T
AmirReza Jamali e1898bf259 feat(submissions): Implement submissions page with paginated table
This commit introduces a new page for users to view their submissions in a structured and paginated table. This allows users to easily track their submission history and access key details.

The main changes include:
- A new page at `/submissions` to display the submissions list.
- A `SubmissionsTable` component to render submission data, including title, country, status, and a link to the submission URL.
- Integration of `react-paginate` to handle navigation through large sets of data.
- A new `useSubmissions` custom hook using TanStack Query for efficient, paginated data fetching from the API.
- Addition of the `currency-symbol-map` dependency to display prices with the correct currency symbol.
2025-09-18 16:52:46 +03:30

83 lines
2.2 KiB
TypeScript

import api from "../axios";
import { API_ENDPOINTS } from "../endpoints";
import { ApiResponse } from "../types";
import {
CreateCustomerCredentials,
CustomerListResponseSchema,
TAssignCustomerToCompanyCredentials,
TCustomersListResponse,
} from "../types/Customers";
export const customersService = {
getCustomers: async (
params?: Record<string, any>,
): Promise<ApiResponse<TCustomersListResponse>> => {
try {
const response = await api.get(API_ENDPOINTS.CUSTOMERS.READ_ALL, {
params,
});
return CustomerListResponseSchema.parse(response.data);
} catch (error) {
console.error("ERROR caught in Customers Services Read all:", error);
throw error;
}
},
deleteCustomer: async (id: string) => {
try {
return (await api.delete(API_ENDPOINTS.CUSTOMERS.DELETE(id))).data;
} catch (error) {
console.error("ERROR caught in Customers Services Delete:", error);
throw error;
}
},
createCustomer: async (credentials: CreateCustomerCredentials) => {
try {
return (await api.post(API_ENDPOINTS.CUSTOMERS.CREATE, credentials)).data;
} catch (error) {
console.error("ERROR caught in Customers Services Create:", error);
throw error;
}
},
updateCustomer: async ({
id,
credentials,
}: {
id: string;
credentials: CreateCustomerCredentials;
}) => {
try {
return (await api.put(API_ENDPOINTS.CUSTOMERS.UPDATE(id), credentials))
.data;
} catch (error) {
console.error("ERROR caught in Customers Services Update:", error);
throw error;
}
},
customerDetails: async (id: string) => {
const response = await api.get(API_ENDPOINTS.CUSTOMERS.DETAILS(id));
return response.data;
},
assignCompanyToCustomer: async ({
credentials,
id,
}: {
id: string;
credentials: TAssignCustomerToCompanyCredentials;
}): Promise<any> => {
try {
return (
await api.post(
API_ENDPOINTS.CUSTOMERS.ASSIGN_COMPANY_TO_CUSTOMER(id),
credentials,
)
).data;
} catch (error) {
console.error(
"ERROR caught in Customers Service => Assign company to customer",
error,
);
throw error;
}
},
};