fix: returns entire doc to generatePreviewURL callback of PreviewButton
This commit is contained in:
@@ -1,18 +1,15 @@
|
||||
import React from 'react';
|
||||
import { useAuth } from '@payloadcms/config-provider';
|
||||
import { useForm } from '../../forms/Form/context';
|
||||
import Button from '../Button';
|
||||
import { Props } from './types';
|
||||
|
||||
const baseClass = 'preview-btn';
|
||||
|
||||
const PreviewButton: React.FC<Props> = ({ generatePreviewURL }) => {
|
||||
const PreviewButton: React.FC<Props> = ({ generatePreviewURL, data }) => {
|
||||
const { token } = useAuth();
|
||||
const { getFields } = useForm();
|
||||
const fields = getFields();
|
||||
|
||||
if (generatePreviewURL && typeof generatePreviewURL === 'function') {
|
||||
const previewURL = generatePreviewURL(fields, token);
|
||||
const previewURL = generatePreviewURL(data, token);
|
||||
|
||||
return (
|
||||
<Button
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { Data } from "../../forms/Form/types";
|
||||
|
||||
export type Props = {
|
||||
generatePreviewURL?: (fields: unknown, token: string) => string
|
||||
generatePreviewURL?: (fields: unknown, token: string) => string,
|
||||
data?: Data
|
||||
}
|
||||
|
||||
@@ -104,7 +104,10 @@ const DefaultAccount: React.FC<Props> = (props) => {
|
||||
)}
|
||||
</ul>
|
||||
<div className={`${baseClass}__document-actions${preview ? ` ${baseClass}__document-actions--with-preview` : ''}`}>
|
||||
<PreviewButton generatePreviewURL={preview} />
|
||||
<PreviewButton
|
||||
generatePreviewURL={preview}
|
||||
data={data}
|
||||
/>
|
||||
{hasSavePermission && (
|
||||
<FormSubmit>Save</FormSubmit>
|
||||
)}
|
||||
|
||||
@@ -68,9 +68,12 @@ const DefaultGlobalView: React.FC<Props> = (props) => {
|
||||
<div className={`${baseClass}__sidebar-sticky`}>
|
||||
<div className={`${baseClass}__sidebar-sticky-wrap`}>
|
||||
<div className={`${baseClass}__document-actions${preview ? ` ${baseClass}__document-actions--with-preview` : ''}`}>
|
||||
<PreviewButton generatePreviewURL={preview} />
|
||||
<PreviewButton
|
||||
generatePreviewURL={preview}
|
||||
data={data}
|
||||
/>
|
||||
{hasSavePermission && (
|
||||
<FormSubmit>Save</FormSubmit>
|
||||
<FormSubmit>Save</FormSubmit>
|
||||
)}
|
||||
</div>
|
||||
{data && (
|
||||
|
||||
@@ -142,7 +142,10 @@ const DefaultEditView: React.FC<Props> = (props) => {
|
||||
) : undefined}
|
||||
<div className={`${baseClass}__document-actions${(preview && isEditing) ? ` ${baseClass}__document-actions--with-preview` : ''}`}>
|
||||
{isEditing && (
|
||||
<PreviewButton generatePreviewURL={preview} />
|
||||
<PreviewButton
|
||||
generatePreviewURL={preview}
|
||||
data={data}
|
||||
/>
|
||||
)}
|
||||
{hasSavePermission && (
|
||||
<FormSubmit>Save</FormSubmit>
|
||||
|
||||
Reference in New Issue
Block a user