update create client form
This commit is contained in:
parent
1f33262e90
commit
2cfe7ed8e6
9 changed files with 1856 additions and 1412 deletions
|
|
@ -1,25 +1,20 @@
|
|||
import DataUtils from "./utils";
|
||||
import axios from "axios";
|
||||
|
||||
const ZIPPOPOTAMUS_BASE_URL = "https://api.zippopotam.us/us";
|
||||
|
||||
class Api {
|
||||
|
||||
static async request(url, method = "get", data = {}) {
|
||||
static async request(url, method = "GET", data = {}) {
|
||||
try {
|
||||
const response = await axios({
|
||||
url,
|
||||
method,
|
||||
data,
|
||||
withCredentials: false,
|
||||
timeout: 10000, // 10 second timeout
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
console.log("DEBUG: API - Request Response: ", response.data);
|
||||
return response.data;
|
||||
const response = await frappe.call({
|
||||
method: "custom_ui.api.proxy.request",
|
||||
args: {
|
||||
url,
|
||||
method,
|
||||
data: JSON.stringify(data),
|
||||
},
|
||||
});
|
||||
console.log("DEBUG: API - Request Response: ", response);
|
||||
return response.message;
|
||||
} catch (error) {
|
||||
console.error("DEBUG: API - Request Error: ", error);
|
||||
// Re-throw the error so calling code can handle it
|
||||
|
|
@ -80,8 +75,8 @@ class Api {
|
|||
/**
|
||||
* Fetch a list of documents from a specific doctype.
|
||||
*
|
||||
* @param {String} doctype
|
||||
* @param {string[]} fields
|
||||
* @param {String} doctype
|
||||
* @param {string[]} fields
|
||||
* @returns {Promise<Object[]>}
|
||||
*/
|
||||
static async getDocsList(doctype, fields = []) {
|
||||
|
|
@ -93,8 +88,8 @@ class Api {
|
|||
/**
|
||||
* Fetch a detailed document by doctype and name.
|
||||
*
|
||||
* @param {String} doctype
|
||||
* @param {String} name
|
||||
* @param {String} doctype
|
||||
* @param {String} name
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
static async getDetailedDoc(doctype, name) {
|
||||
|
|
@ -105,36 +100,27 @@ class Api {
|
|||
|
||||
/**
|
||||
* Fetch a list of places (city/state) by zipcode using Zippopotamus API.
|
||||
*
|
||||
*
|
||||
* @param {String} zipcode
|
||||
* @returns {Promise<Object[]>}
|
||||
*/
|
||||
static async getCityStateByZip(zipcode) {
|
||||
const url = `${ZIPPOPOTAMUS_BASE_URL}/${zipcode}`;
|
||||
try {
|
||||
const response = await this.request(url);
|
||||
const { places } = response || {};
|
||||
|
||||
if (!places || places.length === 0) {
|
||||
throw new Error(`No location data found for zip code ${zipcode}`);
|
||||
}
|
||||
|
||||
return places;
|
||||
} catch (error) {
|
||||
console.error("DEBUG: API - getCityStateByZip Error: ", error);
|
||||
|
||||
// Provide more specific error information
|
||||
if (error.code === 'ERR_NETWORK') {
|
||||
throw new Error('Network error: Unable to connect to location service. This may be due to CORS restrictions or network connectivity issues.');
|
||||
} else if (error.response?.status === 404) {
|
||||
throw new Error(`Zip code ${zipcode} not found in database.`);
|
||||
} else if (error.code === 'ECONNABORTED') {
|
||||
throw new Error('Request timeout: Location service is taking too long to respond.');
|
||||
}
|
||||
|
||||
// Re-throw the original error if we can't categorize it
|
||||
throw error;
|
||||
const response = await this.request(url);
|
||||
const { places } = response || {};
|
||||
if (!places || places.length === 0) {
|
||||
throw new Error(`No location data found for zip code ${zipcode}`);
|
||||
}
|
||||
return places;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a list of Customer names.
|
||||
* @returns {Promise<String[]>}
|
||||
*/
|
||||
static async getCustomerNames() {
|
||||
const customers = await this.getDocsList("Customer", ["name"]);
|
||||
return customers.map((customer) => customer.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue