Add rich text editor to product pages
This commit is contained in:
parent
437df6fe9a
commit
28cc74c954
5 changed files with 33 additions and 17 deletions
|
@ -74,6 +74,19 @@ const useStyles = makeStyles(
|
||||||
"& .ce-inline-toolbar__toggler-and-button-wrapper": {
|
"& .ce-inline-toolbar__toggler-and-button-wrapper": {
|
||||||
paddingRight: 0
|
paddingRight: 0
|
||||||
},
|
},
|
||||||
|
"& .ce-toolbar__actions": {
|
||||||
|
right: 0,
|
||||||
|
top: 0
|
||||||
|
},
|
||||||
|
"& .ce-toolbar__content": {
|
||||||
|
maxWidth: "unset"
|
||||||
|
},
|
||||||
|
"& .ce-toolbar__plus": {
|
||||||
|
left: -9
|
||||||
|
},
|
||||||
|
"& .ce-toolbox.ce-toolbox--opened": {
|
||||||
|
left: 16
|
||||||
|
},
|
||||||
"& .codex-editor__redactor": {
|
"& .codex-editor__redactor": {
|
||||||
marginRight: `${theme.spacing(4)}px !important`,
|
marginRight: `${theme.spacing(4)}px !important`,
|
||||||
paddingBottom: "0 !important"
|
paddingBottom: "0 !important"
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { SearchWarehouses_search_edges_node } from "@saleor/searches/types/Searc
|
||||||
import handleFormSubmit from "@saleor/utils/handlers/handleFormSubmit";
|
import handleFormSubmit from "@saleor/utils/handlers/handleFormSubmit";
|
||||||
import createMultiAutocompleteSelectHandler from "@saleor/utils/handlers/multiAutocompleteSelectChangeHandler";
|
import createMultiAutocompleteSelectHandler from "@saleor/utils/handlers/multiAutocompleteSelectChangeHandler";
|
||||||
import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler";
|
import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler";
|
||||||
|
import getMetadata from "@saleor/utils/metadata/getMetadata";
|
||||||
import useMetadataChangeTrigger from "@saleor/utils/metadata/useMetadataChangeTrigger";
|
import useMetadataChangeTrigger from "@saleor/utils/metadata/useMetadataChangeTrigger";
|
||||||
import useRichText from "@saleor/utils/richText/useRichText";
|
import useRichText from "@saleor/utils/richText/useRichText";
|
||||||
import { diff } from "fast-array-diff";
|
import { diff } from "fast-array-diff";
|
||||||
|
@ -143,15 +144,6 @@ const getStocksData = (
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getMetadata = (
|
|
||||||
data: ProductUpdateFormData,
|
|
||||||
isMetadataModified: boolean,
|
|
||||||
isPrivateMetadataModified: boolean
|
|
||||||
) => ({
|
|
||||||
metadata: isMetadataModified ? data.metadata : undefined,
|
|
||||||
privateMetadata: isPrivateMetadataModified ? data.privateMetadata : undefined
|
|
||||||
});
|
|
||||||
|
|
||||||
function useProductUpdateForm(
|
function useProductUpdateForm(
|
||||||
product: ProductDetails_product,
|
product: ProductDetails_product,
|
||||||
onSubmit: (data: ProductUpdateSubmitData) => SubmitPromise,
|
onSubmit: (data: ProductUpdateSubmitData) => SubmitPromise,
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {
|
||||||
} from "@saleor/products/utils/data";
|
} from "@saleor/products/utils/data";
|
||||||
import { SearchWarehouses_search_edges_node } from "@saleor/searches/types/SearchWarehouses";
|
import { SearchWarehouses_search_edges_node } from "@saleor/searches/types/SearchWarehouses";
|
||||||
import { mapMetadataItemToInput } from "@saleor/utils/maps";
|
import { mapMetadataItemToInput } from "@saleor/utils/maps";
|
||||||
|
import getMetadata from "@saleor/utils/metadata/getMetadata";
|
||||||
import useMetadataChangeTrigger from "@saleor/utils/metadata/useMetadataChangeTrigger";
|
import useMetadataChangeTrigger from "@saleor/utils/metadata/useMetadataChangeTrigger";
|
||||||
import { diff } from "fast-array-diff";
|
import { diff } from "fast-array-diff";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
@ -117,11 +118,6 @@ function useProductVariantUpdateForm(
|
||||||
stocks.remove(id);
|
stocks.remove(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const metadata = isMetadataModified ? form.data.metadata : undefined;
|
|
||||||
const privateMetadata = isPrivateMetadataModified
|
|
||||||
? form.data.privateMetadata
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const dataStocks = stocks.data.map(stock => stock.id);
|
const dataStocks = stocks.data.map(stock => stock.id);
|
||||||
const variantStocks = variant?.stocks.map(stock => stock.warehouse.id) || [];
|
const variantStocks = variant?.stocks.map(stock => stock.warehouse.id) || [];
|
||||||
const stockDiff = diff(variantStocks, dataStocks);
|
const stockDiff = diff(variantStocks, dataStocks);
|
||||||
|
@ -140,10 +136,9 @@ function useProductVariantUpdateForm(
|
||||||
};
|
};
|
||||||
const submitData: ProductVariantUpdateSubmitData = {
|
const submitData: ProductVariantUpdateSubmitData = {
|
||||||
...form.data,
|
...form.data,
|
||||||
|
...getMetadata(form.data, isMetadataModified, isPrivateMetadataModified),
|
||||||
addStocks,
|
addStocks,
|
||||||
attributes: attributes.data,
|
attributes: attributes.data,
|
||||||
metadata,
|
|
||||||
privateMetadata,
|
|
||||||
removeStocks: stockDiff.removed,
|
removeStocks: stockDiff.removed,
|
||||||
updateStocks
|
updateStocks
|
||||||
};
|
};
|
||||||
|
|
16
src/utils/metadata/getMetadata.ts
Normal file
16
src/utils/metadata/getMetadata.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { MetadataFormData } from "@saleor/components/Metadata";
|
||||||
|
|
||||||
|
function getMetadata(
|
||||||
|
data: MetadataFormData,
|
||||||
|
isMetadataModified: boolean,
|
||||||
|
isPrivateMetadataModified: boolean
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
metadata: isMetadataModified ? data.metadata : undefined,
|
||||||
|
privateMetadata: isPrivateMetadataModified
|
||||||
|
? data.privateMetadata
|
||||||
|
: undefined
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default getMetadata;
|
|
@ -3,7 +3,7 @@ import { RichTextEditorChange } from "@saleor/components/RichTextEditor";
|
||||||
import { MutableRefObject, useEffect, useRef } from "react";
|
import { MutableRefObject, useEffect, useRef } from "react";
|
||||||
|
|
||||||
function useRichText(opts: {
|
function useRichText(opts: {
|
||||||
initial?: string | null;
|
initial: string | null;
|
||||||
triggerChange: () => void;
|
triggerChange: () => void;
|
||||||
}): [MutableRefObject<OutputData>, RichTextEditorChange] {
|
}): [MutableRefObject<OutputData>, RichTextEditorChange] {
|
||||||
const data = useRef<OutputData>(
|
const data = useRef<OutputData>(
|
||||||
|
|
Loading…
Reference in a new issue