Merge branch 'develop' into feat-macros-frontend

This commit is contained in:
Fayaz Ahmed 2022-09-23 16:06:01 +05:30 committed by GitHub
commit 3685ca1091
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 91 additions and 10 deletions

View file

@ -135,7 +135,7 @@ GEM
byebug (11.1.3)
climate_control (1.1.1)
coderay (1.1.3)
commonmarker (0.23.5)
commonmarker (0.23.6)
concurrent-ruby (1.1.10)
connection_pool (2.2.5)
crack (0.4.5)

View file

@ -16,7 +16,9 @@ class Api::V1::Accounts::MacrosController < Api::V1::Accounts::BaseController
@macro.save!
end
def show; end
def show
head :not_found if @macro.nil?
end
def destroy
@macro.destroy!

View file

@ -1,6 +1,7 @@
class Public::Api::V1::PortalsController < PublicController
before_action :ensure_custom_domain_request, only: [:show]
before_action :portal
before_action :redirect_to_portal_with_locale, only: [:show]
layout 'portal'
def show; end
@ -9,5 +10,12 @@ class Public::Api::V1::PortalsController < PublicController
def portal
@portal ||= Portal.find_by!(slug: params[:slug], archived: false)
@locale = params[:locale] || @portal.default_locale
end
def redirect_to_portal_with_locale
return if params[:locale].present?
redirect_to "/hc/#{@portal.slug}/#{@portal.default_locale}"
end
end

View file

