switched to paddle inline checkout, removed paypal and most of stripe. added product sync between app and paddle.
This commit is contained in:
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
|
||||
import toast from 'react-hot-toast';
|
||||
import { LoaderCircle, User, Mail, Phone, Lock, MapPin } from 'lucide-react';
|
||||
import { Dialog, DialogContent, DialogTitle, DialogDescription } from '@/components/ui/dialog';
|
||||
import type { GoogleProfilePrefill } from '../marketing/checkout/types';
|
||||
|
||||
declare const route: (name: string, params?: Record<string, unknown>) => string;
|
||||
|
||||
@@ -18,6 +19,8 @@ interface RegisterFormProps {
|
||||
onSuccess?: (payload: RegisterSuccessPayload) => void;
|
||||
privacyHtml: string;
|
||||
locale?: string;
|
||||
prefill?: GoogleProfilePrefill;
|
||||
onClearGoogleProfile?: () => void;
|
||||
}
|
||||
|
||||
type RegisterFormFields = {
|
||||
@@ -30,13 +33,15 @@ type RegisterFormFields = {
|
||||
address: string;
|
||||
phone: string;
|
||||
privacy_consent: boolean;
|
||||
terms: boolean;
|
||||
package_id: number | null;
|
||||
};
|
||||
|
||||
export default function RegisterForm({ packageId, onSuccess, privacyHtml, locale }: RegisterFormProps) {
|
||||
export default function RegisterForm({ packageId, onSuccess, privacyHtml, locale, prefill, onClearGoogleProfile }: RegisterFormProps) {
|
||||
const [privacyOpen, setPrivacyOpen] = useState(false);
|
||||
const [hasTriedSubmit, setHasTriedSubmit] = useState(false);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [prefillApplied, setPrefillApplied] = useState(false);
|
||||
const { t } = useTranslation(['auth', 'common']);
|
||||
const page = usePage<{ errors: Record<string, string>; locale?: string; auth?: { user?: any | null } }>();
|
||||
const resolvedLocale = locale ?? page.props.locale ?? 'de';
|
||||
@@ -51,6 +56,7 @@ export default function RegisterForm({ packageId, onSuccess, privacyHtml, locale
|
||||
address: '',
|
||||
phone: '',
|
||||
privacy_consent: false,
|
||||
terms: false,
|
||||
package_id: packageId || null,
|
||||
});
|
||||
|
||||
@@ -61,6 +67,62 @@ export default function RegisterForm({ packageId, onSuccess, privacyHtml, locale
|
||||
}, [errors, hasTriedSubmit]);
|
||||
|
||||
const registerEndpoint = '/checkout/register';
|
||||
|
||||
const namePrefill = useMemo(() => {
|
||||
const rawFirst = prefill?.given_name ?? prefill?.name?.split(' ')[0] ?? '';
|
||||
const remaining = prefill?.name ? prefill.name.split(' ').slice(1).join(' ') : '';
|
||||
const rawLast = prefill?.family_name ?? remaining;
|
||||
|
||||
return {
|
||||
first: rawFirst ?? '',
|
||||
last: rawLast ?? '',
|
||||
};
|
||||
}, [prefill]);
|
||||
|
||||
const suggestedUsername = useMemo(() => {
|
||||
if (prefill?.email) {
|
||||
const localPart = prefill.email.split('@')[0];
|
||||
if (localPart) {
|
||||
return localPart.slice(0, 30);
|
||||
}
|
||||
}
|
||||
|
||||
const first = prefill?.given_name ?? prefill?.name?.split(' ')[0] ?? '';
|
||||
const last = prefill?.family_name ?? prefill?.name?.split(' ').slice(1).join(' ') ?? '';
|
||||
const combined = `${first}${last}`.trim();
|
||||
if (!combined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return combined
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '')
|
||||
.slice(0, 30) || undefined;
|
||||
}, [prefill]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!prefill || prefillApplied) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (namePrefill.first && !data.first_name) {
|
||||
setData('first_name', namePrefill.first);
|
||||
}
|
||||
|
||||
if (namePrefill.last && !data.last_name) {
|
||||
setData('last_name', namePrefill.last);
|
||||
}
|
||||
|
||||
if (prefill.email && !data.email) {
|
||||
setData('email', prefill.email);
|
||||
}
|
||||
|
||||
if (suggestedUsername && !data.username) {
|
||||
setData('username', suggestedUsername);
|
||||
}
|
||||
|
||||
setPrefillApplied(true);
|
||||
}, [prefill, namePrefill.first, namePrefill.last, data.first_name, data.last_name, data.email, data.username, prefillApplied, setData, suggestedUsername]);
|
||||
|
||||
const submit = async (event: React.FormEvent) => {
|
||||
event.preventDefault();
|
||||
@@ -95,6 +157,7 @@ export default function RegisterForm({ packageId, onSuccess, privacyHtml, locale
|
||||
redirect: json?.redirect ?? null,
|
||||
pending_purchase: json?.pending_purchase ?? json?.user?.pending_purchase ?? false,
|
||||
});
|
||||
onClearGoogleProfile?.();
|
||||
reset();
|
||||
setHasTriedSubmit(false);
|
||||
return;
|
||||
@@ -362,9 +425,13 @@ export default function RegisterForm({ packageId, onSuccess, privacyHtml, locale
|
||||
checked={data.privacy_consent}
|
||||
onChange={(e) => {
|
||||
setData('privacy_consent', e.target.checked);
|
||||
setData('terms', e.target.checked);
|
||||
if (e.target.checked && errors.privacy_consent) {
|
||||
clearErrors('privacy_consent');
|
||||
}
|
||||
if (e.target.checked && errors.terms) {
|
||||
clearErrors('terms');
|
||||
}
|
||||
}}
|
||||
className="h-4 w-4 text-[#FFB6C1] focus:ring-[#FFB6C1] border-gray-300 rounded"
|
||||
/>
|
||||
@@ -379,6 +446,7 @@ export default function RegisterForm({ packageId, onSuccess, privacyHtml, locale
|
||||
</button>.
|
||||
</label>
|
||||
{errors.privacy_consent && <p className="mt-2 text-sm text-red-600">{errors.privacy_consent}</p>}
|
||||
{errors.terms && <p className="mt-2 text-sm text-red-600">{errors.terms}</p>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -419,8 +487,3 @@ export default function RegisterForm({ packageId, onSuccess, privacyHtml, locale
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user