From 85a1c618801a7fb34eccab89b44c481acfa796db Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 8 Sep 2021 12:39:16 +0200 Subject: [PATCH] :sparkles: Improve 404 and add broken link static page on viewer. --- frontend/src/app/main.cljs | 11 ++- frontend/src/app/main/data/users.cljs | 4 + frontend/src/app/main/ui.cljs | 14 ++-- frontend/src/app/main/ui/static.cljs | 108 +++++++++++--------------- frontend/src/app/main/ui/viewer.cljs | 9 +++ frontend/translations/en.po | 8 +- frontend/translations/es.po | 8 +- 7 files changed, 89 insertions(+), 73 deletions(-) diff --git a/frontend/src/app/main.cljs b/frontend/src/app/main.cljs index ce862ff133..9a6842730a 100644 --- a/frontend/src/app/main.cljs +++ b/frontend/src/app/main.cljs @@ -42,10 +42,13 @@ (if-let [conform (get-in match [:data :conform])] (let [spath (get conform :path-params ::any) squery (get conform :query-params ::any)] - (-> (dissoc match :params) - (assoc :path-params (us/conform spath (get match :path-params)) - :query-params (us/conform squery (get match :query-params))))) - match))) + (try + (-> (dissoc match :params) + (assoc :path-params (us/conform spath (get match :path-params)) + :query-params (us/conform squery (get match :query-params)))) + (catch :default _ + nil))) + match))) (defn on-navigate [router path] diff --git a/frontend/src/app/main/data/users.cljs b/frontend/src/app/main/data/users.cljs index b1fc5b7964..07ad91268b 100644 --- a/frontend/src/app/main/data/users.cljs +++ b/frontend/src/app/main/data/users.cljs @@ -24,6 +24,10 @@ ;; --- COMMON SPECS +(defn is-authenticated? + [{:keys [id]}] + (and (uuid? id) (not= id uuid/zero))) + (s/def ::id ::us/uuid) (s/def ::fullname ::us/string) (s/def ::email ::us/email) diff --git a/frontend/src/app/main/ui.cljs b/frontend/src/app/main/ui.cljs index de47c6dd12..caa90ece3f 100644 --- a/frontend/src/app/main/ui.cljs +++ b/frontend/src/app/main/ui.cljs @@ -26,7 +26,7 @@ [app.main.ui.render :as render] [app.main.ui.settings :as settings] [app.main.ui.static :as static] - [app.main.ui.viewer :refer [viewer-page]] + [app.main.ui.viewer :as viewer] [app.main.ui.workspace :as workspace] [app.util.timers :as ts] [cljs.pprint :refer [pprint]] @@ -151,11 +151,13 @@ {:keys [index share-id section page-id] :or {section :interactions}} query-params {:keys [file-id]} path-params] [:& fs/fullscreen-wrapper {} - [:& viewer-page {:page-id page-id - :file-id file-id - :section section - :index index - :share-id share-id}]]) + (if (:token query-params) + [:& viewer/breaking-change-notice] + [:& viewer/viewer-page {:page-id page-id + :file-id file-id + :section section + :index index + :share-id share-id}])]) :render-object (do diff --git a/frontend/src/app/main/ui/static.cljs b/frontend/src/app/main/ui/static.cljs index aec0d11bc1..6f630ce14c 100644 --- a/frontend/src/app/main/ui/static.cljs +++ b/frontend/src/app/main/ui/static.cljs @@ -12,82 +12,68 @@ [app.main.store :as st] [app.main.ui.icons :as i] [app.util.i18n :refer [tr]] + [app.util.object :as obj] [app.util.router :as rt] [rumext.alpha :as mf])) -(defn- go-to-dashboard - [profile] - (let [team-id (du/get-current-team-id profile)] - (st/emit! (rt/nav :dashboard-projects {:team-id team-id})))) +(mf/defc static-header + {::mf/wrap-props false} + [props] + (let [children (obj/get props "children") + on-click (mf/use-callback + (fn [] + (let [profile (deref refs/profile)] + (if (du/is-authenticated? profile) + (let [team-id (du/get-current-team-id profile)] + (st/emit! (rt/nav :dashboard-projects {:team-id team-id}))) + (st/emit! (rt/nav :auth-login {}))))))] + + [:section.exception-layout + [:div.exception-header + {:on-click on-click} + i/logo] + [:div.exception-content + [:div.container children]]])) (mf/defc not-found [] - (let [profile (mf/deref refs/profile)] - [:section.exception-layout - [:div.exception-header - {:on-click (partial go-to-dashboard profile)} - i/logo] - [:div.exception-content - [:div.container - [:div.image i/icon-empty] - [:div.main-message (tr "labels.not-found.main-message")] - [:div.desc-message (tr "labels.not-found.desc-message")] - [:div.sign-info - [:span (tr "labels.not-found.auth-info") " " [:b (:email profile)]] - [:a.btn-primary.btn-small - {:on-click (st/emitf (du/logout))} - (tr "labels.sign-out")]]]]])) + [:> static-header {} + [:div.image i/icon-empty] + [:div.main-message (tr "labels.not-found.main-message")] + [:div.desc-message (tr "labels.not-found.desc-message")]]) (mf/defc bad-gateway [] - (let [profile (mf/deref refs/profile)] - [:section.exception-layout - [:div.exception-header - {:on-click (partial go-to-dashboard profile)} - i/logo] - [:div.exception-content - [:div.container - [:div.image i/icon-empty] - [:div.main-message (tr "labels.bad-gateway.main-message")] - [:div.desc-message (tr "labels.bad-gateway.desc-message")] - [:div.sign-info - [:a.btn-primary.btn-small - {:on-click (st/emitf #(dissoc % :exception))} - (tr "labels.retry")]]]]])) + [:> static-header {} + [:div.image i/icon-empty] + [:div.main-message (tr "labels.bad-gateway.main-message")] + [:div.desc-message (tr "labels.bad-gateway.desc-message")] + [:div.sign-info + [:a.btn-primary.btn-small + {:on-click (st/emitf #(dissoc % :exception))} + (tr "labels.retry")]]]) (mf/defc service-unavailable [] - (let [profile (mf/deref refs/profile)] - [:section.exception-layout - [:div.exception-header - {:on-click (partial go-to-dashboard profile)} - i/logo] - [:div.exception-content - [:div.container - [:div.image i/icon-empty] - [:div.main-message (tr "labels.service-unavailable.main-message")] - [:div.desc-message (tr "labels.service-unavailable.desc-message")] - [:div.sign-info - [:a.btn-primary.btn-small - {:on-click (st/emitf #(dissoc % :exception))} - (tr "labels.retry")]]]]])) + [:> static-header {} + [:div.image i/icon-empty] + [:div.main-message (tr "labels.service-unavailable.main-message")] + [:div.desc-message (tr "labels.service-unavailable.desc-message")] + [:div.sign-info + [:a.btn-primary.btn-small + {:on-click (st/emitf #(dissoc % :exception))} + (tr "labels.retry")]]]) (mf/defc internal-error [] - (let [profile (mf/deref refs/profile)] - [:section.exception-layout - [:div.exception-header - {:on-click (partial go-to-dashboard profile)} - i/logo] - [:div.exception-content - [:div.container - [:div.image i/icon-empty] - [:div.main-message (tr "labels.internal-error.main-message")] - [:div.desc-message (tr "labels.internal-error.desc-message")] - [:div.sign-info - [:a.btn-primary.btn-small - {:on-click (st/emitf (dm/assign-exception nil))} - (tr "labels.retry")]]]]])) + [:> static-header {} + [:div.image i/icon-empty] + [:div.main-message (tr "labels.internal-error.main-message")] + [:div.desc-message (tr "labels.internal-error.desc-message")] + [:div.sign-info + [:a.btn-primary.btn-small + {:on-click (st/emitf (dm/assign-exception nil))} + (tr "labels.retry")]]]) (mf/defc exception-page [{:keys [data] :as props}] diff --git a/frontend/src/app/main/ui/viewer.cljs b/frontend/src/app/main/ui/viewer.cljs index 187951266c..36e6c5fc04 100644 --- a/frontend/src/app/main/ui/viewer.cljs +++ b/frontend/src/app/main/ui/viewer.cljs @@ -12,7 +12,9 @@ [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.hooks :as hooks] + [app.main.ui.icons :as i] [app.main.ui.share-link] + [app.main.ui.static :as static] [app.main.ui.viewer.comments :refer [comments-layer]] [app.main.ui.viewer.handoff :as handoff] [app.main.ui.viewer.header :refer [header]] @@ -150,3 +152,10 @@ (when-let [data (mf/deref refs/viewer-data)] (let [key (str (get-in data [:file :id]))] [:& viewer {:params props :data data :key key}]))) + +(mf/defc breaking-change-notice + [] + [:> static/static-header {} + [:div.image i/unchain] + [:div.main-message (tr "viewer.breaking-change.message")] + [:div.desc-message (tr "viewer.breaking-change.description")]]) diff --git a/frontend/translations/en.po b/frontend/translations/en.po index 9e58c52d06..80da61909b 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -2968,4 +2968,10 @@ msgid "workspace.updates.update" msgstr "Update" msgid "workspace.viewport.click-to-close-path" -msgstr "Click to close the path" \ No newline at end of file +msgstr "Click to close the path" + +msgid "viewer.breaking-change.message" +msgstr "Sorry!" + +msgid "viewer.breaking-change.description" +msgstr "This shareable link is no longer valid. Create a new one or ask the owner for a new one. diff --git a/frontend/translations/es.po b/frontend/translations/es.po index 5ebcd0ca3c..f2c97d48e8 100644 --- a/frontend/translations/es.po +++ b/frontend/translations/es.po @@ -2853,4 +2853,10 @@ msgid "workspace.updates.update" msgstr "Actualizar" msgid "workspace.viewport.click-to-close-path" -msgstr "Pulsar para cerrar la ruta" \ No newline at end of file +msgstr "Pulsar para cerrar la ruta" + +msgid "viewer.breaking-change.message" +msgstr "¡Lo sentimos!" + +msgid "viewer.breaking-change.description" +msgstr "Este link compartido ya no funciona. Crea uno nuevo o pídelo a la persona que lo creó."