diff --git a/package.json b/package.json index 5560ece7c5..c64a2179eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@payloadcms/payload", - "version": "0.0.30", + "version": "0.0.32", "description": "CMS and Application Framework", "license": "ISC", "author": "Payload CMS LLC", diff --git a/src/auth/operations/register.js b/src/auth/operations/register.js index 9dfcb19253..a67bda466b 100644 --- a/src/auth/operations/register.js +++ b/src/auth/operations/register.js @@ -27,7 +27,18 @@ async function register(args) { } // ///////////////////////////////////// - // 2. Execute before create hook + // 2. Execute field-level hooks, access, and validation + // ///////////////////////////////////// + + data = await this.performFieldOperations(collectionConfig, { + data, + hook: 'beforeCreate', + operationName: 'create', + req, + }); + + // ///////////////////////////////////// + // 3. Execute before create hook // ///////////////////////////////////// await collectionConfig.hooks.beforeCreate.reduce(async (priorHook, hook) => { @@ -39,17 +50,6 @@ async function register(args) { })) || data; }, Promise.resolve()); - // ///////////////////////////////////// - // 3. Execute field-level hooks, access, and validation - // ///////////////////////////////////// - - data = await this.performFieldOperations(collectionConfig, { - data, - hook: 'beforeCreate', - operationName: 'create', - req, - }); - // ///////////////////////////////////// // 6. Perform register // ///////////////////////////////////// diff --git a/src/auth/operations/update.js b/src/auth/operations/update.js index 5ec4088040..49e39e6bf4 100644 --- a/src/auth/operations/update.js +++ b/src/auth/operations/update.js @@ -54,7 +54,19 @@ async function update(args) { let { data } = args; // ///////////////////////////////////// - // 2. Execute before update hook + // 2. Execute field-level hooks, access, and validation + // ///////////////////////////////////// + + data = await this.performFieldOperations(collectionConfig, { + data, + req, + hook: 'beforeUpdate', + operationName: 'update', + originalDoc, + }); + + // ///////////////////////////////////// + // 3. Execute before update hook // ///////////////////////////////////// await collectionConfig.hooks.beforeUpdate.reduce(async (priorHook, hook) => { @@ -68,23 +80,11 @@ async function update(args) { }, Promise.resolve()); // ///////////////////////////////////// - // 3. Merge updates into existing data + // 4. Merge updates into existing data // ///////////////////////////////////// data = deepmerge(originalDoc, data, { arrayMerge: overwriteMerge }); - // ///////////////////////////////////// - // 4. Execute field-level hooks, access, and validation - // ///////////////////////////////////// - - data = await this.performFieldOperations(collectionConfig, { - data, - req, - hook: 'beforeUpdate', - operationName: 'update', - originalDoc, - }); - // ///////////////////////////////////// // 5. Handle password update // ///////////////////////////////////// diff --git a/src/client/components/elements/ReactSelect/index.scss b/src/client/components/elements/ReactSelect/index.scss index 60ae81bb19..512781abad 100644 --- a/src/client/components/elements/ReactSelect/index.scss +++ b/src/client/components/elements/ReactSelect/index.scss @@ -51,6 +51,7 @@ div.react-select { } .rs__menu { + z-index: 2; border-radius: 0; @include inputShadowActive; } diff --git a/src/client/components/forms/DraggableSection/index.js b/src/client/components/forms/DraggableSection/index.js index f9ffeeda2e..7a26383e27 100644 --- a/src/client/components/forms/DraggableSection/index.js +++ b/src/client/components/forms/DraggableSection/index.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState } from 'react'; import PropTypes from 'prop-types'; import AnimateHeight from 'react-animate-height'; import { Draggable } from 'react-beautiful-dnd'; @@ -34,6 +34,7 @@ const DraggableSection = (props) => { actionPanelVerticalAlignment, permissions, isOpen, + readOnly, } = props; const [isHovered, setIsHovered] = useState(false); @@ -48,6 +49,7 @@ const DraggableSection = (props) => { {(providedDrag) => (
{
@@ -141,6 +147,7 @@ DraggableSection.defaultProps = { positionPanelVerticalAlignment: 'sticky', actionPanelVerticalAlignment: 'sticky', permissions: {}, + readOnly: false, }; DraggableSection.propTypes = { @@ -162,6 +169,7 @@ DraggableSection.propTypes = { positionPanelVerticalAlignment: PropTypes.oneOf(['top', 'center', 'sticky']), actionPanelVerticalAlignment: PropTypes.oneOf(['top', 'center', 'sticky']), permissions: PropTypes.shape({}), + readOnly: PropTypes.bool, }; export default DraggableSection; diff --git a/src/client/components/forms/RenderFields/index.js b/src/client/components/forms/RenderFields/index.js index 54e7080314..9eed1b7d8e 100644 --- a/src/client/components/forms/RenderFields/index.js +++ b/src/client/components/forms/RenderFields/index.js @@ -80,6 +80,8 @@ const RenderFields = (props) => { if (readOnlyOverride) readOnly = true; + if (operation === 'create') readOnly = false; + if (permissions?.[field?.name]?.read?.permission !== false) { if (permissions?.[field?.name]?.[operation]?.permission === false) { readOnly = true; diff --git a/src/client/components/forms/field-types/Array/index.js b/src/client/components/forms/field-types/Array/index.js index 5a107e7f8c..d70e509106 100644 --- a/src/client/components/forms/field-types/Array/index.js +++ b/src/client/components/forms/field-types/Array/index.js @@ -29,6 +29,9 @@ const ArrayFieldType = (props) => { minRows, singularLabel, permissions, + admin: { + readOnly, + }, } = props; const [rows, dispatchRows] = useReducer(reducer, []); @@ -113,6 +116,7 @@ const ArrayFieldType = (props) => { fields={fields} permissions={permissions} value={value} + readOnly={readOnly} /> ); }; @@ -125,6 +129,7 @@ ArrayFieldType.defaultProps = { minRows: undefined, singularLabel: 'Row', permissions: {}, + admin: {}, }; ArrayFieldType.propTypes = { @@ -143,6 +148,9 @@ ArrayFieldType.propTypes = { permissions: PropTypes.shape({ fields: PropTypes.shape({}), }), + admin: PropTypes.shape({ + readOnly: PropTypes.bool, + }), }; const RenderArray = React.memo((props) => { @@ -163,6 +171,7 @@ const RenderArray = React.memo((props) => { fields, permissions, value, + readOnly, } = props; return ( @@ -183,6 +192,7 @@ const RenderArray = React.memo((props) => { > {rows.length > 0 && rows.map((row, i) => ( { )} - -
- -
+ {!readOnly && ( +
+ +
+ )} ); @@ -231,6 +242,7 @@ RenderArray.defaultProps = { path: '', customComponentsPath: undefined, value: undefined, + readOnly: false, }; RenderArray.propTypes = { @@ -256,6 +268,7 @@ RenderArray.propTypes = { permissions: PropTypes.shape({ fields: PropTypes.shape({}), }).isRequired, + readOnly: PropTypes.bool, }; export default withCondition(ArrayFieldType); diff --git a/src/client/components/forms/field-types/Blocks/index.js b/src/client/components/forms/field-types/Blocks/index.js index 2e75b0c43f..25cda00dcd 100644 --- a/src/client/components/forms/field-types/Blocks/index.js +++ b/src/client/components/forms/field-types/Blocks/index.js @@ -33,6 +33,9 @@ const Blocks = (props) => { required, validate, permissions, + admin: { + readOnly, + }, } = props; const path = pathFromProps || name; @@ -130,6 +133,7 @@ const Blocks = (props) => { permissions={permissions} value={value} blocks={blocks} + readOnly={readOnly} /> ); }; @@ -142,6 +146,7 @@ Blocks.defaultProps = { maxRows: undefined, minRows: undefined, permissions: {}, + admin: {}, }; Blocks.propTypes = { @@ -160,6 +165,9 @@ Blocks.propTypes = { permissions: PropTypes.shape({ fields: PropTypes.shape({}), }), + admin: PropTypes.shape({ + readOnly: PropTypes.bool, + }), }; const RenderBlocks = React.memo((props) => { @@ -181,6 +189,7 @@ const RenderBlocks = React.memo((props) => { value, toggleCollapse, blocks, + readOnly, } = props; return ( @@ -195,7 +204,10 @@ const RenderBlocks = React.memo((props) => { /> - + {(provided) => (
{ if (blockToRender) { return ( { disableFormData, }); - const classes = [ - 'field-type', - baseClass, - showError && 'error', - value && `${baseClass}--checked`, - readOnly && 'read-only', - ].filter(Boolean).join(' '); + useEffect(() => { + if (value === null || value === undefined) { + setValue(false); + } + }, [value, setValue]); return (
{ />