import React, { useState } from "react"; import { usePage } from "@inertiajs/react"; import { Button } from "@/components/ui/button"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { useCheckoutWizard } from "../WizardContext"; import LoginForm, { AuthUserPayload } from "../../../auth/LoginForm"; import RegisterForm, { RegisterSuccessPayload } from "../../../auth/RegisterForm"; import { useTranslation } from 'react-i18next'; interface AuthStepProps { privacyHtml: string; } export const AuthStep: React.FC = ({ privacyHtml }) => { const { t } = useTranslation('marketing'); const page = usePage<{ locale?: string }>(); const locale = page.props.locale ?? "de"; const { isAuthenticated, authUser, setAuthUser, nextStep, selectedPackage } = useCheckoutWizard(); const [mode, setMode] = useState<'login' | 'register'>('register'); const handleLoginSuccess = (payload: AuthUserPayload | null) => { if (!payload) { return; } setAuthUser({ id: payload.id ?? 0, email: payload.email ?? "", name: payload.name ?? undefined, pending_purchase: Boolean(payload.pending_purchase), }); nextStep(); }; const handleRegisterSuccess = (result: RegisterSuccessPayload) => { const nextUser = result?.user ?? null; if (nextUser) { setAuthUser({ id: nextUser.id ?? 0, email: nextUser.email ?? "", name: nextUser.name ?? undefined, pending_purchase: Boolean(result?.pending_purchase ?? nextUser.pending_purchase), }); } nextStep(); }; if (isAuthenticated && authUser) { return (
{t('checkout.auth_step.already_logged_in_title')} {t('checkout.auth_step.already_logged_in_desc', { email: authUser?.email || '' })}
); } return (
{t('checkout.auth_step.google_coming_soon')}
{mode === 'register' ? ( selectedPackage && ( ) ) : ( )}
); };