|
1 | 1 | import { useEnvironment } from '@/context/environment/hooks';
|
2 | 2 | import { useTriggerWorkflow } from '@/hooks/use-trigger-workflow';
|
3 | 3 | import { zodResolver } from '@hookform/resolvers/zod';
|
4 |
| -import { IEnvironment, StepTypeEnum, WorkflowCreationSourceEnum } from '@novu/shared'; |
5 | 4 | import { useEffect, useState } from 'react';
|
6 | 5 | import { useForm } from 'react-hook-form';
|
7 | 6 | import { RiNotification2Fill } from 'react-icons/ri';
|
8 | 7 | import { useNavigate } from 'react-router-dom';
|
9 | 8 | import { z } from 'zod';
|
10 |
| -import { createWorkflow } from '../../api/workflows'; |
11 | 9 | import { ONBOARDING_DEMO_WORKFLOW_ID } from '../../config';
|
12 | 10 | import { useAuth } from '../../context/auth/hooks';
|
13 |
| -import { useFetchWorkflows } from '../../hooks/use-fetch-workflows'; |
14 | 11 | import { useTelemetry } from '../../hooks/use-telemetry';
|
| 12 | +import { useInitDemoWorkflow } from '../../hooks/use-init-demo-workflow'; |
15 | 13 | import { ROUTES } from '../../utils/routes';
|
16 | 14 | import { TelemetryEvent } from '../../utils/telemetry';
|
17 | 15 | import { Button } from '../primitives/button';
|
@@ -92,30 +90,11 @@ export function InboxPlayground() {
|
92 | 90 | });
|
93 | 91 |
|
94 | 92 | const { triggerWorkflow, isPending } = useTriggerWorkflow();
|
95 |
| - const { data } = useFetchWorkflows({ query: ONBOARDING_DEMO_WORKFLOW_ID }); |
96 | 93 | const auth = useAuth();
|
97 | 94 | const [hasNotificationBeenSent, setHasNotificationBeenSent] = useState(false);
|
98 | 95 | const navigate = useNavigate();
|
99 | 96 | const telemetry = useTelemetry();
|
100 |
| - |
101 |
| - useEffect(() => { |
102 |
| - if (!data) return; |
103 |
| - |
104 |
| - /** |
105 |
| - * We only want to create the demo workflow if it doesn't exist yet. |
106 |
| - * This workflow will be used by the inbox preview examples |
107 |
| - */ |
108 |
| - const initializeDemoWorkflow = async () => { |
109 |
| - const workflow = data?.workflows.find((workflow) => workflow.workflowId?.includes(ONBOARDING_DEMO_WORKFLOW_ID)); |
110 |
| - |
111 |
| - if (!workflow) { |
112 |
| - await createDemoWorkflow({ environment: currentEnvironment! }); |
113 |
| - } |
114 |
| - }; |
115 |
| - |
116 |
| - initializeDemoWorkflow(); |
117 |
| - // eslint-disable-next-line react-hooks/exhaustive-deps |
118 |
| - }, [data]); |
| 97 | + useInitDemoWorkflow(currentEnvironment!); |
119 | 98 |
|
120 | 99 | const handleSendNotification = async () => {
|
121 | 100 | try {
|
@@ -249,40 +228,3 @@ export function InboxPlayground() {
|
249 | 228 | </div>
|
250 | 229 | );
|
251 | 230 | }
|
252 |
| - |
253 |
| -async function createDemoWorkflow({ environment }: { environment: IEnvironment }) { |
254 |
| - await createWorkflow({ |
255 |
| - environment, |
256 |
| - workflow: { |
257 |
| - name: 'Onboarding Demo Workflow', |
258 |
| - description: 'A demo workflow to showcase the Inbox component', |
259 |
| - workflowId: ONBOARDING_DEMO_WORKFLOW_ID, |
260 |
| - steps: [ |
261 |
| - { |
262 |
| - name: 'Inbox', |
263 |
| - type: StepTypeEnum.IN_APP, |
264 |
| - controlValues: { |
265 |
| - subject: '{{payload.subject}}', |
266 |
| - body: '{{payload.body}}', |
267 |
| - avatar: window.location.origin + '/images/novu.svg', |
268 |
| - primaryAction: { |
269 |
| - label: '{{payload.primaryActionLabel}}', |
270 |
| - redirect: { |
271 |
| - target: '_self', |
272 |
| - url: '/onboarding/inbox/embed', |
273 |
| - }, |
274 |
| - }, |
275 |
| - secondaryAction: { |
276 |
| - label: '{{payload.secondaryActionLabel}}', |
277 |
| - redirect: { |
278 |
| - target: '_self', |
279 |
| - url: '/onboarding/inbox/embed', |
280 |
| - }, |
281 |
| - }, |
282 |
| - }, |
283 |
| - }, |
284 |
| - ], |
285 |
| - __source: WorkflowCreationSourceEnum.DASHBOARD, |
286 |
| - }, |
287 |
| - }); |
288 |
| -} |
0 commit comments