From 10a366839b521399c357e58be9fbdfbbdd26f7dc Mon Sep 17 00:00:00 2001 From: Magdalena Markusik Date: Thu, 18 Feb 2021 13:59:47 +0100 Subject: [PATCH] Fixes --- src/pages/views/PageDetails.tsx | 3 ++- src/products/views/ProductUpdate/handlers.ts | 5 ++--- src/translations/utils.ts | 15 +++++++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/pages/views/PageDetails.tsx b/src/pages/views/PageDetails.tsx index 04febb570..db773768f 100644 --- a/src/pages/views/PageDetails.tsx +++ b/src/pages/views/PageDetails.tsx @@ -23,6 +23,7 @@ import useNotifier from "@saleor/hooks/useNotifier"; import { commonMessages } from "@saleor/intl"; import usePageSearch from "@saleor/searches/usePageSearch"; import useProductSearch from "@saleor/searches/useProductSearch"; +import { getParsedDataForJsonStringField } from "@saleor/translations/utils"; import createMetadataUpdateHandler from "@saleor/utils/handlers/metadataUpdateHandler"; import { useMetadataUpdate, @@ -53,7 +54,7 @@ const createPageInput = ( attributes: data.attributes, updatedFileAttributes }), - content: !!data.content?.blocks.length ? JSON.stringify(data.content) : null, + content: getParsedDataForJsonStringField(data.content), isPublished: data.isPublished, publicationDate: data.publicationDate, seo: { diff --git a/src/products/views/ProductUpdate/handlers.ts b/src/products/views/ProductUpdate/handlers.ts index 566c32837..e191a8db2 100644 --- a/src/products/views/ProductUpdate/handlers.ts +++ b/src/products/views/ProductUpdate/handlers.ts @@ -56,6 +56,7 @@ import { } from "@saleor/products/types/VariantCreate"; import { mapFormsetStockToStockInput } from "@saleor/products/utils/data"; import { getAvailabilityVariables } from "@saleor/products/utils/handlers"; +import { getParsedDataForJsonStringField } from "@saleor/translations/utils"; import { ReorderEvent } from "@saleor/types"; import { move } from "@saleor/utils/lists"; import { diff } from "fast-array-diff"; @@ -185,9 +186,7 @@ export function createUpdateHandler( category: data.category, chargeTaxes: data.chargeTaxes, collections: data.collections, - description: !!data.description?.blocks?.length - ? JSON.stringify(data.description) - : null, + description: getParsedDataForJsonStringField(data.description), name: data.name, rating: data.rating, seo: { diff --git a/src/translations/utils.ts b/src/translations/utils.ts index d13ad2025..b92d417b7 100644 --- a/src/translations/utils.ts +++ b/src/translations/utils.ts @@ -1,16 +1,23 @@ import { OutputData } from "@editorjs/editorjs"; -import { TranslationInput } from "@saleor/types/globalTypes"; -import { TranslationInputFieldName } from "./types"; +import { + PageTranslationInputFieldName, + TranslationInputFieldName +} from "./types"; export const getParsedTranslationInputData = ({ fieldName, data }: { - fieldName: keyof TranslationInput; + fieldName: TranslationInputFieldName | PageTranslationInputFieldName; data: string | OutputData; }): Record => { - if (fieldName === TranslationInputFieldName.description) { + const fieldsToParse = [ + TranslationInputFieldName.description, + PageTranslationInputFieldName.content + ]; + + if (fieldsToParse.includes(fieldName)) { return { description: getParsedDataForJsonStringField(data as OutputData) };