mirror of
https://github.com/documenso/documenso
synced 2026-04-21 13:27:18 +00:00
fix: missing embed direct template email validation (#2635)
This commit is contained in:
parent
5be71cca21
commit
53b6078fa9
1 changed files with 25 additions and 2 deletions
|
|
@ -14,6 +14,7 @@ import {
|
|||
import { LucideChevronDown, LucideChevronUp } from 'lucide-react';
|
||||
import { DateTime } from 'luxon';
|
||||
import { useSearchParams } from 'react-router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { useThrottleFn } from '@documenso/lib/client-only/hooks/use-throttle-fn';
|
||||
import { DEFAULT_DOCUMENT_DATE_FORMAT } from '@documenso/lib/constants/date-formats';
|
||||
|
|
@ -35,6 +36,7 @@ import type {
|
|||
TSignFieldWithTokenMutationSchema,
|
||||
} from '@documenso/trpc/server/field-router/schema';
|
||||
import { FieldToolTip } from '@documenso/ui/components/field/field-tooltip';
|
||||
import { cn } from '@documenso/ui/lib/utils';
|
||||
import { Button } from '@documenso/ui/primitives/button';
|
||||
import { ElementVisible } from '@documenso/ui/primitives/element-visible';
|
||||
import { Input } from '@documenso/ui/primitives/input';
|
||||
|
|
@ -94,6 +96,7 @@ export const EmbedDirectTemplateClientPage = ({
|
|||
const [isNameLocked, setIsNameLocked] = useState(false);
|
||||
|
||||
const [showPendingFieldTooltip, setShowPendingFieldTooltip] = useState(false);
|
||||
const [emailError, setEmailError] = useState<string | null>(null);
|
||||
|
||||
const [throttledOnCompleteClick, isThrottled] = useThrottleFn(() => void onCompleteClick(), 500);
|
||||
|
||||
|
|
@ -207,6 +210,14 @@ export const EmbedDirectTemplateClientPage = ({
|
|||
return;
|
||||
}
|
||||
|
||||
const { success: isEmailValid } = z.string().email().safeParse(email);
|
||||
|
||||
if (!isEmailValid) {
|
||||
setEmailError(_(msg`A valid email is required`));
|
||||
setIsExpanded(true);
|
||||
return;
|
||||
}
|
||||
|
||||
let directTemplateExternalId = searchParams?.get('externalId') || undefined;
|
||||
|
||||
if (directTemplateExternalId) {
|
||||
|
|
@ -442,11 +453,23 @@ export const EmbedDirectTemplateClientPage = ({
|
|||
<Input
|
||||
type="email"
|
||||
id="email"
|
||||
className="mt-2 bg-background"
|
||||
className={cn(
|
||||
'mt-2 bg-background',
|
||||
emailError && 'border-destructive ring-2 ring-destructive/20',
|
||||
)}
|
||||
disabled={isEmailLocked}
|
||||
value={email}
|
||||
onChange={(e) => !isEmailLocked && setEmail(e.target.value.trim())}
|
||||
onChange={(e) => {
|
||||
if (!isEmailLocked) {
|
||||
setEmail(e.target.value.trim());
|
||||
setEmailError(null);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
{emailError && (
|
||||
<p className="mt-2 text-xs font-medium text-destructive">{emailError}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{hasSignatureField && (
|
||||
|
|
|
|||
Loading…
Reference in a new issue