fix: Disable tabs of the pdf customization if the first field not filled up

This commit is contained in:
Ahmed Bouhuolia
2024-10-10 16:41:21 +02:00
parent cf78255220
commit 863c7693fa
8 changed files with 206 additions and 57 deletions

View File

@@ -10,6 +10,8 @@ import { ElementCustomizeFields } from './ElementCustomizeFields';
import { ElementCustomizePreview } from './ElementCustomizePreview';
import { extractChildren } from '@/utils/extract-children';
import { ElementPreviewState } from '../BrandingTemplates/types';
import { TabProps } from '@blueprintjs/core';
import { useBrandingState } from '../BrandingTemplates/_utils';
export interface ElementCustomizeProps<T, Y>
extends ElementCustomizeFormProps<T, Y> {
@@ -17,13 +19,13 @@ export interface ElementCustomizeProps<T, Y>
children?: React.ReactNode;
}
export function ElementCustomize<T, Y extends ElementPreviewState>({
initialValues,
validationSchema,
brandingState,
onSubmit,
export interface ElementCustomizeContentProps {
children?: React.ReactNode;
}
export function ElementCustomizeContent({
children,
}: ElementCustomizeProps<T, Y>) {
}: ElementCustomizeContentProps) {
const PaperTemplate = React.useMemo(
() => extractChildren(children, ElementCustomize.PaperTemplate),
[children],
@@ -32,23 +34,34 @@ export function ElementCustomize<T, Y extends ElementPreviewState>({
() => extractChildren(children, ElementCustomize.FieldsTab),
[children],
);
const brandingState = useBrandingState();
const value = { PaperTemplate, CustomizeTabs, brandingState };
return (
<ElementCustomizeTabsControllerProvider>
<ElementCustomizeProvider value={value}>
<Group spacing={0} align="stretch">
<ElementCustomizeFields />
<ElementCustomizePreview />
</Group>
</ElementCustomizeProvider>
</ElementCustomizeTabsControllerProvider>
);
}
export function ElementCustomize<T, Y extends ElementPreviewState>({
initialValues,
validationSchema,
onSubmit,
children,
}: ElementCustomizeProps<T, Y>) {
return (
<ElementCustomizeForm
initialValues={initialValues}
validationSchema={validationSchema}
onSubmit={onSubmit}
>
<ElementCustomizeTabsControllerProvider>
<ElementCustomizeProvider value={value}>
<Group spacing={0} align="stretch">
<ElementCustomizeFields />
<ElementCustomizePreview />
</Group>
</ElementCustomizeProvider>
</ElementCustomizeTabsControllerProvider>
{children}
</ElementCustomizeForm>
);
}
@@ -63,16 +76,17 @@ ElementCustomize.PaperTemplate = ({
return <>{children}</>;
};
export interface ElementCustomizeContentProps {
export interface ElementCustomizeFieldsTabProps {
id: string;
label: string;
children?: React.ReactNode;
tabProps?: Partial<TabProps>;
}
ElementCustomize.FieldsTab = ({
id,
label,
children,
}: ElementCustomizeContentProps) => {
}: ElementCustomizeFieldsTabProps) => {
return <>{children}</>;
};