mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-29 18:13:47 +00:00
refactor: replace share modal with auto-copy toast
Remove the full-screen ShareModal dialog that appeared when sharing a gift code. Replace with a bottom toast that automatically copies the share message to clipboard on button press and slides up from the bottom. The toast auto-dismisses after 5 seconds and can be tapped to copy again.
This commit is contained in:
@@ -4246,11 +4246,9 @@
|
|||||||
"devicesShort": "dev.",
|
"devicesShort": "dev.",
|
||||||
"gbShort": "GB",
|
"gbShort": "GB",
|
||||||
"unlimitedTraffic": "Unlimited",
|
"unlimitedTraffic": "Unlimited",
|
||||||
"shareModalTitle": "Share gift",
|
|
||||||
"shareModalDesc": "Send this message to the gift recipient",
|
|
||||||
"shareModalActivateVia": "Activate via bot:",
|
"shareModalActivateVia": "Activate via bot:",
|
||||||
"shareModalActivateViaCabinet": "Or via website:",
|
"shareModalActivateViaCabinet": "Or via website:",
|
||||||
"shareModalCopyAll": "Copy message",
|
"shareToastCopied": "Message copied",
|
||||||
"shareModalCopied": "Copied!"
|
"shareToastTapCopy": "tap to copy again"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4813,11 +4813,9 @@
|
|||||||
"devicesShort_many": "устр.",
|
"devicesShort_many": "устр.",
|
||||||
"gbShort": "ГБ",
|
"gbShort": "ГБ",
|
||||||
"unlimitedTraffic": "Безлимит",
|
"unlimitedTraffic": "Безлимит",
|
||||||
"shareModalTitle": "Поделиться подарком",
|
|
||||||
"shareModalDesc": "Отправьте это сообщение получателю подарка",
|
|
||||||
"shareModalActivateVia": "Активировать через бота:",
|
"shareModalActivateVia": "Активировать через бота:",
|
||||||
"shareModalActivateViaCabinet": "Или через сайт:",
|
"shareModalActivateViaCabinet": "Или через сайт:",
|
||||||
"shareModalCopyAll": "Скопировать сообщение",
|
"shareToastCopied": "Сообщение скопировано",
|
||||||
"shareModalCopied": "Скопировано!"
|
"shareToastTapCopy": "нажмите чтобы скопировать ещё раз"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useMemo, useEffect } from 'react';
|
import { useState, useMemo, useEffect, useCallback, useRef } from 'react';
|
||||||
import { useNavigate, useSearchParams, Link } from 'react-router';
|
import { useNavigate, useSearchParams, Link } from 'react-router';
|
||||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@@ -15,6 +15,7 @@ import type {
|
|||||||
} from '../api/gift';
|
} from '../api/gift';
|
||||||
|
|
||||||
import { cn } from '../lib/utils';
|
import { cn } from '../lib/utils';
|
||||||
|
import { copyToClipboard } from '../utils/clipboard';
|
||||||
import { getApiErrorMessage } from '../utils/api-error';
|
import { getApiErrorMessage } from '../utils/api-error';
|
||||||
import { formatPrice } from '../utils/format';
|
import { formatPrice } from '../utils/format';
|
||||||
|
|
||||||
@@ -58,23 +59,6 @@ function CheckIcon({ className }: { className?: string }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CopyIcon({ className }: { className?: string }) {
|
|
||||||
return (
|
|
||||||
<svg
|
|
||||||
className={className}
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
fill="none"
|
|
||||||
stroke="currentColor"
|
|
||||||
strokeWidth={1.5}
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
>
|
|
||||||
<rect x="9" y="9" width="13" height="13" rx="2" />
|
|
||||||
<path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1" />
|
|
||||||
</svg>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ShareIcon({ className }: { className?: string }) {
|
function ShareIcon({ className }: { className?: string }) {
|
||||||
return (
|
return (
|
||||||
<svg
|
<svg
|
||||||
@@ -969,174 +953,53 @@ function ActivateTabContent({ initialCode }: { initialCode?: string | null }) {
|
|||||||
// Sub-components: My Gifts Tab
|
// Sub-components: My Gifts Tab
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|
||||||
function ShareModal({ gift, onClose }: { gift: SentGift; onClose: () => void }) {
|
function ShareToast({ message, onDismiss }: { message: string; onDismiss: () => void }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [copied, setCopied] = useState(false);
|
const timerRef = useRef<ReturnType<typeof setTimeout>>(undefined);
|
||||||
|
|
||||||
// Escape key + scroll lock
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handler = (e: KeyboardEvent) => {
|
timerRef.current = setTimeout(onDismiss, 5000);
|
||||||
if (e.key === 'Escape') onClose();
|
|
||||||
};
|
|
||||||
document.addEventListener('keydown', handler);
|
|
||||||
document.body.style.overflow = 'hidden';
|
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('keydown', handler);
|
if (timerRef.current) clearTimeout(timerRef.current);
|
||||||
document.body.style.overflow = '';
|
|
||||||
};
|
};
|
||||||
}, [onClose]);
|
}, [onDismiss]);
|
||||||
|
|
||||||
const shortCode = gift.token.slice(0, 12);
|
const handleClick = useCallback(async () => {
|
||||||
const botUsername = import.meta.env.VITE_TELEGRAM_BOT_USERNAME as string | undefined;
|
await copyToClipboard(message);
|
||||||
const botLink = botUsername ? `https://t.me/${botUsername}?start=GIFT_${shortCode}` : null;
|
if (timerRef.current) clearTimeout(timerRef.current);
|
||||||
const cabinetLink = `${window.location.origin}/gift?tab=activate&code=${shortCode}`;
|
timerRef.current = setTimeout(onDismiss, 2000);
|
||||||
|
}, [message, onDismiss]);
|
||||||
const fullMessage = [
|
|
||||||
t('gift.shareText'),
|
|
||||||
'',
|
|
||||||
botLink ? `${t('gift.shareModalActivateVia')} ${botLink}` : null,
|
|
||||||
`${t('gift.shareModalActivateViaCabinet')} ${cabinetLink}`,
|
|
||||||
]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join('\n');
|
|
||||||
|
|
||||||
const handleCopyAll = async () => {
|
|
||||||
try {
|
|
||||||
await navigator.clipboard.writeText(fullMessage);
|
|
||||||
setCopied(true);
|
|
||||||
setTimeout(() => setCopied(false), 2000);
|
|
||||||
} catch {
|
|
||||||
// fallback
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<motion.div
|
<motion.div
|
||||||
initial={{ opacity: 0 }}
|
initial={{ opacity: 0, y: 60 }}
|
||||||
animate={{ opacity: 1 }}
|
animate={{ opacity: 1, y: 0 }}
|
||||||
exit={{ opacity: 0 }}
|
exit={{ opacity: 0, y: 60 }}
|
||||||
transition={{ duration: 0.2 }}
|
transition={{ duration: 0.25, ease: 'easeOut' }}
|
||||||
className="fixed inset-0 z-50 flex items-end justify-center px-4 pb-6 sm:items-center sm:pb-0"
|
className="fixed inset-x-0 bottom-6 z-50 mx-auto w-[calc(100%-2rem)] max-w-md px-1"
|
||||||
onClick={onClose}
|
|
||||||
>
|
>
|
||||||
{/* Backdrop */}
|
<button
|
||||||
<div className="absolute inset-0 backdrop-blur-sm" />
|
type="button"
|
||||||
|
onClick={handleClick}
|
||||||
{/* Modal content */}
|
className="w-full rounded-2xl border border-dark-700/50 bg-dark-900/95 p-4 text-left shadow-2xl shadow-black/40 backdrop-blur-md transition-colors active:bg-dark-800/95"
|
||||||
<motion.div
|
|
||||||
role="dialog"
|
|
||||||
aria-modal="true"
|
|
||||||
aria-labelledby="share-modal-title"
|
|
||||||
initial={{ opacity: 0, y: 40, scale: 0.95 }}
|
|
||||||
animate={{ opacity: 1, y: 0, scale: 1 }}
|
|
||||||
exit={{ opacity: 0, y: 40, scale: 0.95 }}
|
|
||||||
transition={{ duration: 0.25, ease: 'easeOut' }}
|
|
||||||
className="relative w-full max-w-md overflow-hidden rounded-2xl border border-dark-700/50 bg-dark-900 shadow-2xl"
|
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
>
|
>
|
||||||
{/* Header */}
|
<div className="mb-2 flex items-center gap-2">
|
||||||
<div className="flex items-center justify-between border-b border-dark-800/50 px-5 py-4">
|
<CheckIcon className="h-4 w-4 text-success-400" />
|
||||||
<div className="flex items-center gap-3">
|
<span className="text-xs font-bold text-success-400">{t('gift.shareToastCopied')}</span>
|
||||||
<div className="flex h-9 w-9 items-center justify-center rounded-full bg-accent-500/20">
|
<span className="ml-auto text-xs text-dark-500">{t('gift.shareToastTapCopy')}</span>
|
||||||
<ShareIcon className="h-4.5 w-4.5 text-accent-400" />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h3 id="share-modal-title" className="text-base font-bold text-dark-50">
|
|
||||||
{t('gift.shareModalTitle')}
|
|
||||||
</h3>
|
|
||||||
<p className="text-xs text-dark-400">{t('gift.shareModalDesc')}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={onClose}
|
|
||||||
className="flex h-8 w-8 items-center justify-center rounded-lg text-dark-400 transition-colors hover:bg-dark-800 hover:text-dark-200"
|
|
||||||
aria-label={t('common.cancel')}
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
className="h-5 w-5"
|
|
||||||
fill="none"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
stroke="currentColor"
|
|
||||||
strokeWidth={2}
|
|
||||||
>
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
<p className="line-clamp-4 whitespace-pre-line text-xs text-dark-300">{message}</p>
|
||||||
{/* Message preview */}
|
</button>
|
||||||
<div className="px-5 py-4">
|
|
||||||
<div className="rounded-xl border border-dark-700/30 bg-dark-800/40 p-4">
|
|
||||||
<p className="mb-3 text-sm font-medium text-dark-100">{t('gift.shareText')}</p>
|
|
||||||
|
|
||||||
{botLink && (
|
|
||||||
<div className="mb-2">
|
|
||||||
<p className="mb-1 text-xs font-medium text-dark-400">
|
|
||||||
{t('gift.shareModalActivateVia')}
|
|
||||||
</p>
|
|
||||||
<a
|
|
||||||
href={botLink}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="block truncate rounded-lg bg-dark-900/60 px-3 py-2 text-sm text-accent-400 transition-colors hover:bg-dark-900"
|
|
||||||
>
|
|
||||||
{botLink}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<p className="mb-1 text-xs font-medium text-dark-400">
|
|
||||||
{t('gift.shareModalActivateViaCabinet')}
|
|
||||||
</p>
|
|
||||||
<a
|
|
||||||
href={cabinetLink}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="block truncate rounded-lg bg-dark-900/60 px-3 py-2 text-sm text-accent-400 transition-colors hover:bg-dark-900"
|
|
||||||
>
|
|
||||||
{cabinetLink}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Actions */}
|
|
||||||
<div className="border-t border-dark-800/50 px-5 py-4">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={handleCopyAll}
|
|
||||||
className={cn(
|
|
||||||
'flex w-full items-center justify-center gap-2 rounded-xl px-4 py-3.5 text-sm font-bold transition-all duration-200 active:scale-[0.98]',
|
|
||||||
copied
|
|
||||||
? 'bg-success-500/20 text-success-400'
|
|
||||||
: 'bg-accent-500 text-white shadow-lg shadow-accent-500/25 hover:bg-accent-400',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{copied ? (
|
|
||||||
<>
|
|
||||||
<CheckIcon className="h-4 w-4" />
|
|
||||||
{t('gift.shareModalCopied')}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<CopyIcon className="h-4 w-4" />
|
|
||||||
{t('gift.shareModalCopyAll')}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</motion.div>
|
|
||||||
</motion.div>
|
</motion.div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SentGiftCard({ gift }: { gift: SentGift }) {
|
function SentGiftCard({ gift }: { gift: SentGift }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [showShareModal, setShowShareModal] = useState(false);
|
const [showToast, setShowToast] = useState(false);
|
||||||
|
|
||||||
const giftCode = `GIFT-${gift.token.slice(0, 12)}`;
|
const shortCode = gift.token.slice(0, 12);
|
||||||
|
const giftCode = `GIFT-${shortCode}`;
|
||||||
const isActivated = isGiftActivated(gift);
|
const isActivated = isGiftActivated(gift);
|
||||||
const isAvailable = !isActivated && isGiftAvailable(gift.status);
|
const isAvailable = !isActivated && isGiftAvailable(gift.status);
|
||||||
|
|
||||||
@@ -1146,6 +1009,28 @@ function SentGiftCard({ gift }: { gift: SentGift }) {
|
|||||||
? t('gift.statusAvailable')
|
? t('gift.statusAvailable')
|
||||||
: t(getGiftStatusKey(gift.status));
|
: t(getGiftStatusKey(gift.status));
|
||||||
|
|
||||||
|
const buildShareMessage = useCallback(() => {
|
||||||
|
const botUsername = import.meta.env.VITE_TELEGRAM_BOT_USERNAME as string | undefined;
|
||||||
|
const botLink = botUsername ? `https://t.me/${botUsername}?start=GIFT_${shortCode}` : null;
|
||||||
|
const cabinetLink = `${window.location.origin}/gift?tab=activate&code=${shortCode}`;
|
||||||
|
return [
|
||||||
|
t('gift.shareText'),
|
||||||
|
'',
|
||||||
|
botLink ? `${t('gift.shareModalActivateVia')} ${botLink}` : null,
|
||||||
|
`${t('gift.shareModalActivateViaCabinet')} ${cabinetLink}`,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('\n');
|
||||||
|
}, [shortCode, t]);
|
||||||
|
|
||||||
|
const handleShare = useCallback(async () => {
|
||||||
|
const message = buildShareMessage();
|
||||||
|
await copyToClipboard(message);
|
||||||
|
setShowToast(true);
|
||||||
|
}, [buildShareMessage]);
|
||||||
|
|
||||||
|
const handleDismissToast = useCallback(() => setShowToast(false), []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="rounded-2xl border border-dark-800/50 bg-dark-900/50 p-4">
|
<div className="rounded-2xl border border-dark-800/50 bg-dark-900/50 p-4">
|
||||||
{/* Header: tariff name + status badge */}
|
{/* Header: tariff name + status badge */}
|
||||||
@@ -1184,10 +1069,10 @@ function SentGiftCard({ gift }: { gift: SentGift }) {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Share button — opens modal */}
|
{/* Share button — copies message and shows toast */}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setShowShareModal(true)}
|
onClick={handleShare}
|
||||||
className="flex w-full items-center justify-center gap-2 rounded-xl bg-accent-500 px-4 py-3 text-sm font-bold uppercase tracking-wider text-white transition-colors hover:bg-accent-400 active:scale-[0.98]"
|
className="flex w-full items-center justify-center gap-2 rounded-xl bg-accent-500 px-4 py-3 text-sm font-bold uppercase tracking-wider text-white transition-colors hover:bg-accent-400 active:scale-[0.98]"
|
||||||
>
|
>
|
||||||
<ShareIcon className="h-4 w-4" />
|
<ShareIcon className="h-4 w-4" />
|
||||||
@@ -1210,9 +1095,9 @@ function SentGiftCard({ gift }: { gift: SentGift }) {
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Share modal */}
|
{/* Share toast */}
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{showShareModal && <ShareModal gift={gift} onClose={() => setShowShareModal(false)} />}
|
{showToast && <ShareToast message={buildShareMessage()} onDismiss={handleDismissToast} />}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user