mirror of
https://github.com/documenso/documenso
synced 2026-04-21 21:37:18 +00:00
Adds support for creating documents and templates using our embed components. Support is super primitive at the moment and is being polished.
68 lines
2 KiB
TypeScript
68 lines
2 KiB
TypeScript
import { createContext, useContext } from 'react';
|
|
|
|
export type ConfigureDocumentContext = {
|
|
// General
|
|
isTemplate: boolean;
|
|
isPersisted: boolean;
|
|
// Features
|
|
features: {
|
|
allowConfigureSignatureTypes?: boolean;
|
|
allowConfigureLanguage?: boolean;
|
|
allowConfigureDateFormat?: boolean;
|
|
allowConfigureTimezone?: boolean;
|
|
allowConfigureRedirectUrl?: boolean;
|
|
allowConfigureCommunication?: boolean;
|
|
};
|
|
};
|
|
|
|
const ConfigureDocumentContext = createContext<ConfigureDocumentContext | null>(null);
|
|
|
|
export type ConfigureDocumentProviderProps = {
|
|
isTemplate?: boolean;
|
|
isPersisted?: boolean;
|
|
features: {
|
|
allowConfigureSignatureTypes?: boolean;
|
|
allowConfigureLanguage?: boolean;
|
|
allowConfigureDateFormat?: boolean;
|
|
allowConfigureTimezone?: boolean;
|
|
allowConfigureRedirectUrl?: boolean;
|
|
allowConfigureCommunication?: boolean;
|
|
};
|
|
children: React.ReactNode;
|
|
};
|
|
|
|
export const ConfigureDocumentProvider = ({
|
|
isTemplate,
|
|
isPersisted,
|
|
features,
|
|
children,
|
|
}: ConfigureDocumentProviderProps) => {
|
|
return (
|
|
<ConfigureDocumentContext.Provider
|
|
value={{
|
|
isTemplate: isTemplate ?? false,
|
|
isPersisted: isPersisted ?? false,
|
|
features: {
|
|
allowConfigureSignatureTypes: features.allowConfigureSignatureTypes ?? true,
|
|
allowConfigureLanguage: features.allowConfigureLanguage ?? true,
|
|
allowConfigureDateFormat: features.allowConfigureDateFormat ?? true,
|
|
allowConfigureTimezone: features.allowConfigureTimezone ?? true,
|
|
allowConfigureRedirectUrl: features.allowConfigureRedirectUrl ?? true,
|
|
allowConfigureCommunication: features.allowConfigureCommunication ?? true,
|
|
},
|
|
}}
|
|
>
|
|
{children}
|
|
</ConfigureDocumentContext.Provider>
|
|
);
|
|
};
|
|
|
|
export const useConfigureDocument = () => {
|
|
const context = useContext(ConfigureDocumentContext);
|
|
|
|
if (!context) {
|
|
throw new Error('useConfigureDocument must be used within a ConfigureDocumentProvider');
|
|
}
|
|
|
|
return context;
|
|
};
|