Skip to content

Commit

Permalink
fix: returns entire doc to generatePreviewURL callback of PreviewButton
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsfletch committed Feb 19, 2021
1 parent c5d1e5c commit 9b9d0f2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
7 changes: 2 additions & 5 deletions src/admin/components/elements/PreviewButton/index.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/admin/components/elements/PreviewButton/types.ts
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 4 additions & 1 deletion src/admin/components/views/Account/Default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
)}
Expand Down
7 changes: 5 additions & 2 deletions src/admin/components/views/Global/Default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 && (
Expand Down
5 changes: 4 additions & 1 deletion src/admin/components/views/collections/Edit/Default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 9b9d0f2

Please sign in to comment.