diff --git a/src/attributes/types/AttributeOfUploadedFile.ts b/src/attributes/types/AttributeOfUploadedFile.ts new file mode 100644 index 000000000..6ef35862d --- /dev/null +++ b/src/attributes/types/AttributeOfUploadedFile.ts @@ -0,0 +1,3 @@ +import { AttributeValueInput } from "@saleor/types/globalTypes"; + +export type AtributesOfFiles = Pick diff --git a/src/attributes/utils/data.ts b/src/attributes/utils/data.ts index e822d929e..d50fafbaa 100644 --- a/src/attributes/utils/data.ts +++ b/src/attributes/utils/data.ts @@ -25,6 +25,7 @@ import { import { MutationFetchResult } from "react-apollo"; import { AttributePageFormData } from "../components/AttributePage"; +import { AtributesOfFiles } from "../types/AttributeOfUploadedFile"; import { AttributeValueDelete } from "../types/AttributeValueDelete"; export const ATTRIBUTE_TYPES_WITH_DEDICATED_VALUES = [ @@ -240,22 +241,24 @@ export const getFileValuesRemovedFromAttributes = ( export const getAttributesOfRemovedFiles = ( fileAttributesRemoved: FormsetData -) => +): AtributesOfFiles[] => fileAttributesRemoved.map(attribute => ({ file: undefined, id: attribute.id, + contentType: attribute.value?.type, values: [] })); export const getAttributesOfUploadedFiles = ( fileValuesToUpload: FormsetData, uploadFilesResult: Array> -) => +): AtributesOfFiles[] => uploadFilesResult.map((uploadFileResult, index) => { const attribute = fileValuesToUpload[index]; return { file: uploadFileResult.data.fileUpload.uploadedFile.url, + contentType: uploadFileResult.data.fileUpload.uploadedFile.contentType, id: attribute.id, values: [] }; diff --git a/src/attributes/utils/handlers.ts b/src/attributes/utils/handlers.ts index c2e9f5de8..68d8b7438 100644 --- a/src/attributes/utils/handlers.ts +++ b/src/attributes/utils/handlers.ts @@ -188,11 +188,13 @@ function getFileInput( if (updatedFileAttribute) { return { file: updatedFileAttribute.file, - id: updatedFileAttribute.id + id: updatedFileAttribute.id, + contentType: updatedFileAttribute.contentType }; } return { file: attribute.data.selectedValues?.[0]?.file?.url, + contentType: attribute.data.selectedValues?.[0]?.file.contentType, id: attribute.id }; }