@@ -265,6 +265,20 @@ export const addFieldStatePromise = async ({
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'relationship':
|
||||||
|
case 'upload': {
|
||||||
|
const relationshipValue =
|
||||||
|
valueWithDefault && typeof valueWithDefault === 'object' && 'id' in valueWithDefault
|
||||||
|
? valueWithDefault.id
|
||||||
|
: valueWithDefault
|
||||||
|
fieldState.value = relationshipValue
|
||||||
|
fieldState.initialValue = relationshipValue
|
||||||
|
|
||||||
|
state[`${path}${field.name}`] = fieldState
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
fieldState.value = valueWithDefault
|
fieldState.value = valueWithDefault
|
||||||
fieldState.initialValue = valueWithDefault
|
fieldState.initialValue = valueWithDefault
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ const GlobalView: React.FC<IndexProps> = (props) => {
|
|||||||
CustomComponent={CustomEdit}
|
CustomComponent={CustomEdit}
|
||||||
DefaultComponent={DefaultGlobal}
|
DefaultComponent={DefaultGlobal}
|
||||||
componentProps={{
|
componentProps={{
|
||||||
action: `${serverURL}${api}/globals/${slug}?locale=${locale}&depth=0&fallback-locale=null`,
|
action: `${serverURL}${api}/globals/${slug}?locale=${locale}&fallback-locale=null`,
|
||||||
apiURL: `${serverURL}${api}/globals/${slug}?locale=${locale}${
|
apiURL: `${serverURL}${api}/globals/${slug}?locale=${locale}${
|
||||||
global.versions?.drafts ? '&draft=true' : ''
|
global.versions?.drafts ? '&draft=true' : ''
|
||||||
}`,
|
}`,
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ const EditView: React.FC<IndexProps> = (props) => {
|
|||||||
}`
|
}`
|
||||||
const action = `${serverURL}${api}/${slug}${
|
const action = `${serverURL}${api}/${slug}${
|
||||||
isEditing ? `/${id}` : ''
|
isEditing ? `/${id}` : ''
|
||||||
}?locale=${locale}&depth=0&fallback-locale=null`
|
}?locale=${locale}&fallback-locale=null`
|
||||||
const hasSavePermission =
|
const hasSavePermission =
|
||||||
(isEditing && docPermissions?.update?.permission) ||
|
(isEditing && docPermissions?.update?.permission) ||
|
||||||
(!isEditing && (docPermissions as CollectionPermission)?.create?.permission)
|
(!isEditing && (docPermissions as CollectionPermission)?.create?.permission)
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types'
|
import type { CollectionConfig } from '../../../../packages/payload/src/collections/config/types'
|
||||||
import type { PayloadRequest } from '../../../../packages/payload/src/types'
|
import type { PayloadRequest } from '../../../../packages/payload/src/types'
|
||||||
|
|
||||||
import payload from '../../../../packages/payload/src'
|
|
||||||
|
|
||||||
export const contextHooksSlug = 'context-hooks'
|
export const contextHooksSlug = 'context-hooks'
|
||||||
const ContextHooks: CollectionConfig = {
|
const ContextHooks: CollectionConfig = {
|
||||||
slug: contextHooksSlug,
|
slug: contextHooksSlug,
|
||||||
@@ -47,12 +45,12 @@ const ContextHooks: CollectionConfig = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
afterChange: [
|
afterChange: [
|
||||||
async ({ context, doc }) => {
|
async ({ context, doc, req }) => {
|
||||||
if (context.triggerAfterChange === false) {
|
if (context.triggerAfterChange === false) {
|
||||||
// Make sure we don't trigger afterChange again and again in an infinite loop
|
// Make sure we don't trigger afterChange again and again in an infinite loop
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await payload.update({
|
await req.payload.update({
|
||||||
collection: contextHooksSlug,
|
collection: contextHooksSlug,
|
||||||
id: doc.id,
|
id: doc.id,
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
Reference in New Issue
Block a user