-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
581 additions
and
43 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
apps/dashboard/src/components/workflow-editor/steps/sms/configure-sms-step-preview.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as Sentry from '@sentry/react'; | ||
import { useEffect } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
import { SmsPreview } from '@/components/workflow-editor/steps/sms/sms-preview'; | ||
import { useWorkflow } from '@/components/workflow-editor/workflow-provider'; | ||
import { usePreviewStep } from '@/hooks/use-preview-step'; | ||
|
||
export const ConfigureSmsStepPreview = () => { | ||
const { | ||
previewStep, | ||
data: previewData, | ||
isPending: isPreviewPending, | ||
} = usePreviewStep({ | ||
onError: (error) => Sentry.captureException(error), | ||
}); | ||
const { step, isPending } = useWorkflow(); | ||
|
||
const { workflowSlug, stepSlug } = useParams<{ | ||
workflowSlug: string; | ||
stepSlug: string; | ||
}>(); | ||
|
||
useEffect(() => { | ||
if (!workflowSlug || !stepSlug || !step || isPending) return; | ||
|
||
previewStep({ | ||
workflowSlug, | ||
stepSlug, | ||
previewData: { controlValues: step.controls.values, previewPayload: {} }, | ||
}); | ||
}, [workflowSlug, stepSlug, previewStep, step, isPending]); | ||
|
||
return <SmsPreview isPreviewPending={isPreviewPending} previewData={previewData} />; | ||
}; |
111 changes: 111 additions & 0 deletions
111
apps/dashboard/src/components/workflow-editor/steps/sms/sms-editor-preview.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { type StepDataDto, type WorkflowResponseDto } from '@novu/shared'; | ||
import { CSSProperties, useEffect, useRef, useState } from 'react'; | ||
|
||
import { Notification5Fill } from '@/components/icons'; | ||
import { Code2 } from '@/components/icons/code-2'; | ||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/primitives/accordion'; | ||
import { Button } from '@/components/primitives/button'; | ||
import { Editor } from '@/components/primitives/editor'; | ||
import { InAppTabsSection } from '@/components/workflow-editor/steps/in-app/in-app-tabs-section'; | ||
import { SmsPreview } from '@/components/workflow-editor/steps/sms/sms-preview'; | ||
import { loadLanguage } from '@uiw/codemirror-extensions-langs'; | ||
import { useEditorPreview } from '../use-editor-preview'; | ||
|
||
const getInitialAccordionValue = (value: string) => { | ||
try { | ||
return Object.keys(JSON.parse(value)).length > 0 ? 'payload' : undefined; | ||
} catch (e) { | ||
return undefined; | ||
} | ||
}; | ||
|
||
type SmsEditorPreviewProps = { | ||
workflow: WorkflowResponseDto; | ||
step: StepDataDto; | ||
formValues: Record<string, unknown>; | ||
}; | ||
|
||
const extensions = [loadLanguage('json')?.extension ?? []]; | ||
|
||
export const SmsEditorPreview = ({ workflow, step, formValues }: SmsEditorPreviewProps) => { | ||
const workflowSlug = workflow.workflowId; | ||
const stepSlug = step.stepId; | ||
const { editorValue, setEditorValue, previewStep, previewData, isPreviewPending } = useEditorPreview({ | ||
workflowSlug, | ||
stepSlug, | ||
controlValues: formValues, | ||
}); | ||
const [accordionValue, setAccordionValue] = useState<string | undefined>(getInitialAccordionValue(editorValue)); | ||
const [payloadError, setPayloadError] = useState(''); | ||
const [height, setHeight] = useState(0); | ||
const contentRef = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
setAccordionValue(getInitialAccordionValue(editorValue)); | ||
}, [editorValue]); | ||
|
||
useEffect(() => { | ||
const timeout = setTimeout(() => { | ||
if (contentRef.current) { | ||
const rect = contentRef.current.getBoundingClientRect(); | ||
setHeight(rect.height); | ||
} | ||
}, 0); | ||
|
||
return () => clearTimeout(timeout); | ||
}, [editorValue]); | ||
|
||
return ( | ||
<InAppTabsSection> | ||
<div className="relative flex flex-col gap-3"> | ||
<div className="flex items-center gap-2.5 text-sm font-medium"> | ||
<Notification5Fill className="size-3" /> | ||
SMS template editor | ||
</div> | ||
<div className="flex flex-col items-center justify-center gap-2"> | ||
<SmsPreview isPreviewPending={isPreviewPending} previewData={previewData} /> | ||
</div> | ||
<Accordion type="single" collapsible value={accordionValue} onValueChange={setAccordionValue}> | ||
<AccordionItem value="payload"> | ||
<AccordionTrigger> | ||
<div className="flex items-center gap-1"> | ||
<Code2 className="size-5" /> | ||
Configure preview | ||
</div> | ||
</AccordionTrigger> | ||
<AccordionContent | ||
ref={contentRef} | ||
className="flex flex-col gap-2" | ||
style={{ '--radix-collapsible-content-height': `${height}px` } as CSSProperties} | ||
> | ||
<Editor | ||
value={editorValue} | ||
onChange={setEditorValue} | ||
lang="json" | ||
extensions={extensions} | ||
className="border-neutral-alpha-200 bg-background text-foreground-600 mx-0 mt-0 rounded-lg border border-dashed p-3" | ||
/> | ||
{payloadError && <p className="text-destructive text-xs">{payloadError}</p>} | ||
<Button | ||
size="xs" | ||
type="button" | ||
variant="outline" | ||
className="self-end" | ||
onClick={() => { | ||
try { | ||
previewStep(); | ||
setPayloadError(''); | ||
} catch (e) { | ||
setPayloadError(String(e)); | ||
} | ||
}} | ||
> | ||
Apply | ||
</Button> | ||
</AccordionContent> | ||
</AccordionItem> | ||
</Accordion> | ||
</div> | ||
</InAppTabsSection> | ||
); | ||
}; |
19 changes: 19 additions & 0 deletions
19
apps/dashboard/src/components/workflow-editor/steps/sms/sms-editor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getComponentByType } from '@/components/workflow-editor/steps/component-utils'; | ||
import { SmsTabsSection } from '@/components/workflow-editor/steps/sms/sms-tabs-section'; | ||
import { type UiSchema } from '@novu/shared'; | ||
|
||
type SmsEditorProps = { uiSchema: UiSchema }; | ||
export const SmsEditor = (props: SmsEditorProps) => { | ||
const { uiSchema } = props; | ||
const { body } = uiSchema.properties ?? {}; | ||
|
||
return ( | ||
<div className="flex h-full flex-col"> | ||
<SmsTabsSection className="py-5"> | ||
<div className="flex flex-col gap-1 rounded-lg border border-neutral-100 p-1"> | ||
{getComponentByType({ component: body.component })} | ||
</div> | ||
</SmsTabsSection> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.