From 9f19e334c140554d8467b4b3794649f238964667 Mon Sep 17 00:00:00 2001 From: Peter Zimon Date: Wed, 24 Apr 2024 08:42:22 +0200 Subject: [PATCH] Improve technical errors (#20046) ref DES-229 Some of the error messages in Ghost and more specifically in Settings were very technical, e.g. `ValidationError: Validation (isEmpty) failed for locale` This PR deals with some of the occurances for a more human error communication. --- .../src/global/form/TextArea.stories.tsx | 9 --------- .../src/global/form/TextArea.tsx | 1 - .../integrations/AddIntegrationModal.tsx | 1 + .../integrations/CustomIntegrationModal.tsx | 10 ++++++++-- .../advanced/integrations/WebhookModal.tsx | 3 +++ .../components/settings/email/Newsletters.tsx | 4 ++-- .../email/newsletters/AddNewsletterModal.tsx | 2 ++ .../newsletters/NewsletterDetailModal.tsx | 7 +++++-- .../components/settings/general/Facebook.tsx | 9 ++++++++- .../components/settings/general/LockSite.tsx | 2 +- .../components/settings/general/Metadata.tsx | 2 ++ .../settings/general/TitleAndDescription.tsx | 2 ++ .../components/settings/general/Twitter.tsx | 9 ++++++++- .../settings/general/UserDetailModal.tsx | 9 +++++++-- .../settings/general/users/ProfileBasics.tsx | 3 +++ .../settings/general/users/ProfileDetails.tsx | 5 +++++ .../AddRecommendationModal.tsx | 1 + .../RecommendationDescriptionForm.tsx | 1 + .../membership/portal/LookAndFeel.tsx | 7 ++++++- .../membership/portal/PortalModal.tsx | 2 +- .../membership/tiers/TierDetailModal.tsx | 11 +++++++--- .../site/designAndBranding/BrandSettings.tsx | 20 ++++++++++++++++--- .../acceptance/general/users/profile.test.ts | 4 ---- .../test/acceptance/membership/tiers.test.ts | 4 ++-- 24 files changed, 93 insertions(+), 35 deletions(-) diff --git a/apps/admin-x-design-system/src/global/form/TextArea.stories.tsx b/apps/admin-x-design-system/src/global/form/TextArea.stories.tsx index b0b912b131..611bfa14dd 100644 --- a/apps/admin-x-design-system/src/global/form/TextArea.stories.tsx +++ b/apps/admin-x-design-system/src/global/form/TextArea.stories.tsx @@ -80,15 +80,6 @@ export const ResizeDisabled: Story = { } }; -export const MaxLength: Story = { - args: { - title: 'Description', - placeholder: 'Try to enter more than 80 characters, I dare you...', - value: 'This is a nice text area that only accepts up to 80 characters. Try to add more:', - maxLength: 80 - } -}; - export const Error: Story = { args: { title: 'Description', diff --git a/apps/admin-x-design-system/src/global/form/TextArea.tsx b/apps/admin-x-design-system/src/global/form/TextArea.tsx index 8c554eb12c..6a3c1e3b66 100644 --- a/apps/admin-x-design-system/src/global/form/TextArea.tsx +++ b/apps/admin-x-design-system/src/global/form/TextArea.tsx @@ -97,7 +97,6 @@ const TextArea: React.FC = ({ {title && {title}} {hint && {hint}} - {maxLength && Max length is {maxLength}} ); }; diff --git a/apps/admin-x-settings/src/components/settings/advanced/integrations/AddIntegrationModal.tsx b/apps/admin-x-settings/src/components/settings/advanced/integrations/AddIntegrationModal.tsx index fc2e8a1796..8aee196bf0 100644 --- a/apps/admin-x-settings/src/components/settings/advanced/integrations/AddIntegrationModal.tsx +++ b/apps/admin-x-settings/src/components/settings/advanced/integrations/AddIntegrationModal.tsx @@ -63,6 +63,7 @@ const AddIntegrationModal: React.FC = () => { autoFocus={true} error={!!errors.name} hint={errors.name} + maxLength={191} placeholder='Custom integration' title='Name' value={name} diff --git a/apps/admin-x-settings/src/components/settings/advanced/integrations/CustomIntegrationModal.tsx b/apps/admin-x-settings/src/components/settings/advanced/integrations/CustomIntegrationModal.tsx index 7bdb5c88c5..7037a694b8 100644 --- a/apps/admin-x-settings/src/components/settings/advanced/integrations/CustomIntegrationModal.tsx +++ b/apps/admin-x-settings/src/components/settings/advanced/integrations/CustomIntegrationModal.tsx @@ -2,6 +2,7 @@ import APIKeys from './APIKeys'; import NiceModal, {useModal} from '@ebay/nice-modal-react'; import React, {useEffect, useState} from 'react'; import WebhooksTable from './WebhooksTable'; +import {APIError} from '@tryghost/admin-x-framework/errors'; import {APIKey, useRefreshAPIKey} from '@tryghost/admin-x-framework/api/apiKeys'; import {ConfirmationModal, Form, ImageUpload, Modal, TextField, showToast} from '@tryghost/admin-x-design-system'; import {Integration, useBrowseIntegrations, useEditIntegration} from '@tryghost/admin-x-framework/api/integrations'; @@ -112,7 +113,11 @@ const CustomIntegrationModalContent: React.FC<{integration: Integration}> = ({in const imageUrl = getImageUrl(await uploadImage({file})); updateForm(state => ({...state, icon_image: imageUrl})); } catch (e) { - handleError(e); + const error = e as APIError; + if (error.response!.status === 415) { + error.message = 'Unsupported file type'; + } + handleError(error); } }} > @@ -124,12 +129,13 @@ const CustomIntegrationModalContent: React.FC<{integration: Integration}> = ({in updateForm(state => ({...state, name: e.target.value}))} onKeyDown={() => clearError('name')} /> - updateForm(state => ({...state, description: e.target.value}))} /> + updateForm(state => ({...state, description: e.target.value}))} /> = ({webhook, integrationId}) => = ({webhook, integrationId}) => = ({webhook, integrationId}) => onKeyDown={() => clearError('target_url')} /> = ({keywords}) => { onOk: confirmModal => confirmModal?.remove() }); } catch (e) { - let prompt = 'There was an error verifying your email address. Please try again.'; + let prompt = 'There was an error verifying your email address. Try again later.'; if (e instanceof APIError && e.message === 'Token expired') { - prompt = 'The verification link has expired. Please try again.'; + prompt = 'Verification link has expired.'; } NiceModal.show(ConfirmationModal, { title: 'Error verifying email address', diff --git a/apps/admin-x-settings/src/components/settings/email/newsletters/AddNewsletterModal.tsx b/apps/admin-x-settings/src/components/settings/email/newsletters/AddNewsletterModal.tsx index 87ee38e7a5..7466604e0d 100644 --- a/apps/admin-x-settings/src/components/settings/email/newsletters/AddNewsletterModal.tsx +++ b/apps/admin-x-settings/src/components/settings/email/newsletters/AddNewsletterModal.tsx @@ -97,6 +97,7 @@ const AddNewsletterModal: React.FC = () => { autoFocus={true} error={Boolean(errors.name)} hint={errors.name} + maxLength={191} placeholder='Weekly roundup' title='Name' value={formState.name} @@ -104,6 +105,7 @@ const AddNewsletterModal: React.FC = () => { onKeyDown={() => clearError('name')} />