From 96194c331be0cf38b40abaae3017270b828d5caf Mon Sep 17 00:00:00 2001 From: Aditya Patil Date: Fri, 19 Jan 2024 17:43:18 +0530 Subject: [PATCH 01/32] feat: Raven Bot Doctype Setup --- mobile/src/types/Raven/RavenUser.ts | 10 +- mobile/src/types/RavenBot/RavenBot.ts | 25 ++ .../src/types/RavenMessaging/RavenMessage.ts | 8 + raven-app/src/types/Raven/RavenUser.ts | 10 +- raven-app/src/types/RavenBot/RavenBot.ts | 25 ++ .../src/types/RavenMessaging/RavenMessage.ts | 8 + raven/modules.txt | 3 +- .../raven/doctype/raven_user/raven_user.json | 27 +- raven/raven/doctype/raven_user/raven_user.py | 232 ++++++++++-------- raven/raven_bot/__init__.py | 0 raven/raven_bot/doctype/__init__.py | 0 raven/raven_bot/doctype/raven_bot/__init__.py | 0 .../raven_bot/doctype/raven_bot/raven_bot.js | 8 + .../doctype/raven_bot/raven_bot.json | 80 ++++++ .../raven_bot/doctype/raven_bot/raven_bot.py | 14 ++ .../doctype/raven_bot/test_raven_bot.py | 9 + .../doctype/raven_message/raven_message.json | 20 +- 17 files changed, 361 insertions(+), 118 deletions(-) create mode 100644 mobile/src/types/RavenBot/RavenBot.ts create mode 100644 raven-app/src/types/RavenBot/RavenBot.ts create mode 100644 raven/raven_bot/__init__.py create mode 100644 raven/raven_bot/doctype/__init__.py create mode 100644 raven/raven_bot/doctype/raven_bot/__init__.py create mode 100644 raven/raven_bot/doctype/raven_bot/raven_bot.js create mode 100644 raven/raven_bot/doctype/raven_bot/raven_bot.json create mode 100644 raven/raven_bot/doctype/raven_bot/raven_bot.py create mode 100644 raven/raven_bot/doctype/raven_bot/test_raven_bot.py diff --git a/mobile/src/types/Raven/RavenUser.ts b/mobile/src/types/Raven/RavenUser.ts index e3dbd8ec8..4e44ab791 100644 --- a/mobile/src/types/Raven/RavenUser.ts +++ b/mobile/src/types/Raven/RavenUser.ts @@ -10,12 +10,18 @@ export interface RavenUser{ parentfield?: string parenttype?: string idx?: number + /** Type : Select */ + type: "Human" | "Bot" /** User : Link - User */ - user: string + user?: string + /** Bot : Link - Raven Bot */ + bot?: string /** Full Name : Data */ - full_name: string + full_name?: string /** First Name : Data */ first_name?: string /** User Image : Attach Image */ user_image?: string + /** Enabled : Check */ + enabled?: 0 | 1 } \ No newline at end of file diff --git a/mobile/src/types/RavenBot/RavenBot.ts b/mobile/src/types/RavenBot/RavenBot.ts new file mode 100644 index 000000000..74db4f47d --- /dev/null +++ b/mobile/src/types/RavenBot/RavenBot.ts @@ -0,0 +1,25 @@ + +export interface RavenBot{ + creation: string + name: string + modified: string + owner: string + modified_by: string + docstatus: 0 | 1 | 2 + parent?: string + parentfield?: string + parenttype?: string + idx?: number + /** Bot Name : Data */ + bot_name?: string + /** Description : Data */ + description?: string + /** Image : Attach Image */ + image?: string + /** Enabled : Check */ + enabled?: 0 | 1 + /** Is Standard : Check */ + is_standard?: 0 | 1 + /** Module : Link - Module Def */ + module?: string +} \ No newline at end of file diff --git a/mobile/src/types/RavenMessaging/RavenMessage.ts b/mobile/src/types/RavenMessaging/RavenMessage.ts index 93f2f4380..188568bff 100644 --- a/mobile/src/types/RavenMessaging/RavenMessage.ts +++ b/mobile/src/types/RavenMessaging/RavenMessage.ts @@ -36,4 +36,12 @@ export interface RavenMessage{ is_reply?: 0 | 1 /** Linked Message : Link - Raven Message */ linked_message?: string + /** Link Doctype : Link - DocType */ + link_doctype?: string + /** Link Document : Dynamic Link */ + link_document?: string + /** Is Bot Message : Check */ + is_bot_message?: 0 | 1 + /** Bot : Link - Raven User */ + bot?: string } \ No newline at end of file diff --git a/raven-app/src/types/Raven/RavenUser.ts b/raven-app/src/types/Raven/RavenUser.ts index e3dbd8ec8..4e44ab791 100644 --- a/raven-app/src/types/Raven/RavenUser.ts +++ b/raven-app/src/types/Raven/RavenUser.ts @@ -10,12 +10,18 @@ export interface RavenUser{ parentfield?: string parenttype?: string idx?: number + /** Type : Select */ + type: "Human" | "Bot" /** User : Link - User */ - user: string + user?: string + /** Bot : Link - Raven Bot */ + bot?: string /** Full Name : Data */ - full_name: string + full_name?: string /** First Name : Data */ first_name?: string /** User Image : Attach Image */ user_image?: string + /** Enabled : Check */ + enabled?: 0 | 1 } \ No newline at end of file diff --git a/raven-app/src/types/RavenBot/RavenBot.ts b/raven-app/src/types/RavenBot/RavenBot.ts new file mode 100644 index 000000000..74db4f47d --- /dev/null +++ b/raven-app/src/types/RavenBot/RavenBot.ts @@ -0,0 +1,25 @@ + +export interface RavenBot{ + creation: string + name: string + modified: string + owner: string + modified_by: string + docstatus: 0 | 1 | 2 + parent?: string + parentfield?: string + parenttype?: string + idx?: number + /** Bot Name : Data */ + bot_name?: string + /** Description : Data */ + description?: string + /** Image : Attach Image */ + image?: string + /** Enabled : Check */ + enabled?: 0 | 1 + /** Is Standard : Check */ + is_standard?: 0 | 1 + /** Module : Link - Module Def */ + module?: string +} \ No newline at end of file diff --git a/raven-app/src/types/RavenMessaging/RavenMessage.ts b/raven-app/src/types/RavenMessaging/RavenMessage.ts index 93f2f4380..188568bff 100644 --- a/raven-app/src/types/RavenMessaging/RavenMessage.ts +++ b/raven-app/src/types/RavenMessaging/RavenMessage.ts @@ -36,4 +36,12 @@ export interface RavenMessage{ is_reply?: 0 | 1 /** Linked Message : Link - Raven Message */ linked_message?: string + /** Link Doctype : Link - DocType */ + link_doctype?: string + /** Link Document : Dynamic Link */ + link_document?: string + /** Is Bot Message : Check */ + is_bot_message?: 0 | 1 + /** Bot : Link - Raven User */ + bot?: string } \ No newline at end of file diff --git a/raven/modules.txt b/raven/modules.txt index c5387266a..47c760840 100644 --- a/raven/modules.txt +++ b/raven/modules.txt @@ -1,3 +1,4 @@ Raven Raven Messaging -Raven Channel Management \ No newline at end of file +Raven Channel Management +Raven Bot \ No newline at end of file diff --git a/raven/raven/doctype/raven_user/raven_user.json b/raven/raven/doctype/raven_user/raven_user.json index d15dde972..20613279f 100644 --- a/raven/raven/doctype/raven_user/raven_user.json +++ b/raven/raven/doctype/raven_user/raven_user.json @@ -1,14 +1,15 @@ { "actions": [], "allow_rename": 1, - "autoname": "field:user", "creation": "2023-09-06 14:36:48.631681", "default_view": "List", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", "field_order": [ + "type", "user", + "bot", "full_name", "first_name", "user_image", @@ -17,11 +18,12 @@ ], "fields": [ { + "depends_on": "eval: doc.type == 'Human'", "fieldname": "user", "fieldtype": "Link", "label": "User", + "mandatory_depends_on": "eval: doc.type == 'Human'", "options": "User", - "reqd": 1, "unique": 1 }, { @@ -32,7 +34,7 @@ "in_list_view": 1, "in_standard_filter": 1, "label": "Full Name", - "reqd": 1 + "mandatory_depends_on": "eval: doc.type == 'Human'" }, { "fetch_from": "user.first_name", @@ -41,6 +43,7 @@ "label": "First Name" }, { + "depends_on": "eval: doc.type == 'Human'", "fetch_from": ".", "fieldname": "user_image", "fieldtype": "Attach Image", @@ -57,15 +60,29 @@ "fieldname": "html_xuuw", "fieldtype": "HTML", "options": "

To disable the user from accessing Raven, go to \"Users\" and remove the \"Raven User\" role.

" + }, + { + "fieldname": "type", + "fieldtype": "Select", + "label": "Type", + "options": "Human\nBot", + "reqd": 1 + }, + { + "depends_on": "eval: doc.type == 'Bot'", + "fieldname": "bot", + "fieldtype": "Link", + "label": "Bot", + "options": "Raven Bot" } ], "image_field": "user_image", "links": [], - "modified": "2023-12-08 04:14:02.588812", + "modified": "2024-01-19 16:53:51.574064", "modified_by": "Administrator", "module": "Raven", "name": "Raven User", - "naming_rule": "By fieldname", + "naming_rule": "By script", "owner": "Administrator", "permissions": [ { diff --git a/raven/raven/doctype/raven_user/raven_user.py b/raven/raven/doctype/raven_user/raven_user.py index aea5caaeb..76eb1460e 100644 --- a/raven/raven/doctype/raven_user/raven_user.py +++ b/raven/raven/doctype/raven_user/raven_user.py @@ -5,110 +5,130 @@ from frappe.model.document import Document from frappe import _ + class RavenUser(Document): - # begin: auto-generated types - # This code is auto-generated. Do not modify anything in this block. - - from typing import TYPE_CHECKING - - if TYPE_CHECKING: - from frappe.types import DF - - enabled: DF.Check - first_name: DF.Data | None - full_name: DF.Data - user: DF.Link - user_image: DF.AttachImage | None - # end: auto-generated types - - def before_validate(self): - if not self.full_name: - self.full_name = self.first_name - - def before_save(self): - self.update_photo_from_user() - - def after_delete(self): - ''' - Remove the Raven User role from the user. - ''' - user = frappe.get_doc("User", self.user) - user.flags.ignore_permissions = True - user.flags.deleting_raven_user = True - user.remove_roles("Raven User") - user.save() - - def update_photo_from_user(self): - ''' - We need to create a new File record for the user image and attach it to the Raven User record. - Why not just copy the URL from the User record? Because the URL is not accessible to the Raven User, - and Frappe creates a duplicate file in the system (that is public) but does not update the URL in the field. - ''' - user_image = frappe.db.get_value("User", self.user, "user_image") - if user_image and not self.user_image: - image_file = frappe.get_doc( - { - "doctype": "File", - "file_url": user_image, - "attached_to_doctype": "Raven User", - "attached_to_name": self.name, - "attached_to_field": "user_image", - "is_private": 1, - } - ).insert() - self.user_image = image_file.file_url - pass - - -def add_user_to_raven(doc,method): - # called when the user is inserted or updated - # If the auto-create setting is set to True, check if the user is a System user. If yes, then create a Raven User record for the user. - # Else, check if the user has a Raven User role. If yes, then create a Raven User record for the user if not already created. - - # If the user is already added to Raven, do nothing. - if not doc.flags.deleting_raven_user: - if frappe.db.exists("Raven User", {"user": doc.name}): - # Check if the role is still present. If not, then inactivate the Raven User record. - has_raven_role = False - for role in doc.get("roles"): - if role.role == "Raven User": - has_raven_role = True - break - - if has_raven_role: - raven_user = frappe.get_doc("Raven User", {"user": doc.name}) - if not doc.full_name: - raven_user.full_name = doc.first_name - raven_user.enabled = 1 - raven_user.save(ignore_permissions=True) - else: - raven_user = frappe.get_doc("Raven User", {"user": doc.name}) - if not doc.full_name: - raven_user.full_name = doc.first_name - raven_user.enabled = 0 - raven_user.save(ignore_permissions=True) - else: - # Raven user does not exist. Check if the user is a system user. - if doc.user_type == "System User": - # Only create raven user if it exists in the system. - if frappe.db.exists("User", doc.name): - auto_add = frappe.db.get_single_value("Raven Settings", "auto_add_system_users") - - if auto_add: - doc.append("roles", {"role": "Raven User"}) - # Create a Raven User record for the user. - raven_user = frappe.new_doc("Raven User") - raven_user.user = doc.name - if not doc.full_name: - raven_user.full_name = doc.first_name - raven_user.enabled = 1 - raven_user.insert(ignore_permissions=True) - else: - if "Raven User" in [d.role for d in doc.get("roles")]: - # Create a Raven User record for the user. - raven_user = frappe.new_doc("Raven User") - raven_user.user = doc.name - if not doc.full_name: - raven_user.full_name = doc.first_name - raven_user.enabled = 1 - raven_user.insert(ignore_permissions=True) + # begin: auto-generated types + # This code is auto-generated. Do not modify anything in this block. + + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from frappe.types import DF + + enabled: DF.Check + first_name: DF.Data | None + full_name: DF.Data + user: DF.Link + user_image: DF.AttachImage | None + # end: auto-generated types + + def autoname(self): + if self.type == "Bot": + self.name = self.bot + else: + self.name = self.user + + def before_validate(self): + if not self.full_name: + self.full_name = self.first_name + + def before_save(self): + if self.type == "Bot": + self.get_bot_details() + else: + self.update_photo_from_user() + + def after_delete(self): + ''' + Remove the Raven User role from the user. + ''' + user = frappe.get_doc("User", self.user) + user.flags.ignore_permissions = True + user.flags.deleting_raven_user = True + user.remove_roles("Raven User") + user.save() + + def update_photo_from_user(self): + ''' + We need to create a new File record for the user image and attach it to the Raven User record. + Why not just copy the URL from the User record? Because the URL is not accessible to the Raven User, + and Frappe creates a duplicate file in the system (that is public) but does not update the URL in the field. + ''' + user_image = frappe.db.get_value("User", self.user, "user_image") + if user_image and not self.user_image: + image_file = frappe.get_doc( + { + "doctype": "File", + "file_url": user_image, + "attached_to_doctype": "Raven User", + "attached_to_name": self.name, + "attached_to_field": "user_image", + "is_private": 1, + } + ).insert() + self.user_image = image_file.file_url + + def get_bot_details(self): + ''' + Get the bot details for the user. + ''' + bot_details = frappe.db.get_value( + "Raven Bot", self.bot, ["bot_name", "image", "enabled"], as_dict=True) + self.full_name = bot_details.bot_name + self.user_image = bot_details.image + self.enabled = bot_details.enabled + + +def add_user_to_raven(doc, method): + # called when the user is inserted or updated + # If the auto-create setting is set to True, check if the user is a System user. If yes, then create a Raven User record for the user. + # Else, check if the user has a Raven User role. If yes, then create a Raven User record for the user if not already created. + + # If the user is already added to Raven, do nothing. + if not doc.flags.deleting_raven_user: + if frappe.db.exists("Raven User", {"user": doc.name}): + # Check if the role is still present. If not, then inactivate the Raven User record. + has_raven_role = False + for role in doc.get("roles"): + if role.role == "Raven User": + has_raven_role = True + break + + if has_raven_role: + raven_user = frappe.get_doc("Raven User", {"user": doc.name}) + if not doc.full_name: + raven_user.full_name = doc.first_name + raven_user.enabled = 1 + raven_user.save(ignore_permissions=True) + else: + raven_user = frappe.get_doc("Raven User", {"user": doc.name}) + if not doc.full_name: + raven_user.full_name = doc.first_name + raven_user.enabled = 0 + raven_user.save(ignore_permissions=True) + else: + # Raven user does not exist. Check if the user is a system user. + if doc.user_type == "System User": + # Only create raven user if it exists in the system. + if frappe.db.exists("User", doc.name): + auto_add = frappe.db.get_single_value( + "Raven Settings", "auto_add_system_users") + + if auto_add: + doc.append("roles", {"role": "Raven User"}) + # Create a Raven User record for the user. + raven_user = frappe.new_doc("Raven User") + raven_user.user = doc.name + if not doc.full_name: + raven_user.full_name = doc.first_name + raven_user.enabled = 1 + raven_user.insert(ignore_permissions=True) + else: + if "Raven User" in [d.role for d in doc.get("roles")]: + # Create a Raven User record for the user. + raven_user = frappe.new_doc("Raven User") + raven_user.user = doc.name + if not doc.full_name: + raven_user.full_name = doc.first_name + raven_user.enabled = 1 + raven_user.insert(ignore_permissions=True) diff --git a/raven/raven_bot/__init__.py b/raven/raven_bot/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/raven/raven_bot/doctype/__init__.py b/raven/raven_bot/doctype/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/raven/raven_bot/doctype/raven_bot/__init__.py b/raven/raven_bot/doctype/raven_bot/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/raven/raven_bot/doctype/raven_bot/raven_bot.js b/raven/raven_bot/doctype/raven_bot/raven_bot.js new file mode 100644 index 000000000..f6dd2dea3 --- /dev/null +++ b/raven/raven_bot/doctype/raven_bot/raven_bot.js @@ -0,0 +1,8 @@ +// Copyright (c) 2024, The Commit Company and contributors +// For license information, please see license.txt + +// frappe.ui.form.on("Raven Bot", { +// refresh(frm) { + +// }, +// }); diff --git a/raven/raven_bot/doctype/raven_bot/raven_bot.json b/raven/raven_bot/doctype/raven_bot/raven_bot.json new file mode 100644 index 000000000..953e0426d --- /dev/null +++ b/raven/raven_bot/doctype/raven_bot/raven_bot.json @@ -0,0 +1,80 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "field:bot_name", + "creation": "2024-01-19 16:05:10.754915", + "default_view": "List", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "bot_name", + "description", + "image", + "enabled", + "is_standard", + "module" + ], + "fields": [ + { + "fieldname": "description", + "fieldtype": "Data", + "label": "Description" + }, + { + "fieldname": "image", + "fieldtype": "Attach Image", + "label": "Image" + }, + { + "default": "0", + "fieldname": "enabled", + "fieldtype": "Check", + "label": "Enabled" + }, + { + "fieldname": "bot_name", + "fieldtype": "Data", + "label": "Bot Name", + "unique": 1 + }, + { + "default": "0", + "fieldname": "is_standard", + "fieldtype": "Check", + "label": "Is Standard" + }, + { + "fieldname": "module", + "fieldtype": "Link", + "label": "Module", + "mandatory_depends_on": "eval: doc.is_standard == 1", + "options": "Module Def" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2024-01-19 17:31:56.102999", + "modified_by": "Administrator", + "module": "Raven Bot", + "name": "Raven Bot", + "naming_rule": "By fieldname", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/raven/raven_bot/doctype/raven_bot/raven_bot.py b/raven/raven_bot/doctype/raven_bot/raven_bot.py new file mode 100644 index 000000000..3b07f8d96 --- /dev/null +++ b/raven/raven_bot/doctype/raven_bot/raven_bot.py @@ -0,0 +1,14 @@ +# Copyright (c) 2024, The Commit Company and contributors +# For license information, please see license.txt + +import frappe +from frappe.modules.export_file import export_to_files +from frappe.model.document import Document + + +class RavenBot(Document): + def on_update(self): + if frappe.conf.developer_mode and self.is_standard: + export_to_files( + record_list=[["Raven Bot", self.name]], record_module=self.module + ) diff --git a/raven/raven_bot/doctype/raven_bot/test_raven_bot.py b/raven/raven_bot/doctype/raven_bot/test_raven_bot.py new file mode 100644 index 000000000..b163ffe62 --- /dev/null +++ b/raven/raven_bot/doctype/raven_bot/test_raven_bot.py @@ -0,0 +1,9 @@ +# Copyright (c) 2024, The Commit Company and Contributors +# See license.txt + +# import frappe +from frappe.tests.utils import FrappeTestCase + + +class TestRavenBot(FrappeTestCase): + pass diff --git a/raven/raven_messaging/doctype/raven_message/raven_message.json b/raven/raven_messaging/doctype/raven_message/raven_message.json index 7eee68fda..b4d246ed8 100644 --- a/raven/raven_messaging/doctype/raven_message/raven_message.json +++ b/raven/raven_messaging/doctype/raven_message/raven_message.json @@ -22,7 +22,9 @@ "is_reply", "linked_message", "link_doctype", - "link_document" + "link_document", + "is_bot_message", + "bot" ], "fields": [ { @@ -109,11 +111,25 @@ "fieldtype": "Dynamic Link", "label": "Link Document", "options": "link_doctype" + }, + { + "default": "0", + "fieldname": "is_bot_message", + "fieldtype": "Check", + "label": "Is Bot Message" + }, + { + "depends_on": "eval: doc.is_bot_message == 1", + "fieldname": "bot", + "fieldtype": "Link", + "label": "Bot", + "mandatory_depends_on": "eval: doc.is_bot_message == 1", + "options": "Raven User" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-12-22 18:25:02.237368", + "modified": "2024-01-19 17:41:28.463058", "modified_by": "Administrator", "module": "Raven Messaging", "name": "Raven Message", From 4da8451791151307ffc5fc2a67249433fb7ccf9a Mon Sep 17 00:00:00 2001 From: Aditya Patil Date: Fri, 19 Jan 2024 17:59:06 +0530 Subject: [PATCH 02/32] fix: Not assuming User as Human --- mobile/src/types/Raven/RavenUser.ts | 2 +- raven-app/src/types/Raven/RavenUser.ts | 2 +- raven/raven/doctype/raven_user/raven_user.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mobile/src/types/Raven/RavenUser.ts b/mobile/src/types/Raven/RavenUser.ts index 4e44ab791..e1b7e6168 100644 --- a/mobile/src/types/Raven/RavenUser.ts +++ b/mobile/src/types/Raven/RavenUser.ts @@ -11,7 +11,7 @@ export interface RavenUser{ parenttype?: string idx?: number /** Type : Select */ - type: "Human" | "Bot" + type: "User" | "Bot" /** User : Link - User */ user?: string /** Bot : Link - Raven Bot */ diff --git a/raven-app/src/types/Raven/RavenUser.ts b/raven-app/src/types/Raven/RavenUser.ts index 4e44ab791..e1b7e6168 100644 --- a/raven-app/src/types/Raven/RavenUser.ts +++ b/raven-app/src/types/Raven/RavenUser.ts @@ -11,7 +11,7 @@ export interface RavenUser{ parenttype?: string idx?: number /** Type : Select */ - type: "Human" | "Bot" + type: "User" | "Bot" /** User : Link - User */ user?: string /** Bot : Link - Raven Bot */ diff --git a/raven/raven/doctype/raven_user/raven_user.json b/raven/raven/doctype/raven_user/raven_user.json index 20613279f..b57c1004b 100644 --- a/raven/raven/doctype/raven_user/raven_user.json +++ b/raven/raven/doctype/raven_user/raven_user.json @@ -65,7 +65,7 @@ "fieldname": "type", "fieldtype": "Select", "label": "Type", - "options": "Human\nBot", + "options": "User\nBot", "reqd": 1 }, { @@ -78,7 +78,7 @@ ], "image_field": "user_image", "links": [], - "modified": "2024-01-19 16:53:51.574064", + "modified": "2024-01-19 17:53:07.854127", "modified_by": "Administrator", "module": "Raven", "name": "Raven User", From 8fd9782f35b59617527cde85cd0c038b70bd0c9a Mon Sep 17 00:00:00 2001 From: Yash Jane Date: Thu, 25 Jan 2024 16:44:45 +0530 Subject: [PATCH 03/32] feat: add route for Settings page --- raven-app/src/App.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/raven-app/src/App.tsx b/raven-app/src/App.tsx index 31aba6e1a..1c1b72b25 100644 --- a/raven-app/src/App.tsx +++ b/raven-app/src/App.tsx @@ -5,11 +5,11 @@ import { ProtectedRoute } from './utils/auth/ProtectedRoute' import { UserProvider } from './utils/auth/UserProvider' import { ChannelRedirect } from './utils/channel/ChannelRedirect' import "cal-sans"; -import { useState } from 'react' import { ThemeProvider } from './ThemeProvider' import { Toaster } from './components/common/Toast/Toaster' import { FullPageLoader } from './components/layout/Loaders' import { useStickyState } from './hooks/useStickyState' +import { Settings } from './pages/settings/Settings' const router = createBrowserRouter( @@ -23,6 +23,12 @@ const router = createBrowserRouter( import('./components/feature/saved-messages/SavedMessages')} /> import('@/pages/ChatSpace')} /> + }> + + Webhooks

} /> + SS

} /> +
+
), { From 287f14bfb9fd14a8868638996002dd39a8462279 Mon Sep 17 00:00:00 2001 From: Yash Jane Date: Thu, 25 Jan 2024 16:45:12 +0530 Subject: [PATCH 04/32] feat: Sidebar for Settings page (basic routes and layout) --- .../feature/settings/Integrations.tsx | 39 +++++++++++++++++++ .../components/layout/Settings/Sidebar.tsx | 24 ++++++++++++ .../layout/Settings/SidebarBody.tsx | 14 +++++++ .../layout/Settings/SidebarHeader.tsx | 26 +++++++++++++ .../layout/Sidebar/SidebarFooter.tsx | 5 +++ raven-app/src/pages/settings/Settings.tsx | 20 ++++++++++ 6 files changed, 128 insertions(+) create mode 100644 raven-app/src/components/feature/settings/Integrations.tsx create mode 100644 raven-app/src/components/layout/Settings/Sidebar.tsx create mode 100644 raven-app/src/components/layout/Settings/SidebarBody.tsx create mode 100644 raven-app/src/components/layout/Settings/SidebarHeader.tsx create mode 100644 raven-app/src/pages/settings/Settings.tsx diff --git a/raven-app/src/components/feature/settings/Integrations.tsx b/raven-app/src/components/feature/settings/Integrations.tsx new file mode 100644 index 000000000..3444967bd --- /dev/null +++ b/raven-app/src/components/feature/settings/Integrations.tsx @@ -0,0 +1,39 @@ +import { SidebarGroup, SidebarGroupItem, SidebarGroupLabel, SidebarGroupList, SidebarItem } from "@/components/layout/Sidebar" +import { Flex, Text } from "@radix-ui/themes" +import { BiPlug } from "react-icons/bi" + +export interface Props { } + +export const Integrations = (props: Props) => { + return ( + + + {/* */} + + + + Integrations + + + + + + + + + + + ) +} + + +export const IntegrationsItem = ({ route, label }: { route: string, label: string }) => { + + return ( + + + {label} + + + ) +} \ No newline at end of file diff --git a/raven-app/src/components/layout/Settings/Sidebar.tsx b/raven-app/src/components/layout/Settings/Sidebar.tsx new file mode 100644 index 000000000..8f097089f --- /dev/null +++ b/raven-app/src/components/layout/Settings/Sidebar.tsx @@ -0,0 +1,24 @@ +import { Flex, Box, Separator } from "@radix-ui/themes" +import { SidebarBody } from "./SidebarBody" +import { SidebarFooter } from "../Sidebar/SidebarFooter" +import { SidebarHeader } from "./SidebarHeader" + +export interface Props { } + +/** + * Sidebar for Settings page + */ +export const Sidebar = (props: Props) => { + return ( + + + + + + + + + + + ) +} \ No newline at end of file diff --git a/raven-app/src/components/layout/Settings/SidebarBody.tsx b/raven-app/src/components/layout/Settings/SidebarBody.tsx new file mode 100644 index 000000000..f26284c6e --- /dev/null +++ b/raven-app/src/components/layout/Settings/SidebarBody.tsx @@ -0,0 +1,14 @@ +import { Integrations } from "@/components/feature/settings/Integrations" +import { ScrollArea, Flex } from "@radix-ui/themes" + +export interface Props { } + +export const SidebarBody = (props: Props) => { + return ( + + + + + + ) +} \ No newline at end of file diff --git a/raven-app/src/components/layout/Settings/SidebarHeader.tsx b/raven-app/src/components/layout/Settings/SidebarHeader.tsx new file mode 100644 index 000000000..01f6fcf6a --- /dev/null +++ b/raven-app/src/components/layout/Settings/SidebarHeader.tsx @@ -0,0 +1,26 @@ +import { Flex, Text } from "@radix-ui/themes" +import { BiChevronLeft } from "react-icons/bi" +import { useNavigate } from "react-router-dom" + +export interface Props { } + +export const SidebarHeader = (props: Props) => { + + const navigate = useNavigate() + + return ( +
+ navigate('/channel')} + > + + Settings + +
+ ) +} \ No newline at end of file diff --git a/raven-app/src/components/layout/Sidebar/SidebarFooter.tsx b/raven-app/src/components/layout/Sidebar/SidebarFooter.tsx index 65c88f8b3..0dbb6aff3 100644 --- a/raven-app/src/components/layout/Sidebar/SidebarFooter.tsx +++ b/raven-app/src/components/layout/Sidebar/SidebarFooter.tsx @@ -57,6 +57,11 @@ export const SidebarFooter = () => { Mobile App + + + Settings + + Log Out diff --git a/raven-app/src/pages/settings/Settings.tsx b/raven-app/src/pages/settings/Settings.tsx new file mode 100644 index 000000000..d319c370e --- /dev/null +++ b/raven-app/src/pages/settings/Settings.tsx @@ -0,0 +1,20 @@ +import { Sidebar } from "@/components/layout/Settings/Sidebar" +import { Flex, Box } from "@radix-ui/themes" +import { Outlet } from "react-router-dom" + +export interface Props { } + +export const Settings = (props: Props) => { + return ( + <> + + + + + + + + + + ) +} \ No newline at end of file From bd03e2c54d7f53be2d32d9983a164ad5b8a39a0b Mon Sep 17 00:00:00 2001 From: Yash Jane Date: Thu, 25 Jan 2024 17:13:24 +0530 Subject: [PATCH 05/32] style: cursor pointer --- raven-app/src/components/layout/Settings/SidebarHeader.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/raven-app/src/components/layout/Settings/SidebarHeader.tsx b/raven-app/src/components/layout/Settings/SidebarHeader.tsx index 01f6fcf6a..365d30dd7 100644 --- a/raven-app/src/components/layout/Settings/SidebarHeader.tsx +++ b/raven-app/src/components/layout/Settings/SidebarHeader.tsx @@ -16,6 +16,7 @@ export const SidebarHeader = (props: Props) => { gap={'3'} pt='1' height='8' + className="cursor-pointer" onClick={() => navigate('/channel')} > From 536671406db4c6fc85a59b00894466105a9f143d Mon Sep 17 00:00:00 2001 From: Yash Jane Date: Thu, 25 Jan 2024 17:13:52 +0530 Subject: [PATCH 06/32] fix: hide 'Settings' options from Footer menu --- raven-app/src/components/layout/Settings/Sidebar.tsx | 2 +- raven-app/src/components/layout/Sidebar/SidebarFooter.tsx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/raven-app/src/components/layout/Settings/Sidebar.tsx b/raven-app/src/components/layout/Settings/Sidebar.tsx index 8f097089f..4cd74e0a8 100644 --- a/raven-app/src/components/layout/Settings/Sidebar.tsx +++ b/raven-app/src/components/layout/Settings/Sidebar.tsx @@ -18,7 +18,7 @@ export const Sidebar = (props: Props) => { - + ) } \ No newline at end of file diff --git a/raven-app/src/components/layout/Sidebar/SidebarFooter.tsx b/raven-app/src/components/layout/Sidebar/SidebarFooter.tsx index 0dbb6aff3..f35d016bf 100644 --- a/raven-app/src/components/layout/Sidebar/SidebarFooter.tsx +++ b/raven-app/src/components/layout/Sidebar/SidebarFooter.tsx @@ -7,7 +7,7 @@ import { BiDotsHorizontalRounded } from 'react-icons/bi' import { UserAvatar } from '@/components/common/UserAvatar' import { isSystemManager } from '@/utils/roles' -export const SidebarFooter = () => { +export const SidebarFooter = ({ isSettingsPage = false }: { isSettingsPage?: boolean }) => { const userData = useUserData() const { logout } = useContext(UserContext) @@ -57,11 +57,11 @@ export const SidebarFooter = () => { Mobile App - + {!isSettingsPage && Settings - + } Log Out From 78b66ee6a3747314b5c0d676568d13ff7badaa86 Mon Sep 17 00:00:00 2001 From: Aditya Patil Date: Fri, 2 Feb 2024 18:07:36 +0530 Subject: [PATCH 07/32] fix: updated Raven Message doctype --- .../doctype/raven_message/raven_message.json | 354 +++++++++--------- 1 file changed, 178 insertions(+), 176 deletions(-) diff --git a/raven/raven_messaging/doctype/raven_message/raven_message.json b/raven/raven_messaging/doctype/raven_message/raven_message.json index d440c297f..b9bd7c360 100644 --- a/raven/raven_messaging/doctype/raven_message/raven_message.json +++ b/raven/raven_messaging/doctype/raven_message/raven_message.json @@ -1,178 +1,180 @@ { - "actions": [], - "allow_rename": 1, - "autoname": "hash", - "creation": "2023-02-12 17:29:25.498988", - "default_view": "List", - "doctype": "DocType", - "editable_grid": 1, - "engine": "InnoDB", - "field_order": [ - "channel_id", - "text", - "json", - "message_type", - "file", - "image_width", - "image_height", - "file_thumbnail", - "thumbnail_width", - "thumbnail_height", - "message_reactions", - "is_reply", - "linked_message", - "link_doctype", - "link_document", - "is_bot_message", - "bot" - "content" - ], - "fields": [ - { - "fieldname": "channel_id", - "fieldtype": "Link", - "in_list_view": 1, - "in_standard_filter": 1, - "label": "Channel ID", - "options": "Raven Channel", - "reqd": 1, - "search_index": 1 - }, - { - "fieldname": "text", - "fieldtype": "Long Text", - "label": "Text" - }, - { - "fieldname": "json", - "fieldtype": "JSON", - "label": "JSON" - }, - { - "fieldname": "file", - "fieldtype": "Attach", - "label": "File" - }, - { - "fieldname": "message_type", - "fieldtype": "Select", - "label": "Message Type", - "options": "Text\nImage\nFile" - }, - { - "fieldname": "message_reactions", - "fieldtype": "JSON", - "label": "Message Reactions" - }, - { - "default": "0", - "fieldname": "is_reply", - "fieldtype": "Check", - "label": "Is Reply" - }, - { - "fieldname": "linked_message", - "fieldtype": "Link", - "label": "Linked Message", - "options": "Raven Message" - }, - { - "fieldname": "file_thumbnail", - "fieldtype": "Attach", - "label": "File Thumbnail" - }, - { - "fieldname": "image_width", - "fieldtype": "Data", - "label": "Image Width" - }, - { - "fieldname": "image_height", - "fieldtype": "Data", - "label": "Image Height" - }, - { - "fieldname": "thumbnail_width", - "fieldtype": "Data", - "label": "Thumbnail Width" - }, - { - "fieldname": "thumbnail_height", - "fieldtype": "Data", - "label": "Thumbnail Height" - }, - { - "fieldname": "link_doctype", - "fieldtype": "Link", - "label": "Link Doctype", - "options": "DocType" - }, - { - "fieldname": "link_document", - "fieldtype": "Dynamic Link", - "label": "Link Document", - "options": "link_doctype" - }, - { - "default": "0", - "fieldname": "is_bot_message", - "fieldtype": "Check", - "label": "Is Bot Message" - }, - { - "depends_on": "eval: doc.is_bot_message == 1", - "fieldname": "bot", - "fieldtype": "Link", - "label": "Bot", - "mandatory_depends_on": "eval: doc.is_bot_message == 1", - "options": "Raven User" - "fieldname": "content", - "fieldtype": "Long Text", - "label": "Content", - "read_only": 1 - } - ], - "index_web_pages_for_search": 1, - "links": [], - "modified": "2024-01-19 17:41:28.463058", - "modified_by": "Administrator", - "module": "Raven Messaging", - "name": "Raven Message", - "naming_rule": "Random", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "select": 1, - "share": 1, - "write": 1 - }, - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 1, - "print": 1, - "report": 1, - "role": "Raven User", - "share": 1, - "write": 1 - }, - { - "read": 1, - "role": "Raven User" - } - ], - "search_fields": "text", - "sort_field": "modified", - "sort_order": "DESC", - "states": [] + "actions": [], + "allow_rename": 1, + "autoname": "hash", + "creation": "2023-02-12 17:29:25.498988", + "default_view": "List", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "channel_id", + "text", + "json", + "message_type", + "file", + "image_width", + "image_height", + "file_thumbnail", + "thumbnail_width", + "thumbnail_height", + "message_reactions", + "is_reply", + "linked_message", + "link_doctype", + "link_document", + "is_bot_message", + "bot", + "content" + ], + "fields": [ + { + "fieldname": "channel_id", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Channel ID", + "options": "Raven Channel", + "reqd": 1, + "search_index": 1 + }, + { + "fieldname": "text", + "fieldtype": "Long Text", + "label": "Text" + }, + { + "fieldname": "json", + "fieldtype": "JSON", + "label": "JSON" + }, + { + "fieldname": "file", + "fieldtype": "Attach", + "label": "File" + }, + { + "fieldname": "message_type", + "fieldtype": "Select", + "label": "Message Type", + "options": "Text\nImage\nFile" + }, + { + "fieldname": "message_reactions", + "fieldtype": "JSON", + "label": "Message Reactions" + }, + { + "default": "0", + "fieldname": "is_reply", + "fieldtype": "Check", + "label": "Is Reply" + }, + { + "fieldname": "linked_message", + "fieldtype": "Link", + "label": "Linked Message", + "options": "Raven Message" + }, + { + "fieldname": "file_thumbnail", + "fieldtype": "Attach", + "label": "File Thumbnail" + }, + { + "fieldname": "image_width", + "fieldtype": "Data", + "label": "Image Width" + }, + { + "fieldname": "image_height", + "fieldtype": "Data", + "label": "Image Height" + }, + { + "fieldname": "thumbnail_width", + "fieldtype": "Data", + "label": "Thumbnail Width" + }, + { + "fieldname": "thumbnail_height", + "fieldtype": "Data", + "label": "Thumbnail Height" + }, + { + "fieldname": "link_doctype", + "fieldtype": "Link", + "label": "Link Doctype", + "options": "DocType" + }, + { + "fieldname": "link_document", + "fieldtype": "Dynamic Link", + "label": "Link Document", + "options": "link_doctype" + }, + { + "default": "0", + "fieldname": "is_bot_message", + "fieldtype": "Check", + "label": "Is Bot Message" + }, + { + "depends_on": "eval: doc.is_bot_message == 1", + "fieldname": "bot", + "fieldtype": "Link", + "label": "Bot", + "mandatory_depends_on": "eval: doc.is_bot_message == 1", + "options": "Raven User" + }, + { + "fieldname": "content", + "fieldtype": "Long Text", + "label": "Content", + "read_only": 1 + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2024-01-19 17:41:28.463058", + "modified_by": "Administrator", + "module": "Raven Messaging", + "name": "Raven Message", + "naming_rule": "Random", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "select": 1, + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "if_owner": 1, + "print": 1, + "report": 1, + "role": "Raven User", + "share": 1, + "write": 1 + }, + { + "read": 1, + "role": "Raven User" + } + ], + "search_fields": "text", + "sort_field": "modified", + "sort_order": "DESC", + "states": [] } \ No newline at end of file From d21b0b142767cc63d850314a67b200c219fc0db6 Mon Sep 17 00:00:00 2001 From: Sumit Jain Date: Mon, 12 Feb 2024 12:39:07 +0530 Subject: [PATCH 08/32] feat:type files --- raven-app/src/types/Integrations/Webhook.ts | 54 +++++++++++++++++++ .../src/types/Integrations/WebhookData.ts | 17 ++++++ .../src/types/Integrations/WebhookHeader.ts | 17 ++++++ raven-app/src/utils/removeFrappeFields.ts | 14 +++++ 4 files changed, 102 insertions(+) create mode 100644 raven-app/src/types/Integrations/Webhook.ts create mode 100644 raven-app/src/types/Integrations/WebhookData.ts create mode 100644 raven-app/src/types/Integrations/WebhookHeader.ts create mode 100644 raven-app/src/utils/removeFrappeFields.ts diff --git a/raven-app/src/types/Integrations/Webhook.ts b/raven-app/src/types/Integrations/Webhook.ts new file mode 100644 index 000000000..13390acb3 --- /dev/null +++ b/raven-app/src/types/Integrations/Webhook.ts @@ -0,0 +1,54 @@ +import { WebhookHeader } from './WebhookHeader' +import { WebhookData } from './WebhookData' + +export interface Webhook{ + creation: string + name: string + modified: string + owner: string + modified_by: string + docstatus: 0 | 1 | 2 + parent?: string + parentfield?: string + parenttype?: string + idx?: number + /** DocType : Link - DocType */ + webhook_doctype: string + /** Doc Event : Select */ + webhook_docevent?: "after_insert" | "on_update" | "on_submit" | "on_cancel" | "on_trash" | "on_update_after_submit" | "on_change" + /** Enabled : Check */ + enabled?: 0 | 1 + /** Condition : Small Text - The webhook will be triggered if this expression is true */ + condition?: string + /** Request URL : Data */ + request_url: string + /** Request Timeout : Int - The number of seconds until the request expires */ + timeout: number + /** Is Dynamic URL? : Check - On checking this option, URL will be treated like a jinja template string */ + is_dynamic_url?: 0 | 1 + /** Request Method : Select */ + request_method: "POST" | "PUT" | "DELETE" + /** Request Structure : Select */ + request_structure?: "" | "Form URL-Encoded" | "JSON" + /** Enable Security : Check */ + enable_security?: 0 | 1 + /** Webhook Secret : Password */ + webhook_secret?: string + /** Headers : Table - Webhook Header */ + webhook_headers?: WebhookHeader[] + /** Data : Table - Webhook Data */ + webhook_data?: WebhookData[] + /** JSON Request Body : Code - To add dynamic values from the document, use jinja tags like + +
+
{ "id": "{{ doc.name }}" }
+
+
*/ + webhook_json?: string + /** Select Document : Dynamic Link */ + preview_document?: string + /** Meets Condition? : Data */ + meets_condition?: string + /** Request Body : Code */ + preview_request_body?: string +} \ No newline at end of file diff --git a/raven-app/src/types/Integrations/WebhookData.ts b/raven-app/src/types/Integrations/WebhookData.ts new file mode 100644 index 000000000..87b044c18 --- /dev/null +++ b/raven-app/src/types/Integrations/WebhookData.ts @@ -0,0 +1,17 @@ + +export interface WebhookData{ + creation: string + name: string + modified: string + owner: string + modified_by: string + docstatus: 0 | 1 | 2 + parent?: string + parentfield?: string + parenttype?: string + idx?: number + /** Fieldname : Select */ + fieldname: string + /** Key : Data */ + key: string +} \ No newline at end of file diff --git a/raven-app/src/types/Integrations/WebhookHeader.ts b/raven-app/src/types/Integrations/WebhookHeader.ts new file mode 100644 index 000000000..587bb6e0f --- /dev/null +++ b/raven-app/src/types/Integrations/WebhookHeader.ts @@ -0,0 +1,17 @@ + +export interface WebhookHeader{ + creation: string + name: string + modified: string + owner: string + modified_by: string + docstatus: 0 | 1 | 2 + parent?: string + parentfield?: string + parenttype?: string + idx?: number + /** Key : Small Text */ + key?: string + /** Value : Small Text */ + value?: string +} \ No newline at end of file diff --git a/raven-app/src/utils/removeFrappeFields.ts b/raven-app/src/utils/removeFrappeFields.ts new file mode 100644 index 000000000..099cb188d --- /dev/null +++ b/raven-app/src/utils/removeFrappeFields.ts @@ -0,0 +1,14 @@ +import { FrappeDoc } from "frappe-react-sdk"; + +type BaseFields = 'owner' | 'creation' | 'modified' | 'modified_by' | 'docstatus'; +type ChildFields = 'parent' | 'parenttype' | 'parentfield'; +export const removeFrappeFields = (data: FrappeDoc): Omit, BaseFields> => { + + try { + const { owner, creation, modified, modified_by, docstatus, ...withoutBaseFields } = data; + return withoutBaseFields; + } + catch (e) { + return data + } +} \ No newline at end of file From 9b5b88b307ca86591568848563c2f7a48dd3d25b Mon Sep 17 00:00:00 2001 From: Sumit Jain Date: Mon, 12 Feb 2024 12:40:42 +0530 Subject: [PATCH 09/32] feat:webhook form --- raven-app/src/App.tsx | 7 +- .../integrations/webhooks/WebhookForm.tsx | 158 ++++++++ .../integrations/webhooks/WebhookHeaders.tsx | 73 ++++ .../webhooks/WebhookReturnDataFieldTable.tsx | 246 ++++++++++++ .../feature/integrations/webhooks/utils.ts | 367 ++++++++++++++++++ 5 files changed, 850 insertions(+), 1 deletion(-) create mode 100644 raven-app/src/components/feature/integrations/webhooks/WebhookForm.tsx create mode 100644 raven-app/src/components/feature/integrations/webhooks/WebhookHeaders.tsx create mode 100644 raven-app/src/components/feature/integrations/webhooks/WebhookReturnDataFieldTable.tsx create mode 100644 raven-app/src/components/feature/integrations/webhooks/utils.ts diff --git a/raven-app/src/App.tsx b/raven-app/src/App.tsx index 1c1b72b25..c5ef1129b 100644 --- a/raven-app/src/App.tsx +++ b/raven-app/src/App.tsx @@ -10,6 +10,9 @@ import { Toaster } from './components/common/Toast/Toaster' import { FullPageLoader } from './components/layout/Loaders' import { useStickyState } from './hooks/useStickyState' import { Settings } from './pages/settings/Settings' +import { CreateWebhook } from './components/feature/integrations/webhooks/CreateWebhook' +import ViewWebhook from './components/feature/integrations/webhooks/ViewWebhook' +import { WebhookList } from './components/feature/integrations/webhooks/WebhookList' const router = createBrowserRouter( @@ -25,7 +28,9 @@ const router = createBrowserRouter(
}> - Webhooks

} /> + } /> + } /> + } /> SS

} />
diff --git a/raven-app/src/components/feature/integrations/webhooks/WebhookForm.tsx b/raven-app/src/components/feature/integrations/webhooks/WebhookForm.tsx new file mode 100644 index 000000000..9ec259d34 --- /dev/null +++ b/raven-app/src/components/feature/integrations/webhooks/WebhookForm.tsx @@ -0,0 +1,158 @@ +import React, { useMemo } from 'react'; +import { Controller, useFormContext } from 'react-hook-form'; +import { Webhook } from '@/types/Integrations/Webhook' +import { Box, Checkbox, Flex, TextFieldInput, Select, TextArea, Heading, Text } from '@radix-ui/themes'; +import { ErrorText, HelperText, Label } from '@/components/common/Form'; +import { WebhookData } from './WebhookReturnDataFieldTable'; +import { WebhookHeaders } from './WebhookHeaders'; +import { TriggerEvents } from './utils'; + +export interface WebhookFormField extends Webhook { + need_condition: boolean +} + +export const WebhookForm = ({ isEdit = false }: { isEdit?: boolean }) => { + const { register, formState: { errors }, control, setValue, watch } = useFormContext() + + const onTriggerEventChange = (value: string) => { + if (value) { + setValue('webhook_data', []) + const field = TriggerEvents?.find(event => event.key === value) + if (field) { + setValue('webhook_doctype', field.doctype) + setValue('webhook_docevent', field.event) + } + } + } + + const webhookDoctype = watch('webhook_doctype') + + const webhookDocevent = watch('webhook_docevent') + + const security = watch('enable_security') + + const needCondition = watch('need_condition') + + const triggerValue = useMemo(() => { + if (webhookDoctype && webhookDocevent) { + const field = TriggerEvents?.find(event => event.doctype === webhookDoctype && event.event === webhookDocevent) + return field?.key + } + return '' + }, [webhookDoctype, webhookDocevent]) + + return ( + + + + + {errors?.name && {errors.name.message}} + + + + + {errors?.request_url && {errors.request_url.message}} + + + + + The number of seconds until the request expires + {errors?.timeout && {errors.timeout.message}} + + + ( + + field.onChange(!field.value)} /> + + + )} + /> + + {errors?.enable_security && {errors.enable_security.message}} + + {security ? + + + {errors?.webhook_secret && {errors.webhook_secret.message}} + : null} + + + + + + + + Trigger Events + { + TriggerEvents?.map((event, index) => ( + {event.label} + )) + } + + + + + + + ( + + field.onChange(!field.value)} /> + + + )} + /> + + {errors?.enable_security && {errors.enable_security.message}} + + {needCondition && + + + +