11import { FeatureFlagsKeysEnum , ISubscriberResponseDto } from '@novu/shared' ;
2+ import { JSONSchema7 } from 'json-schema' ;
23import { useCallback , useEffect , useMemo , useRef } from 'react' ;
34import { type ContextResponseDto } from '@/api/contexts' ;
45import { Accordion } from '@/components/primitives/accordion' ;
56import { useCreateVariable } from '@/components/variable/hooks/use-create-variable' ;
67import { useEnvironment } from '@/context/environment/hooks' ;
78import { useDefaultSubscriberData } from '@/hooks/use-default-subscriber-data' ;
9+ import { useDynamicPreviewSchema } from '@/hooks/use-dynamic-preview-schema' ;
810import { useFeatureFlag } from '@/hooks/use-feature-flag' ;
911import { useFetchOrganizationSettings } from '@/hooks/use-fetch-organization-settings' ;
1012import { useIsPayloadSchemaEnabled } from '@/hooks/use-is-payload-schema-enabled' ;
@@ -101,6 +103,17 @@ export function PreviewContextPanel({
101103 const { isPayloadSchemaDrawerOpen, highlightedVariableKey, openSchemaDrawer, closeSchemaDrawer } =
102104 useCreateVariable ( ) ;
103105
106+ const previewSchema = useDynamicPreviewSchema ( ) ;
107+ const schemas = useMemo (
108+ ( ) => ( {
109+ payload : workflow ?. payloadSchema ,
110+ subscriber : previewSchema ?. properties ?. subscriber as JSONSchema7 | undefined ,
111+ context : previewSchema ?. properties ?. context as JSONSchema7 | undefined ,
112+ steps : previewSchema ?. properties ?. steps as JSONSchema7 | undefined ,
113+ } ) ,
114+ [ previewSchema , workflow ?. payloadSchema ]
115+ ) ;
116+
104117 const hasDigestStep = useMemo ( ( ) => {
105118 return workflow ?. steps ?. some ( ( step ) => step . type === StepTypeEnum . DIGEST ) ?? false ;
106119 } , [ workflow ?. steps ] ) ;
@@ -249,6 +262,7 @@ export function PreviewContextPanel({
249262 errors = { errors }
250263 localParsedData = { localParsedData }
251264 workflow = { workflow }
265+ schema = { schemas . payload }
252266 onUpdate = { updateJsonSection }
253267 onClearPersisted = { canClearPersisted ? handleClearPersistedPayload : undefined }
254268 hasDigestStep = { hasDigestStep }
@@ -258,7 +272,7 @@ export function PreviewContextPanel({
258272 < PreviewSubscriberSection
259273 error = { errors . subscriber }
260274 subscriber = { localParsedData . subscriber }
261- workflow = { workflow }
275+ schema = { schemas . subscriber }
262276 onUpdate = { updateJsonSection }
263277 onSubscriberSelect = { handleSubscriberSelection }
264278 onClearPersisted = { canClearPersisted ? handleClearPersistedSubscriber : undefined }
@@ -276,7 +290,7 @@ export function PreviewContextPanel({
276290 < PreviewContextSection
277291 error = { errors . context }
278292 context = { localParsedData . context }
279- workflow = { workflow }
293+ schema = { schemas . context }
280294 onUpdate = { updateJsonSection }
281295 onContextSelect = { handleContextSelection }
282296 onClearPersisted = { canClearPersisted ? handleClearPersistedContext : undefined }
0 commit comments