Skip to content

Commit

Permalink
Fixed publication lang. empty error
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzimon committed May 13, 2024
1 parent 8f89296 commit 71233e0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
6 changes: 3 additions & 3 deletions apps/admin-x-framework/src/hooks/useHandleError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ const useHandleError = () => {
} else if (error instanceof ValidationError && error.data?.errors[0]) {
showToast({
message: error.data.errors[0].context || error.data.errors[0].message,
type: 'pageError'
type: 'error'
});
} else if (error instanceof APIError) {
showToast({
message: error.message,
type: 'pageError'
type: 'error'
});
} else {
showToast({
message: 'Something went wrong, please try again.',
type: 'pageError'
type: 'error'
});
}
}, [sentryDSN]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ const PublicationLanguage: React.FC<{ keywords: string[] }> = ({keywords}) => {
handleCancel,
updateSetting,
focusRef,
errors,
clearError,
handleEditingChange
} = useSettingGroup();
} = useSettingGroup({
onValidate: () => {
if (!publicationLanguage) {
return {
publicationLanguage: 'Enter a value'
};
}

return {};
}
});

const [publicationLanguage] = getSettingValues(localSettings, ['locale']) as string[];

Expand Down Expand Up @@ -42,12 +54,14 @@ const PublicationLanguage: React.FC<{ keywords: string[] }> = ({keywords}) => {
const inputFields = (
<SettingGroupContent columns={1}>
<TextField
hint={hint}
error={!!errors.publicationLanguage}
hint={errors.publicationLanguage || hint}
inputRef={focusRef}
placeholder="Site language"
title='Site language'
value={publicationLanguage}
onChange={handleLanguageChange}
onKeyDown={() => clearError('password')}
/>
</SettingGroupContent>
);
Expand Down
8 changes: 1 addition & 7 deletions apps/admin-x-settings/src/hooks/useSettingGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import React, {useEffect, useRef, useState} from 'react';
import {ErrorMessages, OkProps, SaveHandler, SaveState, useForm, useHandleError} from '@tryghost/admin-x-framework/hooks';
import {Setting, SettingValue, useEditSettings} from '@tryghost/admin-x-framework/api/settings';
import {SiteData} from '@tryghost/admin-x-framework/api/site';
import {showToast, useGlobalDirtyState} from '@tryghost/admin-x-design-system';
import {toast} from 'react-hot-toast';
import {useGlobalData} from '../components/providers/GlobalDataProvider';
import {useGlobalDirtyState} from '@tryghost/admin-x-design-system';

interface LocalSetting extends Setting {
dirty?: boolean;
Expand Down Expand Up @@ -107,15 +106,10 @@ const useSettingGroup = ({savingDelay, onValidate}: {savingDelay?: number; onVal
focusRef,
siteData,
handleSave: async () => {
toast.remove();
const result = await handleSave();
if (result) {
setEditing(false);
} else {
showToast({
title: 'Can\'t save settings',
type: 'error'
});
}
return result;
},
Expand Down

0 comments on commit 71233e0

Please sign in to comment.