feat: Creates 404 page for public portal [CW-2727] (#8293)
Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
committed by
GitHub
parent
23ea829510
commit
3b84b0fc47
@@ -39,10 +39,6 @@ class Public::Api::V1::Portals::ArticlesController < Public::Api::V1::Portals::B
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def portal
|
|
||||||
@portal ||= Portal.find_by!(slug: permitted_params[:slug], archived: false)
|
|
||||||
end
|
|
||||||
|
|
||||||
def list_params
|
def list_params
|
||||||
params.permit(:query, :locale, :sort, :status)
|
params.permit(:query, :locale, :sort, :status)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ class Public::Api::V1::Portals::BaseController < PublicController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def portal
|
||||||
|
@portal ||= Portal.find_by!(slug: params[:slug], archived: false)
|
||||||
|
end
|
||||||
|
|
||||||
def set_locale(&)
|
def set_locale(&)
|
||||||
switch_locale_with_portal(&) if params[:locale].present?
|
switch_locale_with_portal(&) if params[:locale].present?
|
||||||
switch_locale_with_article(&) if params[:article_slug].present?
|
switch_locale_with_article(&) if params[:article_slug].present?
|
||||||
@@ -40,6 +44,8 @@ class Public::Api::V1::Portals::BaseController < PublicController
|
|||||||
|
|
||||||
def switch_locale_with_article(&)
|
def switch_locale_with_article(&)
|
||||||
article = Article.find_by(slug: params[:article_slug])
|
article = Article.find_by(slug: params[:article_slug])
|
||||||
|
Rails.logger.info "Article: not found for slug: #{params[:article_slug]}"
|
||||||
|
render_404 && return if article.blank?
|
||||||
|
|
||||||
@locale = if article.category.present?
|
@locale = if article.category.present?
|
||||||
article.category.locale
|
article.category.locale
|
||||||
@@ -53,4 +59,9 @@ class Public::Api::V1::Portals::BaseController < PublicController
|
|||||||
def allow_iframe_requests
|
def allow_iframe_requests
|
||||||
response.headers.delete('X-Frame-Options') if @is_plain_layout_enabled
|
response.headers.delete('X-Frame-Options') if @is_plain_layout_enabled
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_404
|
||||||
|
portal
|
||||||
|
render 'public/api/v1/portals/error/404', status: :not_found
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,10 +13,9 @@ class Public::Api::V1::Portals::CategoriesController < Public::Api::V1::Portals:
|
|||||||
private
|
private
|
||||||
|
|
||||||
def set_category
|
def set_category
|
||||||
@category = @portal.categories.find_by!(locale: params[:locale], slug: params[:category_slug])
|
@category = @portal.categories.find_by(locale: params[:locale], slug: params[:category_slug])
|
||||||
end
|
|
||||||
|
|
||||||
def portal
|
Rails.logger.info "Category: not found for slug: #{params[:category_slug]}"
|
||||||
@portal ||= Portal.find_by!(slug: params[:slug], archived: false)
|
render_404 && return if @category.blank?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
12
app/views/public/api/v1/portals/error/404.html.erb
Normal file
12
app/views/public/api/v1/portals/error/404.html.erb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<div class="max-w-6xl h-full w-full flex-grow flex flex-col items-center justify-center mx-auto py-16 px-4 relative">
|
||||||
|
<div class="text-center mb-12">
|
||||||
|
<span class="text-8xl">🔍</span>
|
||||||
|
</div>
|
||||||
|
<h1 class="text-6xl text-center font-semibold text-slate-800 dark:text-slate-100 leading-relaxed"><%= I18n.t('public_portal.404.title') %></h1>
|
||||||
|
<p class="text-center text-slate-700 dark:text-slate-300 my-1"><%= I18n.t('public_portal.404.description') %></p>
|
||||||
|
<div class="text-center my-8">
|
||||||
|
<a href="/hc/<%= @portal.slug %>/<%= @portal.config['default_locale'] || params[:locale] %>/<%= @theme.present? ? '?theme='+@theme : '' %>" class="text-woot-500 font-semibold underline">
|
||||||
|
<%= I18n.t('public_portal.404.back_to_home') %>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -220,6 +220,10 @@ en:
|
|||||||
made_with: Made with
|
made_with: Made with
|
||||||
header:
|
header:
|
||||||
go_to_homepage: Go to the main site
|
go_to_homepage: Go to the main site
|
||||||
|
404:
|
||||||
|
title: Page not found
|
||||||
|
description: We couldn't find the page you were looking for.
|
||||||
|
back_to_home: Go to home page
|
||||||
slack_unfurl:
|
slack_unfurl:
|
||||||
fields:
|
fields:
|
||||||
name: Name
|
name: Name
|
||||||
|
|||||||
Reference in New Issue
Block a user