From f956be3fbcb24da7d1ad468434dc4911a40de348 Mon Sep 17 00:00:00 2001 From: Magdalena Markusik Date: Fri, 25 Sep 2020 16:21:10 +0200 Subject: [PATCH] refactor after review --- .../CategoryCreatePage/CategoryCreatePage.tsx | 2 +- .../CollectionCreatePage.tsx | 2 +- src/components/SeoForm/SeoForm.tsx | 18 ++++++------------ .../PageDetailsPage/PageDetailsPage.tsx | 8 ++++---- .../ProductCreatePage/ProductCreatePage.tsx | 2 +- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/categories/components/CategoryCreatePage/CategoryCreatePage.tsx b/src/categories/components/CategoryCreatePage/CategoryCreatePage.tsx index ed71cf471..0ac329841 100644 --- a/src/categories/components/CategoryCreatePage/CategoryCreatePage.tsx +++ b/src/categories/components/CategoryCreatePage/CategoryCreatePage.tsx @@ -79,7 +79,7 @@ export const CategoryCreatePage: React.FC = ({ /> = ({ /> ; loading?: boolean; helperText?: string; - isCreating?: boolean; + allowEmptySlug?: boolean; title: string; slug: string; slugPlaceholder?: string; @@ -97,7 +97,7 @@ const SeoForm: React.FC = props => { disabled, errors = [], helperText, - isCreating = false, + allowEmptySlug = false, loading, title, slug, @@ -124,15 +124,11 @@ const SeoForm: React.FC = props => { const getSlugHelperMessage = () => { const error = !!getError(SeoField.slug); - if (isCreating && !error) { + if (allowEmptySlug && !error) { return intl.formatMessage(seoFieldMessage); } - if (error) { - return getSlugErrorMessage(); - } - - return ""; + return error ? getSlugErrorMessage() : ""; }; const getSlugErrorMessage = () => { @@ -144,7 +140,7 @@ const SeoForm: React.FC = props => { : getPageErrorMessage(error as PageErrorFragment, intl); }; - const handleSlugChange = event => { + const handleSlugChange = (event: React.ChangeEvent) => { const { value } = event.target; if (value === "" || SLUG_REGEX.test(value)) { @@ -152,7 +148,7 @@ const SeoForm: React.FC = props => { } }; - const getError = fieldName => getFieldError(errors, fieldName); + const getError = (fieldName: SeoField) => getFieldError(errors, fieldName); return ( @@ -211,7 +207,6 @@ const SeoForm: React.FC = props => {
@@ -240,7 +235,6 @@ const SeoForm: React.FC = props => { /> diff --git a/src/pages/components/PageDetailsPage/PageDetailsPage.tsx b/src/pages/components/PageDetailsPage/PageDetailsPage.tsx index 10696254d..772049b04 100644 --- a/src/pages/components/PageDetailsPage/PageDetailsPage.tsx +++ b/src/pages/components/PageDetailsPage/PageDetailsPage.tsx @@ -38,7 +38,7 @@ export interface PageDetailsPageProps { disabled: boolean; errors: PageErrorFragment[]; page: PageDetails_page; - isCreating?: boolean; + allowEmptySlug?: boolean; saveButtonBarState: ConfirmButtonTransitionState; onBack: () => void; onRemove: () => void; @@ -56,7 +56,7 @@ const PageDetailsPage: React.FC = ({ }) => { const intl = useIntl(); const localizeDate = useDateLocalize(); - const pageExists = page === null; + const pageExists = page !== null; const initialForm: FormData = { content: maybe( @@ -79,7 +79,7 @@ const PageDetailsPage: React.FC = ({ = ({ = ({ )}