From e9ba4200b296240c00051945762f23ed3743d95f Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Mon, 25 Nov 2024 06:16:00 +0530 Subject: [PATCH] feat: Add custom attributes components (#10467) --- .../CustomAttributes/CheckboxAttribute.vue | 46 ++++ .../CustomAttributes/DateAttribute.vue | 148 +++++++++++++ .../CustomAttributes/ListAttribute.vue | 100 +++++++++ .../CustomAttributes/OtherAttribute.vue | 202 ++++++++++++++++++ .../story/CustomAttributes.story.vue | 83 +++++++ .../CustomAttributes/story/fixtures.js | 39 ++++ .../components-next/switch/Switch.story.vue | 56 +++++ .../components-next/switch/Switch.vue | 38 ++++ .../dashboard/i18n/locale/en/components.json | 3 + .../dashboard/i18n/locale/en/contact.json | 25 +++ 10 files changed, 740 insertions(+) create mode 100644 app/javascript/dashboard/components-next/CustomAttributes/CheckboxAttribute.vue create mode 100644 app/javascript/dashboard/components-next/CustomAttributes/DateAttribute.vue create mode 100644 app/javascript/dashboard/components-next/CustomAttributes/ListAttribute.vue create mode 100644 app/javascript/dashboard/components-next/CustomAttributes/OtherAttribute.vue create mode 100644 app/javascript/dashboard/components-next/CustomAttributes/story/CustomAttributes.story.vue create mode 100644 app/javascript/dashboard/components-next/CustomAttributes/story/fixtures.js create mode 100644 app/javascript/dashboard/components-next/switch/Switch.story.vue create mode 100644 app/javascript/dashboard/components-next/switch/Switch.vue diff --git a/app/javascript/dashboard/components-next/CustomAttributes/CheckboxAttribute.vue b/app/javascript/dashboard/components-next/CustomAttributes/CheckboxAttribute.vue new file mode 100644 index 000000000..d5ecc3aab --- /dev/null +++ b/app/javascript/dashboard/components-next/CustomAttributes/CheckboxAttribute.vue @@ -0,0 +1,46 @@ + + + + + + + + diff --git a/app/javascript/dashboard/components-next/CustomAttributes/DateAttribute.vue b/app/javascript/dashboard/components-next/CustomAttributes/DateAttribute.vue new file mode 100644 index 000000000..f564f0d1c --- /dev/null +++ b/app/javascript/dashboard/components-next/CustomAttributes/DateAttribute.vue @@ -0,0 +1,148 @@ + + + + + + {{ formattedDate }} + + + + + + + + + + + + + diff --git a/app/javascript/dashboard/components-next/CustomAttributes/ListAttribute.vue b/app/javascript/dashboard/components-next/CustomAttributes/ListAttribute.vue new file mode 100644 index 000000000..a9831762f --- /dev/null +++ b/app/javascript/dashboard/components-next/CustomAttributes/ListAttribute.vue @@ -0,0 +1,100 @@ + + + + + + + {{ + attribute.value || + t('CONTACTS_LAYOUT.SIDEBAR.ATTRIBUTES.TRIGGER.SELECT') + }} + + + + + + + + + + diff --git a/app/javascript/dashboard/components-next/CustomAttributes/OtherAttribute.vue b/app/javascript/dashboard/components-next/CustomAttributes/OtherAttribute.vue new file mode 100644 index 000000000..8b5b538c3 --- /dev/null +++ b/app/javascript/dashboard/components-next/CustomAttributes/OtherAttribute.vue @@ -0,0 +1,202 @@ + + + + + + + + {{ attribute.value }} + + + {{ + attribute.value || + t('CONTACTS_LAYOUT.SIDEBAR.ATTRIBUTES.TRIGGER.INPUT') + }} + + + + + + + + + + + + + + diff --git a/app/javascript/dashboard/components-next/CustomAttributes/story/CustomAttributes.story.vue b/app/javascript/dashboard/components-next/CustomAttributes/story/CustomAttributes.story.vue new file mode 100644 index 000000000..ea87a3f0c --- /dev/null +++ b/app/javascript/dashboard/components-next/CustomAttributes/story/CustomAttributes.story.vue @@ -0,0 +1,83 @@ + + + + + + + + + + {{ attribute.attributeDisplayName }} + + + handleUpdate(attribute.attributeDisplayType, value) + " + @delete="() => handleDelete(attribute.attributeDisplayType)" + /> + + + + + + + + + + {{ attribute.attributeDisplayName }} + + + handleUpdate(attribute.attributeDisplayType, value) + " + @delete="() => handleDelete(attribute.attributeDisplayType)" + /> + + + + + diff --git a/app/javascript/dashboard/components-next/CustomAttributes/story/fixtures.js b/app/javascript/dashboard/components-next/CustomAttributes/story/fixtures.js new file mode 100644 index 000000000..7cd600dcf --- /dev/null +++ b/app/javascript/dashboard/components-next/CustomAttributes/story/fixtures.js @@ -0,0 +1,39 @@ +export default [ + { + attributeKey: 'textContact', + attributeDisplayName: 'Text Input', + attributeDisplayType: 'text', + value: 'Sample text value', + }, + { + attributeKey: 'linkContact', + attributeDisplayName: 'URL Input', + attributeDisplayType: 'link', + value: 'https://www.chatwoot.com', + }, + { + attributeKey: 'numberContact', + attributeDisplayName: 'Number Input', + attributeDisplayType: 'number', + value: '42', + }, + { + attributeKey: 'listContact', + attributeDisplayName: 'List Input', + attributeDisplayType: 'list', + value: 'Option 2', + attributeValues: ['Option 1', 'Option 2', 'Option 3'], + }, + { + attributeKey: 'dateContact', + attributeDisplayName: 'Date Input', + attributeDisplayType: 'date', + value: '2024-03-25T00:00:00.000Z', + }, + { + attributeKey: 'checkboxContact', + attributeDisplayName: 'Checkbox Input', + attributeDisplayType: 'checkbox', + value: true, + }, +]; diff --git a/app/javascript/dashboard/components-next/switch/Switch.story.vue b/app/javascript/dashboard/components-next/switch/Switch.story.vue new file mode 100644 index 000000000..9e4f7ae63 --- /dev/null +++ b/app/javascript/dashboard/components-next/switch/Switch.story.vue @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + Default: + + + + + Checked: + + + + + + + + + Last change: {{ lastChange }} + + + + + + + + + + diff --git a/app/javascript/dashboard/components-next/switch/Switch.vue b/app/javascript/dashboard/components-next/switch/Switch.vue new file mode 100644 index 000000000..e8f409c0e --- /dev/null +++ b/app/javascript/dashboard/components-next/switch/Switch.vue @@ -0,0 +1,38 @@ + + + + + {{ t('SWITCH.TOGGLE') }} + + + diff --git a/app/javascript/dashboard/i18n/locale/en/components.json b/app/javascript/dashboard/i18n/locale/en/components.json index f5207fde9..69cd57fee 100644 --- a/app/javascript/dashboard/i18n/locale/en/components.json +++ b/app/javascript/dashboard/i18n/locale/en/components.json @@ -31,6 +31,9 @@ "BREADCRUMB": { "ARIA_LABEL": "Breadcrumb" }, + "SWITCH": { + "TOGGLE": "Toggle switch" + }, "LABEL": { "TAG_BUTTON": "tag" } diff --git a/app/javascript/dashboard/i18n/locale/en/contact.json b/app/javascript/dashboard/i18n/locale/en/contact.json index 28335dcf8..defc28e67 100644 --- a/app/javascript/dashboard/i18n/locale/en/contact.json +++ b/app/javascript/dashboard/i18n/locale/en/contact.json @@ -442,6 +442,31 @@ } }, "SIDEBAR": { + "ATTRIBUTES": { + "SEARCH_PLACEHOLDER": "Search for attributes", + "UNUSED_ATTRIBUTES": "{count} Used attribute | {count} Unused attributes", + "EMPTY_STATE": "There are no contact custom attributes available in this account. You can create a custom attribute in settings.", + "YES": "Yes", + "NO": "No", + "TRIGGER": { + "SELECT": "Select value", + "INPUT": "Enter value" + }, + "VALIDATIONS": { + "INVALID_NUMBER": "Invalid number", + "REQUIRED": "Valid value is required", + "INVALID_INPUT": "Invalid input", + "INVALID_URL": "Invalid URL", + "INVALID_DATE": "Invalid date" + }, + "NO_ATTRIBUTES": "No attributes found", + "API": { + "SUCCESS_MESSAGE": "Attribute updated successfully", + "DELETE_SUCCESS_MESSAGE": "Attribute deleted successfully", + "UPDATE_ERROR": "Unable to update attribute. Please try again later", + "DELETE_ERROR": "Unable to delete attribute. Please try again later" + } + }, "MERGE": { "TITLE": "Merge contact", "DESCRIPTION": "Combine two profiles into one, including all attributes and conversations. In case of conflict, the primary contact’s attributes will take precedence.",