From 872f271eb18cdfbc29cc5a3f332d2b5a03d12985 Mon Sep 17 00:00:00 2001 From: Hussain Nagaria Date: Sun, 19 Oct 2025 16:28:26 +0530 Subject: [PATCH] refactor: unified new/edit form for sync source --- .../doctype/lead_sync_source/facebook.py | 12 +- .../lead_sync_source/lead_sync_source.json | 8 +- .../lead_sync_source/lead_sync_source.py | 17 +- frontend/components.d.ts | 1 + frontend/src/components/Controls/Grid.vue | 3 +- .../LeadSyncing/EditLeadSyncSource.vue | 142 -------- .../LeadSyncing/LeadSyncSourceForm.vue | 325 ++++++++++++++++++ .../LeadSyncing/LeadSyncSourcePage.vue | 7 +- .../Settings/LeadSyncing/LeadSyncSources.vue | 25 -- .../LeadSyncing/NewLeadSyncSource.vue | 182 ---------- .../LeadSyncing/leadSyncSourceConfig.js | 3 +- frontend/src/stores/meta.js | 2 +- 12 files changed, 358 insertions(+), 369 deletions(-) delete mode 100644 frontend/src/components/Settings/LeadSyncing/EditLeadSyncSource.vue create mode 100644 frontend/src/components/Settings/LeadSyncing/LeadSyncSourceForm.vue delete mode 100644 frontend/src/components/Settings/LeadSyncing/NewLeadSyncSource.vue diff --git a/crm/lead_syncing/doctype/lead_sync_source/facebook.py b/crm/lead_syncing/doctype/lead_sync_source/facebook.py index 841e7050..f5f3c73b 100644 --- a/crm/lead_syncing/doctype/lead_sync_source/facebook.py +++ b/crm/lead_syncing/doctype/lead_sync_source/facebook.py @@ -138,6 +138,14 @@ def create_facebook_lead_form_in_db(form: dict, page_id: str) -> None: "questions": form["questions"], } ) - - frappe.errprint(form_doc.as_dict()) form_doc.insert(ignore_permissions=True) + +@frappe.whitelist() +def get_pages_with_forms() -> list[dict]: + pages = frappe.db.get_all("Facebook Page", fields=["id", "name"]) + for page in pages: + forms = frappe.db.get_all( + "Facebook Lead Form", filters={"page": page["id"]}, fields=["id", "name"] + ) + page["forms"] = forms + return pages \ No newline at end of file diff --git a/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.json b/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.json index ce99f1b8..170a5aeb 100644 --- a/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.json +++ b/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.json @@ -41,7 +41,8 @@ "fieldname": "access_token", "fieldtype": "Password", "label": "Access Token", - "length": 500 + "length": 500, + "reqd": 1 }, { "fieldname": "facebook_page", @@ -76,13 +77,14 @@ "fieldname": "background_sync_frequency", "fieldtype": "Select", "label": "Background Sync Frequency", - "options": "Every 5 Minutes\nEvery 10 Minutes\nEvery 15 Minutes\nHourly\nDaily\nMonthly" + "options": "Every 5 Minutes\nEvery 10 Minutes\nEvery 15 Minutes\nHourly\nDaily\nMonthly", + "reqd": 1 } ], "grid_page_length": 50, "index_web_pages_for_search": 1, "links": [], - "modified": "2025-10-08 12:23:22.097933", + "modified": "2025-10-19 15:07:26.256720", "modified_by": "Administrator", "module": "Lead Syncing", "name": "Lead Sync Source", diff --git a/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.py b/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.py index 96c862b3..4dae3ce2 100644 --- a/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.py +++ b/crm/lead_syncing/doctype/lead_sync_source/lead_sync_source.py @@ -4,7 +4,10 @@ import frappe from frappe.model.document import Document -from crm.lead_syncing.doctype.lead_sync_source.facebook import sync_leads_from_facebook +from crm.lead_syncing.doctype.lead_sync_source.facebook import ( + fetch_and_store_pages_from_facebook, + sync_leads_from_facebook, +) class LeadSyncSource(Document): @@ -16,10 +19,8 @@ class LeadSyncSource(Document): if TYPE_CHECKING: from frappe.types import DF - access_token: DF.Password | None - background_sync_frequency: DF.Literal[ - "Every 5 Minutes", "Every 10 Minutes", "Every 15 Minutes", "Hourly", "Daily", "Monthly" - ] + access_token: DF.Password + background_sync_frequency: DF.Literal["Every 5 Minutes", "Every 10 Minutes", "Every 15 Minutes", "Hourly", "Daily", "Monthly"] enabled: DF.Check facebook_lead_form: DF.Link | None facebook_page: DF.Link | None @@ -45,10 +46,10 @@ class LeadSyncSource(Document): if already_active: frappe.throw(frappe._("A lead sync source is already enabled for this Facebook Lead Form!")) - def before_save(self): + def before_insert(self): if self.type == "Facebook" and self.access_token: - # fetch_and_store_pages_from_facebook(self.access_token) - pass + fetch_and_store_pages_from_facebook(self.access_token) + # rest of the source types can be added here @frappe.whitelist() def sync_leads(self): diff --git a/frontend/components.d.ts b/frontend/components.d.ts index 6d3dc1da..c9f8494b 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -180,6 +180,7 @@ declare module 'vue' { LeadsIcon: typeof import('./src/components/Icons/LeadsIcon.vue')['default'] LeadsListView: typeof import('./src/components/ListViews/LeadsListView.vue')['default'] LeadSyncSettings: typeof import('./src/components/Settings/LeadSyncing/LeadSyncSettings.vue')['default'] + LeadSyncSourceForm: typeof import('./src/components/Settings/LeadSyncing/LeadSyncSourceForm.vue')['default'] LeadSyncSourcePage: typeof import('./src/components/Settings/LeadSyncing/LeadSyncSourcePage.vue')['default'] LeadSyncSources: typeof import('./src/components/Settings/LeadSyncing/LeadSyncSources.vue')['default'] LightningIcon: typeof import('./src/components/Icons/LightningIcon.vue')['default'] diff --git a/frontend/src/components/Controls/Grid.vue b/frontend/src/components/Controls/Grid.vue index c8f6a025..43a69e24 100644 --- a/frontend/src/components/Controls/Grid.vue +++ b/frontend/src/components/Controls/Grid.vue @@ -274,7 +274,8 @@ -
- -
-
-
-
-
- - {{ __('Enabled') }} -
-
-
- - -
-
-
- -
-
-
- -
- - - -
- - -
- -
-
- - \ No newline at end of file diff --git a/frontend/src/components/Settings/LeadSyncing/LeadSyncSourceForm.vue b/frontend/src/components/Settings/LeadSyncing/LeadSyncSourceForm.vue new file mode 100644 index 00000000..47f29e9c --- /dev/null +++ b/frontend/src/components/Settings/LeadSyncing/LeadSyncSourceForm.vue @@ -0,0 +1,325 @@ + + + \ No newline at end of file diff --git a/frontend/src/components/Settings/LeadSyncing/LeadSyncSourcePage.vue b/frontend/src/components/Settings/LeadSyncing/LeadSyncSourcePage.vue index 69d4e04a..332dcbe5 100644 --- a/frontend/src/components/Settings/LeadSyncing/LeadSyncSourcePage.vue +++ b/frontend/src/components/Settings/LeadSyncing/LeadSyncSourcePage.vue @@ -1,6 +1,6 @@