Add Google login to checkout login form
This commit is contained in:
@@ -46,6 +46,7 @@ export const AuthStep: React.FC<AuthStepProps> = ({ privacyHtml, googleProfile,
|
||||
const [mode, setMode] = useState<'login' | 'register'>('register');
|
||||
const [isRedirectingToGoogle, setIsRedirectingToGoogle] = useState(false);
|
||||
const [showGoogleHelper, setShowGoogleHelper] = useState(false);
|
||||
const showGoogleControls = mode === 'register';
|
||||
|
||||
useEffect(() => {
|
||||
if (googleAuth?.status === 'signin') {
|
||||
@@ -60,6 +61,16 @@ export const AuthStep: React.FC<AuthStepProps> = ({ privacyHtml, googleProfile,
|
||||
}
|
||||
}, [googleAuth?.error]);
|
||||
|
||||
useEffect(() => {
|
||||
if (mode !== 'login') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (showGoogleHelper) {
|
||||
setShowGoogleHelper(false);
|
||||
}
|
||||
}, [mode, showGoogleHelper]);
|
||||
|
||||
const handleLoginSuccess = (payload: AuthUserPayload | null) => {
|
||||
if (!payload) {
|
||||
return;
|
||||
@@ -148,39 +159,43 @@ export const AuthStep: React.FC<AuthStepProps> = ({ privacyHtml, googleProfile,
|
||||
>
|
||||
{t('checkout.auth_step.switch_to_login')}
|
||||
</Button>
|
||||
<div className="flex flex-1 justify-start gap-2 sm:flex-none">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={handleGoogleLogin}
|
||||
disabled={isRedirectingToGoogle}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
{isRedirectingToGoogle ? (
|
||||
<LoaderCircle className="h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<GoogleIcon className="h-4 w-4" />
|
||||
)}
|
||||
{t('checkout.auth_step.continue_with_google')}
|
||||
</Button>
|
||||
<CollapsibleTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1 rounded-full border border-muted-foreground/30 px-3 py-1 text-xs font-medium text-muted-foreground transition hover:border-muted-foreground/60 hover:text-foreground",
|
||||
showGoogleHelper && "bg-muted/60 text-foreground"
|
||||
)}
|
||||
{showGoogleControls && (
|
||||
<div className="flex flex-1 justify-start gap-2 sm:flex-none">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={handleGoogleLogin}
|
||||
disabled={isRedirectingToGoogle}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
{t('checkout.auth_step.google_helper_badge')}
|
||||
<ChevronDown className={cn("h-3 w-3 transition-transform", showGoogleHelper && "rotate-180")} />
|
||||
</button>
|
||||
</CollapsibleTrigger>
|
||||
</div>
|
||||
{isRedirectingToGoogle ? (
|
||||
<LoaderCircle className="h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<GoogleIcon className="h-4 w-4" />
|
||||
)}
|
||||
{t('checkout.auth_step.continue_with_google')}
|
||||
</Button>
|
||||
<CollapsibleTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1 rounded-full border border-muted-foreground/30 px-3 py-1 text-xs font-medium text-muted-foreground transition hover:border-muted-foreground/60 hover:text-foreground",
|
||||
showGoogleHelper && "bg-muted/60 text-foreground"
|
||||
)}
|
||||
>
|
||||
{t('checkout.auth_step.google_helper_badge')}
|
||||
<ChevronDown className={cn("h-3 w-3 transition-transform", showGoogleHelper && "rotate-180")} />
|
||||
</button>
|
||||
</CollapsibleTrigger>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<CollapsibleContent>
|
||||
<Alert className="border-dashed border-muted/60 bg-muted/20 text-xs sm:text-sm">
|
||||
<AlertDescription>{t('checkout.auth_step.google_helper')}</AlertDescription>
|
||||
</Alert>
|
||||
</CollapsibleContent>
|
||||
{showGoogleControls && (
|
||||
<CollapsibleContent>
|
||||
<Alert className="border-dashed border-muted/60 bg-muted/20 text-xs sm:text-sm">
|
||||
<AlertDescription>{t('checkout.auth_step.google_helper')}</AlertDescription>
|
||||
</Alert>
|
||||
</CollapsibleContent>
|
||||
)}
|
||||
</Collapsible>
|
||||
|
||||
{googleAuth?.error && (
|
||||
|
||||
Reference in New Issue
Block a user