Skip to content

Commit

Permalink
fix: editor not submiting
Browse files Browse the repository at this point in the history
  • Loading branch information
BiswaViraj committed Apr 19, 2024
1 parent 855dc9a commit 477ece9
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions apps/web/src/pages/templates/components/StepEditorSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Sidebar } from '@novu/design-system';
import { StepTypeEnum } from '@novu/shared';
import { ReactNode } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { StepTypeEnum } from '@novu/shared';
import { Sidebar } from '@novu/design-system';

import { useStepIndex } from '../hooks/useStepIndex';
import { StepName } from './StepName';
import { useFormContext } from 'react-hook-form';
import { useBasePath } from '../hooks/useBasePath';
import { EditorSidebarHeaderActions } from './EditorSidebarHeaderActions';
import { useStepVariantsCount } from '../hooks/useStepVariantsCount';
import { useNavigateToVariantPreview } from '../hooks/useNavigateToVariantPreview';
import { useStepIndex } from '../hooks/useStepIndex';
import { useStepVariantsCount } from '../hooks/useStepVariantsCount';
import { EditorSidebarHeaderActions } from './EditorSidebarHeaderActions';
import { IForm } from './formTypes';
import { StepName } from './StepName';
import { useTemplateEditorForm } from './TemplateEditorFormProvider';

const StepSidebarHeader = () => {
const { channel } = useParams<{
Expand All @@ -35,6 +38,9 @@ export const StepEditorSidebar = ({ children }: { children: ReactNode }) => {
const navigate = useNavigate();
const basePath = useBasePath();
const { navigateToVariantPreview } = useNavigateToVariantPreview();
const { onSubmit, onInvalid } = useTemplateEditorForm();
const methods = useFormContext<IForm>();
const { handleSubmit } = methods;
const { stepIndex, variantIndex } = useStepIndex();
const { variantsCount } = useStepVariantsCount();
const key = `${stepIndex}_${variantIndex}`;
Expand All @@ -46,6 +52,10 @@ export const StepEditorSidebar = ({ children }: { children: ReactNode }) => {
StepTypeEnum.PUSH,
].includes(channel as StepTypeEnum);

const onSubmitHandler = async (data: IForm) => {
await onSubmit(data);
};

return (
<Sidebar
key={key}
Expand All @@ -62,6 +72,7 @@ export const StepEditorSidebar = ({ children }: { children: ReactNode }) => {
navigate(basePath);
}}
data-test-id="step-editor-sidebar"
onSubmit={handleSubmit(onSubmitHandler, onInvalid)}
>
{children}
</Sidebar>
Expand Down

0 comments on commit 477ece9

Please sign in to comment.