From 07c1181d6ecf3a1ae52734fcfb980f3d3158a18c Mon Sep 17 00:00:00 2001 From: Casey Date: Wed, 3 Dec 2025 07:15:58 -0600 Subject: [PATCH] update js inject file to bust caching --- custom_ui/api/db/clients.py | 4 +- .../custom_ui/page/custom_ui/custom_ui.html | 1 + .../custom_ui/page/custom_ui/custom_ui.js | 57 ++++++++++++++----- .../components/clientSubPages/Overview.vue | 19 ++++--- frontend/src/components/pages/Estimate.vue | 2 +- 5 files changed, 58 insertions(+), 25 deletions(-) diff --git a/custom_ui/api/db/clients.py b/custom_ui/api/db/clients.py index ef1735b..b3ffc67 100644 --- a/custom_ui/api/db/clients.py +++ b/custom_ui/api/db/clients.py @@ -262,7 +262,7 @@ def upsert_client(data): "custom_customer": customer_doc.name, "role": contact_data.get("contact_role", "Other"), "custom_email": contact_data.get("email"), - "is_primary_contact": data.get("is_primary", False), + "is_primary_contact":1 if data.get("is_primary", False) else 0, "email_ids": [{ "email_id": contact_data.get("email"), "is_primary": 1 @@ -338,7 +338,7 @@ def upsert_client(data): address_doc.save(ignore_permissions=True) customer_doc.save(ignore_permissions=True) - + frappe.local.message_log = [] return build_success_response({ "customer": customer_doc.as_dict(), "address": address_doc.as_dict(), diff --git a/custom_ui/custom_ui/page/custom_ui/custom_ui.html b/custom_ui/custom_ui/page/custom_ui/custom_ui.html index 7b3a836..e16be9a 100644 --- a/custom_ui/custom_ui/page/custom_ui/custom_ui.html +++ b/custom_ui/custom_ui/page/custom_ui/custom_ui.html @@ -1,4 +1,5 @@
+THIS IS A TEST {% if bundle_path %} {% else %} diff --git a/custom_ui/custom_ui/page/custom_ui/custom_ui.js b/custom_ui/custom_ui/page/custom_ui/custom_ui.js index 847afd7..be94daa 100644 --- a/custom_ui/custom_ui/page/custom_ui/custom_ui.js +++ b/custom_ui/custom_ui/page/custom_ui/custom_ui.js @@ -1,20 +1,47 @@ frappe.pages["custom_ui"].on_page_load = async (wrapper) => { - $(wrapper).html('
'); - console.log("App root div created"); - manifest = await fetch("/assets/custom_ui/dist/.vite/manifest.json").then((res) => res.json()); - console.log("Fetched manifest:", manifest); + // Create root div for spa if it doesn't exist + const appRootId = "custom-ui-app"; + if (!document.getElementById(appRootId)) { + $(wrapper).html('
'); + console.log("App root div created"); + } - const script = document.createElement("script"); - script.src = "/assets/custom_ui/dist/" + manifest["src/main.js"]["file"]; - script.type = "module"; - document.body.appendChild(script); - console.log("Appended script:", script.src); + // Attempt to load the manifest file + try { + // Cache busting by appending a timestamp + const manifestUrl = `/assets/custom_ui/dist/.vite/manifest.json?v=${Date.now()}`; + manifest = await fetch(manifestUrl).then((res) => res.json()); + console.log("Fetched manifest:", manifest); - const link = document.createElement("link"); - link.rel = "stylesheet"; - link.href = "/assets/custom_ui/dist/" + manifest["src/main.js"]["css"][0]; - document.head.appendChild(link); + // Check existence of old script and link elements and remove them + const existingScript = document.getElementById("custom-ui-main-js"); + if (existingScript) existingScript.remove(); - console.log("Custom UI stylesheet loaded:", link.href); - console.log("Custom UI script loaded:", script.src); + const existingLink = document.getElementById("custom-ui-main-css"); + if (existingLink) existingLink.remove(); + + // Append new script and link elements + const cssHref = manifest["src/main.js"]["css"]?.[0]; + if (cssHref) { + const link = document.createElement("link"); + link.id = "custom-ui-main-css"; + link.rel = "stylesheet"; + link.href = `/assets/custom_ui/dist/${cssHref}`; + document.head.appendChild(link); + console.log("Appended stylesheet:", link.href); + } + + const jsFile = manifest["src/main.js"]["file"]; + if (jsFile) { + const script = document.createElement("script"); + script.id = "custom-ui-main-js"; + script.type = "module"; + script.src = `/assets/custom_ui/dist/${jsFile}`; + document.body.appendChild(script); + console.log("Appended script:", script.src); + } + + } catch (error) { + console.error("Error loading manifest or app resources:", error); + } }; diff --git a/frontend/src/components/clientSubPages/Overview.vue b/frontend/src/components/clientSubPages/Overview.vue index 15f5e54..f03b6ec 100644 --- a/frontend/src/components/clientSubPages/Overview.vue +++ b/frontend/src/components/clientSubPages/Overview.vue @@ -403,27 +403,32 @@ const primaryContactEmail = computed(() => { const isFormValid = computed(() => { const hasCustomerName = formData.value.customerName?.trim(); const hasCustomerType = formData.value.customerType?.trim(); - const hasAddressTitle = formData.value.addressTitle?.trim(); const hasAddressLine1 = formData.value.addressLine1?.trim(); const hasPincode = formData.value.pincode?.trim(); const hasCity = formData.value.city?.trim(); const hasState = formData.value.state?.trim(); const hasContacts = formData.value.contacts && formData.value.contacts.length > 0; - const primaryContact = formData.value.contacts?.find((c) => c.isPrimary); - const hasFirstName = primaryContact?.firstName?.trim(); - const hasLastName = primaryContact?.lastName?.trim(); + + // Check that all contacts have required fields + const allContactsValid = formData.value.contacts?.every((contact) => { + return ( + contact.firstName?.trim() && + contact.lastName?.trim() && + contact.email?.trim() && + contact.phoneNumber?.trim() && + contact.contactRole?.trim() + ); + }); return ( hasCustomerName && hasCustomerType && - hasAddressTitle && hasAddressLine1 && hasPincode && hasCity && hasState && hasContacts && - hasFirstName && - hasLastName + allContactsValid ); }); diff --git a/frontend/src/components/pages/Estimate.vue b/frontend/src/components/pages/Estimate.vue index 90273c2..779eeff 100644 --- a/frontend/src/components/pages/Estimate.vue +++ b/frontend/src/components/pages/Estimate.vue @@ -92,7 +92,7 @@ :disabled="selectedItems.length === 0" /> -
+