diff --git a/apps/dashboard/src/components/workflow-editor/steps/in-app/in-app-editor-preview.tsx b/apps/dashboard/src/components/workflow-editor/steps/in-app/in-app-editor-preview.tsx index 7534eb81a37..50be368259b 100644 --- a/apps/dashboard/src/components/workflow-editor/steps/in-app/in-app-editor-preview.tsx +++ b/apps/dashboard/src/components/workflow-editor/steps/in-app/in-app-editor-preview.tsx @@ -7,24 +7,18 @@ import { Button } from '@/components/primitives/button'; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/primitives/collapsible'; import { Editor } from '@/components/primitives/editor'; import { InAppPreview } from '@/components/workflow-editor/in-app-preview'; -import { usePreviewStep } from '@/hooks/use-preview-step'; +import { GeneratePreviewResponseDto } from '@novu/shared'; import { loadLanguage } from '@uiw/codemirror-extensions-langs'; -import { useFormContext } from 'react-hook-form'; -import { useParams } from 'react-router-dom'; type InAppEditorPreviewProps = { value: string; onChange: (value: string) => void; + previewData?: GeneratePreviewResponseDto; + applyPreview: () => void; }; export const InAppEditorPreview = (props: InAppEditorPreviewProps) => { - const { value, onChange } = props; + const { value, onChange, previewData, applyPreview } = props; const [isEditorOpen, setIsEditorOpen] = useState(true); - const { previewStep, data } = usePreviewStep(); - const { workflowSlug = '', stepSlug = '' } = useParams<{ - workflowSlug: string; - stepSlug: string; - }>(); - const form = useFormContext(); const [payloadError, setPayloadError] = useState(''); return ( @@ -68,11 +62,7 @@ export const InAppEditorPreview = (props: InAppEditorPreviewProps) => { className="self-end" onClick={() => { try { - previewStep({ - workflowSlug, - stepSlug, - data: { controlValues: form.getValues(), previewPayload: JSON.parse(value) }, - }); + applyPreview(); } catch (e) { setPayloadError(String(e)); } @@ -83,7 +73,7 @@ export const InAppEditorPreview = (props: InAppEditorPreviewProps) => { - {data && } + {previewData && } ); }; diff --git a/apps/dashboard/src/components/workflow-editor/steps/in-app/in-app-tabs.tsx b/apps/dashboard/src/components/workflow-editor/steps/in-app/in-app-tabs.tsx index 052c7c322a8..6537dc11c6e 100644 --- a/apps/dashboard/src/components/workflow-editor/steps/in-app/in-app-tabs.tsx +++ b/apps/dashboard/src/components/workflow-editor/steps/in-app/in-app-tabs.tsx @@ -1,7 +1,7 @@ import { RiEdit2Line, RiPencilRuler2Line } from 'react-icons/ri'; import { Cross2Icon } from '@radix-ui/react-icons'; import { useNavigate, useParams } from 'react-router-dom'; -import { useForm, useWatch } from 'react-hook-form'; +import { FieldValues, useForm, useWatch } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { type WorkflowResponseDto, type StepDataDto, type StepUpdateDto } from '@novu/shared'; @@ -38,7 +38,7 @@ export const InAppTabs = ({ workflow, step }: { workflow: WorkflowResponseDto; s const [editorValue, setEditorValue] = useState('{}'); const { reset, formState } = form; - const { previewStep } = usePreviewStep(); + const { previewStep, data: previewData } = usePreviewStep(); const { updateWorkflow } = useUpdateWorkflow({ onSuccess: () => { showToast({ @@ -159,7 +159,18 @@ export const InAppTabs = ({ workflow, step }: { workflow: WorkflowResponseDto; s - + { + previewStep({ + stepSlug, + workflowSlug, + data: { controlValues: form.getValues() as FieldValues, previewPayload: JSON.parse(editorValue) }, + }); + }} + />