Files
webb/src/components/sections/AppHandoffSection.tsx
T

209 lines
8.1 KiB
TypeScript
Raw Normal View History

'use client';
import React, { useState, useEffect } from 'react';
import QRCode from 'qrcode';
import {
Smartphone,
Copy,
Check,
ExternalLink,
2026-11-06 10:53:55 +05:30
ShieldCheck
} from 'lucide-react';
import { AppItem, ToolItem, resolveLocalised } from '@/types';
import { KineticText } from '@/components/magicui/kinetic-text';
interface AppHandoffSectionProps {
app?: AppItem;
tool?: ToolItem | null;
locale?: string;
showBonus?: boolean;
showQr?: boolean;
}
export function AppHandoffSection({
app,
tool,
locale = 'en',
showBonus = true,
showQr = true,
}: AppHandoffSectionProps) {
const [qrDataUrl, setQrDataUrl] = useState<string>('');
const [copiedPromo, setCopiedPromo] = useState(false);
const [copiedLink, setCopiedLink] = useState(false);
const [origin, setOrigin] = useState<string>('');
useEffect(() => {
if (typeof window !== 'undefined') {
setOrigin(window.location.origin);
}
}, []);
if (!app) return null;
const bonusCode = app.welcomeBonus?.code || 'TRYWEB50';
const baseHost = origin || 'http://localhost:3000';
const targetUrl = tool
? `${baseHost}/go/${tool.slug}/${app.slug}?promo=${bonusCode}`
: `${baseHost}/apps/${app.slug}?promo=${bonusCode}`;
useEffect(() => {
if (showQr) {
QRCode.toDataURL(targetUrl, {
2026-11-06 10:53:55 +05:30
width: 220,
margin: 1,
color: {
2026-11-06 10:53:55 +05:30
dark: '#141E28',
light: '#F8F9FA',
},
})
2026-11-06 10:53:55 +05:30
.then((url) => setQrDataUrl(url))
.catch(() => {});
}
2026-11-06 10:53:55 +05:30
}, [showQr, targetUrl]);
const copyPromo = () => {
navigator.clipboard.writeText(bonusCode);
setCopiedPromo(true);
setTimeout(() => setCopiedPromo(false), 2000);
};
2026-11-06 10:53:55 +05:30
const copyLink = () => {
navigator.clipboard.writeText(targetUrl);
setCopiedLink(true);
setTimeout(() => setCopiedLink(false), 2000);
};
const appName = resolveLocalised(app.name, locale);
const appTagline = resolveLocalised(app.tagline, locale);
return (
<section id="app-handoff" className="py-16 sm:py-24 bg-paper border-b border-rule relative overflow-hidden">
{/* Studio Lighting Background Glow */}
<div
className="pointer-events-none absolute top-10 left-10 w-[500px] h-[350px] [background:radial-gradient(ellipse_at_center,color-mix(in_oklab,var(--color-accent)_12%,transparent)_0%,transparent_70%)]"
aria-hidden="true"
/>
<div
className="pointer-events-none absolute inset-0 opacity-20 studio-proof-grid"
aria-hidden="true"
/>
<div className="max-w-container mx-auto px-4 sm:px-6 lg:px-8 space-y-10 relative z-10">
2026-11-06 10:53:55 +05:30
{/* Section Header */}
<div className="max-w-2xl space-y-2 border-b border-rule pb-5">
<h2 className="text-3xl sm:text-4xl font-display font-bold text-ink tracking-tight">
<KineticText>Continue on mobile</KineticText>
2026-11-06 10:53:55 +05:30
</h2>
<p className="text-sm sm:text-base text-ink-2 font-body text-pretty">
Handoff this tool directly to your iOS or Android phone with 50 bonus credits.
</p>
</div>
2026-11-06 10:53:55 +05:30
<div className="grid grid-cols-1 lg:grid-cols-12 gap-8 items-start">
{/* Left Column: App Specifications & Store Buttons */}
<div className="lg:col-span-7 studio-sheet rounded-3xl p-6 sm:p-8 space-y-6">
2026-11-06 10:53:55 +05:30
<div className="border-b border-rule pb-5 space-y-2">
<span className="text-xs text-muted font-body">Dedicated companion client</span>
<h3 className="text-2xl font-display font-bold text-ink">
{appName}
</h3>
<p className="text-sm text-ink-2 font-body leading-relaxed">
{appTagline}
</p>
</div>
2026-11-06 10:53:55 +05:30
{/* Promo Voucher */}
{showBonus && (
<div className="p-4 bg-paper-2 border border-rule rounded-2xl flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3">
2026-11-06 10:53:55 +05:30
<div className="space-y-0.5">
<span className="text-xs font-body font-semibold text-ink">
50 Free credits voucher code
</span>
<p className="text-xs text-muted font-body">
Enter during installation for complimentary batch runs.
</p>
</div>
<div className="flex items-center gap-2">
<span className="font-body text-sm font-semibold text-accent px-3 py-1 bg-paper-hi border border-rule rounded-full">
2026-11-06 10:53:55 +05:30
{bonusCode}
</span>
<button
type="button"
onClick={copyPromo}
className="btn-secondary text-xs px-3 py-1.5 rounded-full min-h-[36px]"
2026-11-06 10:53:55 +05:30
aria-label="Copy voucher code"
>
{copiedPromo ? <Check className="w-3.5 h-3.5 text-accent" aria-hidden="true" /> : <Copy className="w-3.5 h-3.5 text-muted" aria-hidden="true" />}
</button>
</div>
</div>
)}
2026-11-06 10:53:55 +05:30
{/* Official Store Buttons */}
<div className="pt-2 space-y-3">
<span className="text-xs text-muted font-body block">Direct store installation</span>
<div className="flex flex-col sm:flex-row flex-wrap gap-3">
<a
href={app.stores?.ios?.url || `/go/${tool?.slug || 'explore'}/${app.slug}`}
target="_blank"
rel="noopener noreferrer"
className="btn-secondary min-h-[48px] rounded-full justify-center w-full sm:w-auto"
>
2026-11-06 10:53:55 +05:30
<Smartphone className="w-4 h-4 text-accent" aria-hidden="true" />
<span>Apple App Store</span>
<ExternalLink className="w-3.5 h-3.5 text-muted ml-1" aria-hidden="true" />
</a>
<a
href={app.stores?.android?.url || `/go/${tool?.slug || 'explore'}/${app.slug}`}
target="_blank"
rel="noopener noreferrer"
className="btn-secondary min-h-[48px] rounded-full justify-center w-full sm:w-auto"
>
2026-11-06 10:53:55 +05:30
<Smartphone className="w-4 h-4 text-accent" aria-hidden="true" />
<span>Google Play</span>
<ExternalLink className="w-3.5 h-3.5 text-muted ml-1" aria-hidden="true" />
</a>
<button
type="button"
2026-11-06 10:53:55 +05:30
onClick={copyLink}
className="btn-secondary min-h-[48px] rounded-full justify-center w-full sm:w-auto"
2026-11-06 10:53:55 +05:30
aria-label="Copy direct deep link"
>
2026-11-06 10:53:55 +05:30
{copiedLink ? <Check className="w-4 h-4 text-accent" aria-hidden="true" /> : <Copy className="w-4 h-4 text-muted" aria-hidden="true" />}
<span>{copiedLink ? 'Link copied' : 'Copy link'}</span>
</button>
</div>
</div>
2026-11-06 10:53:55 +05:30
<div className="pt-2 text-xs text-muted font-body">
{resolveLocalised(app.creditsNote, locale, 'Credits and in-app purchases are specific to this app.')}
</div>
</div>
{/* Right Column: Clean QR Code Card */}
{showQr && qrDataUrl && (
<div className="lg:col-span-5 studio-sheet rounded-3xl p-6 sm:p-8 text-center flex flex-col items-center">
2026-11-06 10:53:55 +05:30
<span className="text-xs text-muted font-body mb-4">Scan with phone camera</span>
<div className="p-4 bg-paper-hi border border-rule rounded-2xl inline-block shadow-sm">
2026-11-06 10:53:55 +05:30
<img
src={qrDataUrl}
alt="Scan QR code to install app"
className="w-44 h-44 object-contain rounded-xl"
2026-11-06 10:53:55 +05:30
/>
</div>
<div className="mt-4 space-y-1 text-xs font-body text-muted">
<p className="font-medium text-ink">Instant mobile handoff</p>
<p>Directs to App Store or Google Play with {bonusCode} applied automatically.</p>
</div>
</div>
)}
</div>
</div>
</section>
);
}