diff --git a/app/controllers/api/v1/accounts/portals_controller.rb b/app/controllers/api/v1/accounts/portals_controller.rb index f994f6722..c3d8ad024 100644 --- a/app/controllers/api/v1/accounts/portals_controller.rb +++ b/app/controllers/api/v1/accounts/portals_controller.rb @@ -18,8 +18,6 @@ class Api::V1::Accounts::PortalsController < Api::V1::Accounts::BaseController def create @portal = Current.account.portals.build(portal_params) - render json: { error: @portal.errors.messages }, status: :unprocessable_entity and return unless @portal.valid? - @portal.save! process_attached_logo end diff --git a/app/javascript/dashboard/helper/commons.js b/app/javascript/dashboard/helper/commons.js index 346628985..d50080e82 100644 --- a/app/javascript/dashboard/helper/commons.js +++ b/app/javascript/dashboard/helper/commons.js @@ -75,3 +75,10 @@ export const convertToCategorySlug = text => { .replace(/[^\w ]+/g, '') .replace(/ +/g, '-'); }; + +export const convertToPortalSlug = text => { + return text + .toLowerCase() + .replace(/[^\w ]+/g, '') + .replace(/ +/g, '-'); +}; diff --git a/app/javascript/dashboard/helper/specs/commons.spec.js b/app/javascript/dashboard/helper/specs/commons.spec.js index 3ab06c02a..85e2beb37 100644 --- a/app/javascript/dashboard/helper/specs/commons.spec.js +++ b/app/javascript/dashboard/helper/specs/commons.spec.js @@ -3,6 +3,7 @@ import { createPendingMessage, convertToAttributeSlug, convertToCategorySlug, + convertToPortalSlug, } from '../commons'; describe('#getTypingUsersText', () => { @@ -104,3 +105,9 @@ describe('convertToCategorySlug', () => { ); }); }); + +describe('convertToPortalSlug', () => { + it('should convert to slug', () => { + expect(convertToPortalSlug('Room rental')).toBe('room-rental'); + }); +}); diff --git a/app/javascript/dashboard/i18n/locale/en/helpCenter.json b/app/javascript/dashboard/i18n/locale/en/helpCenter.json index 15792bc97..4e70fc58d 100644 --- a/app/javascript/dashboard/i18n/locale/en/helpCenter.json +++ b/app/javascript/dashboard/i18n/locale/en/helpCenter.json @@ -74,6 +74,54 @@ } } } + }, + "ADD": { + "TITLE": "Create a portal", + "SUB_TITLE": "A Help Center in Chatwoot is known as a portal. You can have multiple portals and can have different locales for each portal.", + "NAME": { + "LABEL": "Name", + "PLACEHOLDER": "Portal name", + "HELP_TEXT": "The name will be used in the public facing portal internally", + "ERROR": "Name is required" + }, + "PAGE_TITLE": { + "LABEL": "Page Title", + "PLACEHOLDER": "Portal page title", + "HELP_TEXT": "The name will be used in the public facing portal", + "ERROR": "Page title is required" + }, + "SLUG": { + "LABEL": "Slug", + "PLACEHOLDER": "Portal slug for urls", + "HELP_TEXT": "app.chatwoot.com/portal/my-portal", + "ERROR": "Slug is required" + }, + "DOMAIN": { + "LABEL": "Custom Domain", + "PLACEHOLDER": "Portal custom domain", + "HELP_TEXT": "Add only If you want to use a custom domain for your portals", + "ERROR": "Custom Domain is required" + }, + "HOME_PAGE_LINK": { + "LABEL": "Home Page Link", + "PLACEHOLDER": "Portal home page link", + "HELP_TEXT": "The link used to return from the portal to the home page.", + "ERROR": "Home Page Link is required" + }, + "HEADER_TEXT": { + "LABEL": "Header Text", + "PLACEHOLDER": "Portal header text", + "HELP_TEXT": "Portal header text", + "ERROR": "Portal header text is required" + }, + "BUTTONS": { + "CREATE": "Create portal", + "CANCEL": "Cancel" + }, + "API": { + "SUCCESS_MESSAGE": "Portal created successfully.", + "ERROR_MESSAGE": "Couldn't create the portal. Try again." + } } }, "TABLE": { diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/components/AddPortal.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/components/AddPortal.vue new file mode 100644 index 000000000..aa526fd99 --- /dev/null +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/components/AddPortal.vue @@ -0,0 +1,185 @@ + + + + diff --git a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/portals/ListAllPortals.vue b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/portals/ListAllPortals.vue index 7420d8047..4ce773921 100644 --- a/app/javascript/dashboard/routes/dashboard/helpcenter/pages/portals/ListAllPortals.vue +++ b/app/javascript/dashboard/routes/dashboard/helpcenter/pages/portals/ListAllPortals.vue @@ -2,7 +2,7 @@

{{ $t('HELP_CENTER.PORTAL.HEADER') }}

- + {{ $t('HELP_CENTER.PORTAL.NEW_BUTTON') }}
@@ -22,6 +22,9 @@ :title="$t('HELP_CENTER.PORTAL.NO_PORTALS_MESSAGE')" />
+ + + @@ -30,11 +33,18 @@ import { mapGetters } from 'vuex'; import PortalListItem from '../../components/PortalListItem'; import Spinner from 'shared/components/Spinner.vue'; import EmptyState from 'dashboard/components/widgets/EmptyState'; +import AddPortal from '../../components/AddPortal'; export default { components: { PortalListItem, EmptyState, Spinner, + AddPortal, + }, + data() { + return { + isAddModalOpen: false, + }; }, computed: { ...mapGetters({ @@ -50,8 +60,11 @@ export default { }, }, methods: { - createPortal() { - this.$emit('create-portal'); + addPortal() { + this.isAddModalOpen = !this.isAddModalOpen; + }, + closeModal() { + this.isAddModalOpen = false; }, }, }; diff --git a/app/javascript/dashboard/store/modules/helpCenterPortals/actions.js b/app/javascript/dashboard/store/modules/helpCenterPortals/actions.js index c9a17b6bb..5afdead83 100644 --- a/app/javascript/dashboard/store/modules/helpCenterPortals/actions.js +++ b/app/javascript/dashboard/store/modules/helpCenterPortals/actions.js @@ -26,13 +26,20 @@ export const actions = { } }, - create: async ({ commit }, params) => { + create: async ({ commit, state, dispatch }, params) => { commit(types.SET_UI_FLAG, { isCreating: true }); try { const { data } = await portalAPIs.create(params); const { id: portalId } = data; commit(types.ADD_PORTAL_ENTRY, data); commit(types.ADD_PORTAL_ID, portalId); + const { + portals: { selectedPortalId }, + } = state; + // Check if there are any selected portal + if (!selectedPortalId) { + dispatch('setPortalId', portalId); + } } catch (error) { throwErrorMessage(error); } finally { diff --git a/app/javascript/dashboard/store/modules/helpCenterPortals/specs/actions.spec.js b/app/javascript/dashboard/store/modules/helpCenterPortals/specs/actions.spec.js index 7f0c646a2..c78a2a97c 100644 --- a/app/javascript/dashboard/store/modules/helpCenterPortals/specs/actions.spec.js +++ b/app/javascript/dashboard/store/modules/helpCenterPortals/specs/actions.spec.js @@ -43,7 +43,7 @@ describe('#actions', () => { it('sends correct actions if API is success', async () => { axios.post.mockResolvedValue({ data: apiResponse.payload[1] }); await actions.create( - { commit }, + { commit, dispatch, state: { portals: { selectedPortalId: null } } }, { color: 'red', custom_domain: 'domain_for_help', @@ -59,7 +59,12 @@ describe('#actions', () => { }); it('sends correct actions if API is error', async () => { axios.post.mockRejectedValue({ message: 'Incorrect header' }); - await expect(actions.create({ commit }, {})).rejects.toThrow(Error); + await expect( + actions.create( + { commit, dispatch, state: { portals: { selectedPortalId: null } } }, + {} + ) + ).rejects.toThrow(Error); expect(commit.mock.calls).toEqual([ [types.SET_UI_FLAG, { isCreating: true }], [types.SET_UI_FLAG, { isCreating: false }],