diff --git a/src/client/components/elements/DuplicateDocument/index.js b/src/client/components/elements/DuplicateDocument/index.js index d297914550..40c27aafba 100644 --- a/src/client/components/elements/DuplicateDocument/index.js +++ b/src/client/components/elements/DuplicateDocument/index.js @@ -1,7 +1,8 @@ -import React from 'react'; +import React, { useCallback } from 'react'; import PropTypes from 'prop-types'; -import { Link } from 'react-router-dom'; +import { useHistory } from 'react-router-dom'; import config from 'payload/config'; +import Button from '../Button'; import useForm from '../../forms/Form/useForm'; import './index.scss'; @@ -11,21 +12,28 @@ const { routes: { admin } } = config; const baseClass = 'duplicate'; const Duplicate = ({ slug }) => { + const { push } = useHistory(); const { getData } = useForm(); - const data = getData(); + + const handleClick = useCallback(() => { + const data = getData(); + + push({ + pathname: `${admin}/collections/${slug}/create`, + state: { + data, + }, + }); + }, [push, getData, slug]); return ( - Duplicate - + ); }; diff --git a/src/client/components/forms/field-types/File/index.js b/src/client/components/forms/field-types/File/index.js index 64ac56ed75..19565a33d7 100644 --- a/src/client/components/forms/field-types/File/index.js +++ b/src/client/components/forms/field-types/File/index.js @@ -111,7 +111,7 @@ const File = (props) => { }; } - return null; + return () => { }; }, [handleDragIn, handleDragOut, handleDrop, dropRef]); useEffect(() => { diff --git a/src/client/components/forms/field-types/Relationship/index.js b/src/client/components/forms/field-types/Relationship/index.js index 0fedc14190..7ebbac3805 100644 --- a/src/client/components/forms/field-types/Relationship/index.js +++ b/src/client/components/forms/field-types/Relationship/index.js @@ -336,13 +336,15 @@ const RelationshipFieldType = (props) => { useEffect(() => { const formatInitialData = (valueToFormat) => { if (hasMultipleRelations) { + const id = valueToFormat?.value?.id || valueToFormat?.value; + return { ...valueToFormat, - value: valueToFormat.value.id, + value: id, }; } - return valueToFormat.id; + return valueToFormat?.id || valueToFormat; }; if (dataToInitialize) { diff --git a/src/client/components/forms/field-types/Upload/index.js b/src/client/components/forms/field-types/Upload/index.js index 79dca1c3dd..b395b00119 100644 --- a/src/client/components/forms/field-types/Upload/index.js +++ b/src/client/components/forms/field-types/Upload/index.js @@ -14,7 +14,7 @@ import SelectExistingModal from './SelectExisting'; import './index.scss'; -const { collections } = config; +const { collections, serverURL, routes: { api } } = config; const baseClass = 'upload'; @@ -43,10 +43,12 @@ const Upload = (props) => { const addModalSlug = `${path}-add`; const selectExistingModalSlug = `${path}-select-existing`; + const dataToInitialize = (typeof initialData === 'object' && initialData.id) ? initialData.id : initialData; + const fieldType = useFieldType({ path, required, - initialData: initialData?.id, + initialData: dataToInitialize, defaultValue, validate, }); @@ -66,10 +68,23 @@ const Upload = (props) => { ].filter(Boolean).join(' '); useEffect(() => { - if (initialData) { + if (typeof initialData === 'object' && initialData?.id) { setInternalValue(initialData); } - }, [initialData]); + + if (typeof initialData === 'string') { + const fetchFile = async () => { + const response = await fetch(`${serverURL}${api}/${relationTo}/${initialData}`); + + if (response.ok) { + const json = await response.json(); + setInternalValue(json); + } + }; + + fetchFile(); + } + }, [initialData, setInternalValue, relationTo]); return (