@ -188,6 +188,10 @@ export default {
return false;
},
message() {
if (this.contentType === 'input_csat') {
return this.$t('CONVERSATION.CSAT_REPLY_MESSAGE');
}
// If the message is an email, emailMessageContent would be present
// In that case, we would use letter package to render the email
if (this.emailMessageContent && this.isIncoming) {

View file

@ -4,7 +4,12 @@ export const buildPortalURL = portalSlug => {
return `${baseURL}/hc/${portalSlug}`;
};
export const buildPortalArticleURL = (portalSlug, categorySlug, articleId) => {
export const buildPortalArticleURL = (
portalSlug,
categorySlug,
locale,
articleId
) => {
const portalURL = buildPortalURL(portalSlug);
return `${portalURL}/${categorySlug}/${articleId}`;
return `${portalURL}/${locale}/${categorySlug}/${articleId}`;
};

View file

@ -0,0 +1,29 @@
import { buildPortalArticleURL, buildPortalURL } from '../portalHelper';
describe('PortalHelper', () => {
describe('buildPortalURL', () => {
it('returns the correct url', () => {
window.chatwootConfig = {
hostURL: 'https://app.chatwoot.com',
helpCenterURL: 'https://help.chatwoot.com',
};
expect(buildPortalURL('handbook')).toEqual(
'https://help.chatwoot.com/hc/handbook'
);
window.chatwootConfig = {};
});
});
describe('buildPortalArticleURL', () => {
it('returns the correct url', () => {
window.chatwootConfig = {
hostURL: 'https://app.chatwoot.com',
helpCenterURL: 'https://help.chatwoot.com',
};
expect(buildPortalArticleURL('handbook', 'culture', 'fr', 1)).toEqual(
'https://help.chatwoot.com/hc/handbook/fr/culture/1'
);
window.chatwootConfig = {};
});
});
});

View file

@ -1,6 +1,7 @@
{
"CONVERSATION": {
"SELECT_A_CONVERSATION": "Please select a conversation from left pane",
"CSAT_REPLY_MESSAGE": "Please rate the conversation",
"404": "Sorry, we cannot find the conversation. Please try again",
"SWITCH_VIEW_LAYOUT": "Switch the layout",
"DASHBOARD_APP_TAB_MESSAGES": "Messages",

View file

@ -1,8 +1,9 @@
<template>
<div class="edit-article--container">
<input
<resizable-text-area
v-model="articleTitle"
type="text"
rows="1"
class="article-heading"
:placeholder="$t('HELP_CENTER.EDIT_ARTICLE.TITLE_PLACEHOLDER')"
@focus="onFocus"
@ -23,11 +24,13 @@
<script>
import { debounce } from '@chatwoot/utils';
import ResizableTextArea from 'shared/components/ResizableTextArea';
import WootMessageEditor from 'dashboard/components/widgets/WootWriter/Editor.vue';
export default {
components: {
WootMessageEditor,
ResizableTextArea,
},
props: {
article: {
@ -83,7 +86,8 @@ export default {
font-size: var(--font-size-giga);
font-weight: var(--font-weight-bold);
min-height: var(--space-jumbo);
max-height: var(--space-jumbo);
max-height: 64rem;
height: auto;
border: 0px solid transparent;
padding: 0;
color: var(--s-900);

View file

@ -90,6 +90,7 @@ export default {
return buildPortalArticleURL(
slug,
this.article.category.slug,
this.article.category.locale,
this.article.id
);
},

View file

@ -149,6 +149,7 @@ export default {
.container {
padding: 0 var(--space-normal);
width: 100%;
overflow: auto;
.articles--loader {
align-items: center;
display: flex;

View file

@ -126,5 +126,6 @@ export default {
}
.is-sidebar-open {
flex: 0.7;
flex-grow: 1;
}
</style>

View file

@ -11,4 +11,12 @@ class ApplicationRecord < ActiveRecord::Base
"#{self.class.name}Drop".constantize.new(self)
end
private
def normalize_empty_string_to_nil(attrs = [])
attrs.each do |attr|
self[attr] = nil if self[attr].blank?
end
end
end

View file

@ -38,6 +38,7 @@ class Portal < ApplicationRecord
source: :user
has_one_attached :logo
before_validation -> { normalize_empty_string_to_nil(%i[custom_domain homepage_link]) }
validates :account_id, presence: true
validates :name, presence: true
validates :slug, presence: true, uniqueness: true

View file

@ -10,6 +10,7 @@ json.category do
json.id article.category_id
json.name article.category.name
json.slug article.category.slug
json.locale article.category.locale
end
if article.portal.present?

View file

@ -15,7 +15,7 @@
</div>
<% else %>
<% category.articles.published.take(5).each do |article| %>
<div class="flex justify-between content-center h-8 my-1">
<div class="flex justify-between content-center my-1">
<a
class="text-slate-800 hover:underline leading-8"
href="/hc/<%= portal.slug %>/<%= category.locale %>/<%= category.slug %>/<%= article.id %>"

View file

@ -17,6 +17,7 @@
</div>
<% end %>
</div>
<% if @portal.config["allowed_locales"].length > 1 %>
<div class="flex items-center">
<div class="inline-flex relative w-24">
<select
@ -32,5 +33,6 @@
</div>
</div>
</div>
<% end %>
</nav>
</header>

View file

@ -1,7 +1,7 @@
<%= render "public/api/v1/portals/hero", portal: @portal %>
<div class="max-w-5xl w-full flex-grow mx-auto py-8 px-4">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-x-32 gap-y-0 lg:gap-y-12">
<% @portal.categories.where(locale: params[:locale]).each do |category| %>
<% @portal.categories.where(locale: @locale).each do |category| %>
<%= render "public/api/v1/portals/category-block", category: category, portal: @portal %>
<% end %>
</div>

View file

@ -1,5 +1,5 @@
shared: &shared
version: '2.9.0'
version: '2.9.1'
development:
<<: *shared

View file

@ -287,6 +287,7 @@ Rails.application.routes.draw do
end
end
get 'hc/:slug', to: 'public/api/v1/portals#show'
get 'hc/:slug/:locale', to: 'public/api/v1/portals#show'
get 'hc/:slug/:locale/categories', to: 'public/api/v1/portals/categories#index'
get 'hc/:slug/:locale/:category_slug', to: 'public/api/v1/portals/categories#show'

View file

@ -1,6 +1,6 @@
{
"name": "@chatwoot/chatwoot",
"version": "2.9.0",
"version": "2.9.1",
"license": "MIT",
"scripts": {
"eslint": "eslint app/**/*.{js,vue}",

View file

@ -173,6 +173,13 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
expect(json_response['payload']['name']).to eql(macro.name)
expect(json_response['payload']['created_by']['id']).to eql(administrator.id)
end
it 'return not_found status when macros not available' do
get "/api/v1/accounts/#{account.id}/macros/15",
headers: administrator.create_new_auth_token
expect(response).to have_http_status(:not_found)
end
end
end

View file

@ -32,6 +32,11 @@ RSpec.describe Portal, type: :model do
expect(portal).not_to be_valid
expect(portal.errors.full_messages[0]).to eq('Cofig in portal on some_other_key is not supported.')
end
it 'converts empty string to nil' do
portal.update(custom_domain: '')
expect(portal.custom_domain).to be_nil
end
end
end
end