-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): Implement email step editor & mini preview (#7129)
- Loading branch information
Showing
20 changed files
with
1,429 additions
and
255 deletions.
There are no files selected for viewing
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
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
79 changes: 79 additions & 0 deletions
79
apps/dashboard/src/components/workflow-editor/steps/email/configure-email-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,79 @@ | ||
import * as Sentry from '@sentry/react'; | ||
import { HTMLAttributes, useEffect } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
import { useStep } from '@/components/workflow-editor/steps/step-provider'; | ||
import { usePreviewStep } from '@/hooks'; | ||
import { EmailPreviewHeader } from '@/components/workflow-editor/steps/email/email-preview'; | ||
import { Separator } from '@/components/primitives/separator'; | ||
import { Skeleton } from '@/components/primitives/skeleton'; | ||
import { ChannelTypeEnum } from '@novu/shared'; | ||
import { cn } from '@/utils/ui'; | ||
|
||
type MiniEmailPreviewProps = HTMLAttributes<HTMLDivElement>; | ||
const MiniEmailPreview = (props: MiniEmailPreviewProps) => { | ||
const { className, children, ...rest } = props; | ||
return ( | ||
<div | ||
className={cn( | ||
'border-neutral-alpha-200 before:to-background relative isolate mb-4 rounded-lg border border-dashed before:pointer-events-none before:absolute before:inset-0 before:-m-px before:rounded-lg before:bg-gradient-to-b before:from-transparent before:bg-clip-padding', | ||
className | ||
)} | ||
{...rest} | ||
> | ||
<div className="flex flex-col gap-1 py-1"> | ||
<EmailPreviewHeader className="px-2 text-sm" /> | ||
<Separator className="bg-neutral-alpha-100" /> | ||
<div className="relative z-10 space-y-1 px-2">{children}</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
type ConfigureEmailStepPreviewProps = HTMLAttributes<HTMLDivElement>; | ||
export function ConfigureEmailStepPreview(props: ConfigureEmailStepPreviewProps) { | ||
const { | ||
previewStep, | ||
data: previewData, | ||
isPending: isPreviewPending, | ||
} = usePreviewStep({ | ||
onError: (error) => { | ||
Sentry.captureException(error); | ||
}, | ||
}); | ||
const { step, isPending } = useStep(); | ||
|
||
const { workflowSlug, stepSlug } = useParams<{ | ||
workflowSlug: string; | ||
stepSlug: string; | ||
}>(); | ||
|
||
useEffect(() => { | ||
if (!workflowSlug || !stepSlug || !step || isPending) return; | ||
|
||
previewStep({ | ||
workflowSlug, | ||
stepSlug, | ||
data: { controlValues: step.controls.values, previewPayload: {} }, | ||
}); | ||
}, [workflowSlug, stepSlug, previewStep, step, isPending]); | ||
|
||
if (isPreviewPending) { | ||
return ( | ||
<MiniEmailPreview> | ||
<Skeleton className="h-5 w-full max-w-[25ch]" /> | ||
<Skeleton className="h-5 w-full max-w-[15ch]" /> | ||
</MiniEmailPreview> | ||
); | ||
} | ||
|
||
if (previewData?.result?.type !== ChannelTypeEnum.EMAIL) { | ||
return <MiniEmailPreview>No preview available</MiniEmailPreview>; | ||
} | ||
|
||
return ( | ||
<MiniEmailPreview {...props}> | ||
<div className="text-foreground-400 line-clamp-2 text-xs">{previewData.result.preview.subject}</div> | ||
</MiniEmailPreview> | ||
); | ||
} |
Oops, something went wrong.