mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 09:12:02 +10:00
@ -26,6 +26,7 @@ import { useToast } from '@documenso/ui/primitives/use-toast';
|
|||||||
|
|
||||||
import { claimPlan } from '~/api/claim-plan/fetcher';
|
import { claimPlan } from '~/api/claim-plan/fetcher';
|
||||||
|
|
||||||
|
import { STEP } from '../constants';
|
||||||
import { FormErrorMessage } from '../form/form-error-message';
|
import { FormErrorMessage } from '../form/form-error-message';
|
||||||
|
|
||||||
const ZWidgetFormSchema = z
|
const ZWidgetFormSchema = z
|
||||||
@ -48,13 +49,16 @@ const ZWidgetFormSchema = z
|
|||||||
|
|
||||||
export type TWidgetFormSchema = z.infer<typeof ZWidgetFormSchema>;
|
export type TWidgetFormSchema = z.infer<typeof ZWidgetFormSchema>;
|
||||||
|
|
||||||
|
type StepKeys = keyof typeof STEP;
|
||||||
|
type StepValues = (typeof STEP)[StepKeys];
|
||||||
|
|
||||||
export type WidgetProps = HTMLAttributes<HTMLDivElement>;
|
export type WidgetProps = HTMLAttributes<HTMLDivElement>;
|
||||||
|
|
||||||
export const Widget = ({ className, children, ...props }: WidgetProps) => {
|
export const Widget = ({ className, children, ...props }: WidgetProps) => {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const event = usePlausible();
|
const event = usePlausible();
|
||||||
|
|
||||||
const [step, setStep] = useState<'EMAIL' | 'NAME' | 'SIGN'>('EMAIL');
|
const [step, setStep] = useState<StepValues>(STEP.EMAIL);
|
||||||
const [showSigningDialog, setShowSigningDialog] = useState(false);
|
const [showSigningDialog, setShowSigningDialog] = useState(false);
|
||||||
const [draftSignatureDataUrl, setDraftSignatureDataUrl] = useState<string | null>(null);
|
const [draftSignatureDataUrl, setDraftSignatureDataUrl] = useState<string | null>(null);
|
||||||
|
|
||||||
@ -81,11 +85,11 @@ export const Widget = ({ className, children, ...props }: WidgetProps) => {
|
|||||||
const signatureText = watch('signatureText');
|
const signatureText = watch('signatureText');
|
||||||
|
|
||||||
const stepsRemaining = useMemo(() => {
|
const stepsRemaining = useMemo(() => {
|
||||||
if (step === 'NAME') {
|
if (step === STEP.NAME) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (step === 'SIGN') {
|
if (step === STEP.EMAIL) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,16 +97,16 @@ export const Widget = ({ className, children, ...props }: WidgetProps) => {
|
|||||||
}, [step]);
|
}, [step]);
|
||||||
|
|
||||||
const onNextStepClick = () => {
|
const onNextStepClick = () => {
|
||||||
if (step === 'EMAIL') {
|
if (step === STEP.EMAIL) {
|
||||||
setStep('NAME');
|
setStep(STEP.NAME);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
document.querySelector<HTMLElement>('#name')?.focus();
|
document.querySelector<HTMLElement>('#name')?.focus();
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (step === 'NAME') {
|
if (step === STEP.NAME) {
|
||||||
setStep('SIGN');
|
setStep(STEP.SIGN);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
document.querySelector<HTMLElement>('#signatureText')?.focus();
|
document.querySelector<HTMLElement>('#signatureText')?.focus();
|
||||||
@ -226,7 +230,7 @@ export const Widget = ({ className, children, ...props }: WidgetProps) => {
|
|||||||
type="button"
|
type="button"
|
||||||
className="bg-primary h-full w-14 rounded"
|
className="bg-primary h-full w-14 rounded"
|
||||||
disabled={!field.value || !!errors.email?.message}
|
disabled={!field.value || !!errors.email?.message}
|
||||||
onClick={() => step === 'EMAIL' && onNextStepClick()}
|
onClick={() => step === STEP.EMAIL && onNextStepClick()}
|
||||||
>
|
>
|
||||||
Next
|
Next
|
||||||
</Button>
|
</Button>
|
||||||
@ -238,7 +242,7 @@ export const Widget = ({ className, children, ...props }: WidgetProps) => {
|
|||||||
<FormErrorMessage error={errors.email} className="mt-1" />
|
<FormErrorMessage error={errors.email} className="mt-1" />
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|
||||||
{(step === 'NAME' || step === 'SIGN') && (
|
{(step === STEP.NAME || step === STEP.SIGN) && (
|
||||||
<motion.div
|
<motion.div
|
||||||
key="name"
|
key="name"
|
||||||
className="mt-4"
|
className="mt-4"
|
||||||
|
|||||||
5
apps/marketing/src/components/constants.ts
Normal file
5
apps/marketing/src/components/constants.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export const STEP = {
|
||||||
|
EMAIL: 'EMAIL',
|
||||||
|
NAME: 'NAME',
|
||||||
|
SIGN: "SIGN"
|
||||||
|
} as const;
|
||||||
Reference in New Issue
Block a user