add query for client details

This commit is contained in:
Casey 2025-11-13 15:17:43 -06:00
parent 172927e069
commit 0b280cec8e
8 changed files with 114 additions and 69 deletions

View file

@ -1,4 +1,5 @@
import ApiUtils from "./apiUtils";
import { useErrorStore } from "./stores/errors";
const ZIPPOPOTAMUS_BASE_URL = "https://api.zippopotam.us/us";
const FRAPPE_PROXY_METHOD = "custom_ui.api.proxy.request";
@ -15,6 +16,7 @@ const FRAPPE_GET_CLIENT_NAMES_METHOD = "custom_ui.api.db.clients.get_client_name
class Api {
static async request(frappeMethod, args = {}) {
const errorStore = useErrorStore();
args = ApiUtils.toSnakeCaseObject(args);
const request = { method: frappeMethod, args };
console.log("DEBUG: API - Request Args: ", request);
@ -28,6 +30,7 @@ class Api {
return response.message.data;
} catch (error) {
console.error("ERROR: API - Request Error: ", error);
errorStore.setApiError("Frappe API", error.message || "API request error");
throw error;
}
}
@ -112,11 +115,11 @@ class Api {
* @param {Object} sorting - Sorting parameters from store (optional)
* @returns {Promise<{data: Array, pagination: Object}>}
*/
static async getPaginatedClientDetails(paginationParams = {}, filters = {}, sorting = []) {
static async getPaginatedClientDetails(paginationParams = {}, filters = {}, sortings = []) {
const { page = 0, pageSize = 10 } = paginationParams;
const result = await this.request(FRAPPE_GET_CLIENT_TABLE_DATA_METHOD, {
filters,
sorting,
sortings,
page: page + 1,
pageSize,
});

View file

@ -3,7 +3,7 @@ class ApiUtils {
console.log("Converting to snake case:", obj);
const newObj = Object.entries(obj).reduce((acc, [key, value]) => {
const snakeKey = key.replace(/[A-Z]/g, (match) => "_" + match.toLowerCase());
if (key === "sorting") {
if (key === "sortings") {
value = value
? value.map((item) => {
const [field, order] = item;

View file

@ -37,10 +37,9 @@ import TabPanel from "primevue/tabpanel";
import Api from "../../api";
import ApiWithToast from "../../api-toast";
import { useLoadingStore } from "../../stores/loading";
import { useErrorStore } from "../../stores/errors";
const loadingStore = useLoadingStore();
const errorStore = useErrorStore();
const clientNames = ref([]);
const client = ref({});
const { clientName } = defineProps({
@ -50,10 +49,10 @@ const { clientName } = defineProps({
const getClientNames = async (type) => {
loadingStore.setLoading(true);
try {
const names = await Api.getCustomerNames(type);
const names = await Api.getClientNames(type);
clientNames.value = names;
} catch (error) {
errorStore.addError(error.message || "Error fetching client names");
console.error("Error fetching client names in Client.vue: ", error.message || error);
} finally {
loadingStore.setLoading(false);
}
@ -61,9 +60,14 @@ const getClientNames = async (type) => {
const getClient = async (name) => {
loadingStore.setLoading(true);
const clientData = await ApiWithToast.makeApiCall(() => Api.getClient(name));
client.value = clientData || {};
loadingStore.setLoading(false);
try {
const clientData = await Api.getClient(name);
client.value = clientData || {};
} catch (error) {
console.error("Error fetching client data in Client.vue: ", error.message || error);
} finally {
loadingStore.setLoading(false);
}
};
onMounted(async () => {

View file

@ -165,7 +165,7 @@ const tableActions = [
{
label: "View Details",
action: (rowData) => {
router.push(`/clients/${rowData.id}`);
router.push(`/clients/${rowData.customerName}`);
},
type: "button",
style: "info",