Spaces:
Paused
Paused
CBV01 commited on
Commit ·
95243f9
1
Parent(s): 0aefca0
feat: Multi-tier plans (Free/Basic/Standard/Premium/Unlimited), fixed coupon system, plan cards on user side, account limit bypass for Unlimited
Browse files- backend/main.py +29 -15
- frontend/src/app/admin/page.tsx +1 -0
- frontend/src/components/MonetizationOverlay.tsx +250 -121
- frontend/src/components/Sidebar.tsx +1 -0
backend/main.py
CHANGED
|
@@ -81,6 +81,13 @@ PLAN_CONFIGS = {
|
|
| 81 |
"max_daily_keywords": 30,
|
| 82 |
"scrape_limit": 350,
|
| 83 |
"has_premium_access": True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
}
|
| 85 |
}
|
| 86 |
|
|
@@ -629,15 +636,17 @@ async def get_me(user_id: str = Depends(get_current_user_id)):
|
|
| 629 |
async def send_code(req: PhoneLoginRequest, user_id: str = Depends(get_current_user_id)):
|
| 630 |
# Limit check
|
| 631 |
conn = get_db_connection()
|
| 632 |
-
user = conn.execute("SELECT max_accounts FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 633 |
count_row = conn.execute("SELECT COUNT(*) FROM accounts WHERE user_id = ?", (user_id,)).fetchone()
|
| 634 |
if hasattr(conn, "close"): conn.close()
|
| 635 |
|
|
|
|
| 636 |
max_acc = user["max_accounts"] if user else 1
|
| 637 |
current_count = count_row[0] if count_row else 0
|
| 638 |
|
| 639 |
-
if current_count >= max_acc and user_id != "admin_virtual_id":
|
| 640 |
-
|
|
|
|
| 641 |
|
| 642 |
# Fallback to defaults from environment/config
|
| 643 |
api_id = req.api_id or TELEGRAM_API_ID
|
|
@@ -1320,13 +1329,14 @@ async def scrape_keyword_stream(
|
|
| 1320 |
max_keywords = user_row["max_daily_keywords"] or plan_cfg["max_daily_keywords"]
|
| 1321 |
current_keywords = user_row["daily_keyword_count"] or 0
|
| 1322 |
|
| 1323 |
-
if current_keywords >= max_keywords:
|
| 1324 |
if hasattr(conn, "close"): conn.close()
|
| 1325 |
raise HTTPException(status_code=403, detail=f"Daily keyword limit reached ({max_keywords}). Reset at Midnight UTC.")
|
| 1326 |
|
| 1327 |
# Increment keyword use
|
| 1328 |
-
|
| 1329 |
-
|
|
|
|
| 1330 |
|
| 1331 |
# Cap requested limit by allowed limit
|
| 1332 |
limit = min(limit, allowed_limit)
|
|
@@ -1863,11 +1873,12 @@ async def get_user_status(user_id: str = Depends(get_current_user_id)):
|
|
| 1863 |
|
| 1864 |
@app.post("/api/monetization/apply-coupon")
|
| 1865 |
async def apply_coupon(code: str, user_id: str = Depends(get_current_user_id)):
|
|
|
|
| 1866 |
conn = get_db_connection()
|
| 1867 |
try:
|
| 1868 |
-
coupon = conn.execute("SELECT * FROM coupons WHERE code = ? AND is_active = 1", (code,)).fetchone()
|
| 1869 |
if not coupon:
|
| 1870 |
-
raise HTTPException(status_code=400, detail="Invalid or
|
| 1871 |
|
| 1872 |
price = int(coupon["price"])
|
| 1873 |
if price == 0:
|
|
@@ -1881,13 +1892,15 @@ async def apply_coupon(code: str, user_id: str = Depends(get_current_user_id)):
|
|
| 1881 |
WHERE id = ?""",
|
| 1882 |
(cfg["max_accounts"], cfg["scrape_limit"], cfg["max_daily_campaigns"], cfg["max_daily_keywords"], user_id)
|
| 1883 |
)
|
| 1884 |
-
#
|
| 1885 |
-
conn.execute("UPDATE coupons SET is_active = 0 WHERE code = ?", (code,))
|
| 1886 |
if hasattr(conn, "commit"): conn.commit()
|
| 1887 |
return {"status": "success", "message": "Premium plan activated successfully!", "discount": "free"}
|
| 1888 |
else:
|
| 1889 |
-
# Discount code - user still needs to pay 'price'
|
| 1890 |
-
|
|
|
|
|
|
|
| 1891 |
finally:
|
| 1892 |
if hasattr(conn, "close"): conn.close()
|
| 1893 |
|
|
@@ -2161,13 +2174,14 @@ async def create_campaign(req: CampaignRequest, user_id: str = Depends(get_curre
|
|
| 2161 |
max_daily = user_row["max_daily_campaigns"] or plan_cfg["max_daily_campaigns"]
|
| 2162 |
current_daily = user_row["daily_campaign_count"] or 0
|
| 2163 |
|
| 2164 |
-
if current_daily >= max_daily:
|
| 2165 |
if hasattr(conn, "close"): conn.close()
|
| 2166 |
raise HTTPException(status_code=403, detail=f"Daily campaign limit reached ({max_daily}). Upgrade your plan to increase limits.")
|
| 2167 |
|
| 2168 |
# Increment usage
|
| 2169 |
-
|
| 2170 |
-
|
|
|
|
| 2171 |
|
| 2172 |
try:
|
| 2173 |
# The schedule_time sent by the frontend must already be in UTC.
|
|
|
|
| 81 |
"max_daily_keywords": 30,
|
| 82 |
"scrape_limit": 350,
|
| 83 |
"has_premium_access": True
|
| 84 |
+
},
|
| 85 |
+
"unlimited": {
|
| 86 |
+
"max_daily_campaigns": 999999,
|
| 87 |
+
"max_accounts": 99,
|
| 88 |
+
"max_daily_keywords": 999999,
|
| 89 |
+
"scrape_limit": 1000,
|
| 90 |
+
"has_premium_access": True
|
| 91 |
}
|
| 92 |
}
|
| 93 |
|
|
|
|
| 636 |
async def send_code(req: PhoneLoginRequest, user_id: str = Depends(get_current_user_id)):
|
| 637 |
# Limit check
|
| 638 |
conn = get_db_connection()
|
| 639 |
+
user = conn.execute("SELECT max_accounts, plan FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 640 |
count_row = conn.execute("SELECT COUNT(*) FROM accounts WHERE user_id = ?", (user_id,)).fetchone()
|
| 641 |
if hasattr(conn, "close"): conn.close()
|
| 642 |
|
| 643 |
+
plan = user["plan"] if user else "free"
|
| 644 |
max_acc = user["max_accounts"] if user else 1
|
| 645 |
current_count = count_row[0] if count_row else 0
|
| 646 |
|
| 647 |
+
if plan != "unlimited" and current_count >= max_acc and user_id != "admin_virtual_id":
|
| 648 |
+
plan_limits = {"free": 1, "basic": 1, "standard": 2, "premium": 3}
|
| 649 |
+
raise HTTPException(status_code=403, detail=f"Account limit reached ({max_acc}). Upgrade your plan to link more accounts.")
|
| 650 |
|
| 651 |
# Fallback to defaults from environment/config
|
| 652 |
api_id = req.api_id or TELEGRAM_API_ID
|
|
|
|
| 1329 |
max_keywords = user_row["max_daily_keywords"] or plan_cfg["max_daily_keywords"]
|
| 1330 |
current_keywords = user_row["daily_keyword_count"] or 0
|
| 1331 |
|
| 1332 |
+
if current_keywords >= max_keywords and plan != "unlimited":
|
| 1333 |
if hasattr(conn, "close"): conn.close()
|
| 1334 |
raise HTTPException(status_code=403, detail=f"Daily keyword limit reached ({max_keywords}). Reset at Midnight UTC.")
|
| 1335 |
|
| 1336 |
# Increment keyword use
|
| 1337 |
+
if plan != "unlimited":
|
| 1338 |
+
conn.execute("UPDATE users SET daily_keyword_count = daily_keyword_count + 1 WHERE id = ?", (user_id,))
|
| 1339 |
+
if hasattr(conn, "commit"): conn.commit()
|
| 1340 |
|
| 1341 |
# Cap requested limit by allowed limit
|
| 1342 |
limit = min(limit, allowed_limit)
|
|
|
|
| 1873 |
|
| 1874 |
@app.post("/api/monetization/apply-coupon")
|
| 1875 |
async def apply_coupon(code: str, user_id: str = Depends(get_current_user_id)):
|
| 1876 |
+
code = code.strip().upper()
|
| 1877 |
conn = get_db_connection()
|
| 1878 |
try:
|
| 1879 |
+
coupon = conn.execute("SELECT * FROM coupons WHERE UPPER(code) = ? AND is_active = 1", (code,)).fetchone()
|
| 1880 |
if not coupon:
|
| 1881 |
+
raise HTTPException(status_code=400, detail="Invalid or expired coupon code. Please check and try again.")
|
| 1882 |
|
| 1883 |
price = int(coupon["price"])
|
| 1884 |
if price == 0:
|
|
|
|
| 1892 |
WHERE id = ?""",
|
| 1893 |
(cfg["max_accounts"], cfg["scrape_limit"], cfg["max_daily_campaigns"], cfg["max_daily_keywords"], user_id)
|
| 1894 |
)
|
| 1895 |
+
# Deactivate coupon after single use
|
| 1896 |
+
conn.execute("UPDATE coupons SET is_active = 0 WHERE UPPER(code) = ?", (code,))
|
| 1897 |
if hasattr(conn, "commit"): conn.commit()
|
| 1898 |
return {"status": "success", "message": "Premium plan activated successfully!", "discount": "free"}
|
| 1899 |
else:
|
| 1900 |
+
# Discount code - deactivate so it can't be reused, user still needs to pay 'price'
|
| 1901 |
+
conn.execute("UPDATE coupons SET is_active = 0 WHERE UPPER(code) = ?", (code,))
|
| 1902 |
+
if hasattr(conn, "commit"): conn.commit()
|
| 1903 |
+
return {"status": "success", "message": f"Coupon applied! Pay only \u20a6{price:,} instead.", "discount": "partial", "new_price": price}
|
| 1904 |
finally:
|
| 1905 |
if hasattr(conn, "close"): conn.close()
|
| 1906 |
|
|
|
|
| 2174 |
max_daily = user_row["max_daily_campaigns"] or plan_cfg["max_daily_campaigns"]
|
| 2175 |
current_daily = user_row["daily_campaign_count"] or 0
|
| 2176 |
|
| 2177 |
+
if current_daily >= max_daily and plan != "unlimited":
|
| 2178 |
if hasattr(conn, "close"): conn.close()
|
| 2179 |
raise HTTPException(status_code=403, detail=f"Daily campaign limit reached ({max_daily}). Upgrade your plan to increase limits.")
|
| 2180 |
|
| 2181 |
# Increment usage
|
| 2182 |
+
if plan != "unlimited":
|
| 2183 |
+
conn.execute("UPDATE users SET daily_campaign_count = daily_campaign_count + 1 WHERE id = ?", (user_id,))
|
| 2184 |
+
if hasattr(conn, "commit"): conn.commit()
|
| 2185 |
|
| 2186 |
try:
|
| 2187 |
# The schedule_time sent by the frontend must already be in UTC.
|
frontend/src/app/admin/page.tsx
CHANGED
|
@@ -577,6 +577,7 @@ export default function AdminDashboard() {
|
|
| 577 |
<option value="basic">Basic (50c)</option>
|
| 578 |
<option value="standard">Standard (150c)</option>
|
| 579 |
<option value="premium">Premium (300c)</option>
|
|
|
|
| 580 |
</select>
|
| 581 |
</td>
|
| 582 |
<td className="px-6 py-4">
|
|
|
|
| 577 |
<option value="basic">Basic (50c)</option>
|
| 578 |
<option value="standard">Standard (150c)</option>
|
| 579 |
<option value="premium">Premium (300c)</option>
|
| 580 |
+
<option value="unlimited">Unlimited (Admin Only)</option>
|
| 581 |
</select>
|
| 582 |
</td>
|
| 583 |
<td className="px-6 py-4">
|
frontend/src/components/MonetizationOverlay.tsx
CHANGED
|
@@ -2,21 +2,60 @@
|
|
| 2 |
|
| 3 |
import React, { useState, useEffect } from 'react';
|
| 4 |
import { apiFetch } from '@/lib/auth';
|
| 5 |
-
import { Lock, Ticket, CreditCard, CheckCircle2, X, AlertCircle } from 'lucide-react';
|
| 6 |
|
| 7 |
interface MonetizationOverlayProps {
|
| 8 |
children: React.ReactNode;
|
| 9 |
featureName: string;
|
| 10 |
}
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
export const MonetizationOverlay: React.FC<MonetizationOverlayProps> = ({ children, featureName }) => {
|
| 13 |
const [status, setStatus] = useState<any>(null);
|
| 14 |
const [loading, setLoading] = useState(true);
|
|
|
|
| 15 |
const [couponCode, setCouponCode] = useState('');
|
| 16 |
const [applying, setApplying] = useState(false);
|
| 17 |
const [msg, setMsg] = useState({ type: '', text: '' });
|
| 18 |
const [showProofForm, setShowProofForm] = useState(false);
|
| 19 |
-
const [
|
|
|
|
| 20 |
|
| 21 |
const fetchStatus = async () => {
|
| 22 |
try {
|
|
@@ -32,181 +71,271 @@ export const MonetizationOverlay: React.FC<MonetizationOverlayProps> = ({ childr
|
|
| 32 |
}
|
| 33 |
};
|
| 34 |
|
| 35 |
-
useEffect(() => {
|
| 36 |
-
fetchStatus();
|
| 37 |
-
}, []);
|
| 38 |
|
| 39 |
const applyCoupon = async () => {
|
| 40 |
-
if (!couponCode) return;
|
| 41 |
setApplying(true);
|
| 42 |
setMsg({ type: '', text: '' });
|
| 43 |
try {
|
| 44 |
-
const res = await apiFetch(`/api/monetization/apply-coupon?code=${couponCode}`, { method: 'POST' });
|
| 45 |
const data = await res.json();
|
| 46 |
if (res.ok) {
|
| 47 |
if (data.discount === 'free') {
|
| 48 |
-
setMsg({ type: 'success', text:
|
| 49 |
setTimeout(() => window.location.reload(), 2000);
|
| 50 |
} else {
|
|
|
|
| 51 |
setMsg({ type: 'success', text: data.message });
|
| 52 |
-
|
| 53 |
}
|
| 54 |
} else {
|
| 55 |
-
setMsg({ type: 'error', text: data.detail ||
|
| 56 |
}
|
| 57 |
-
} catch
|
| 58 |
-
setMsg({ type: 'error', text:
|
| 59 |
} finally {
|
| 60 |
setApplying(false);
|
| 61 |
}
|
| 62 |
};
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
const submitProof = async () => {
|
| 65 |
-
if (!proof.name || !proof.bank)
|
|
|
|
|
|
|
|
|
|
| 66 |
setApplying(true);
|
| 67 |
try {
|
| 68 |
-
const
|
|
|
|
|
|
|
| 69 |
const res = await apiFetch('/api/monetization/submit-proof', {
|
| 70 |
method: 'POST',
|
| 71 |
-
body: JSON.stringify({ proof_details: proofStr, amount:
|
| 72 |
});
|
| 73 |
if (res.ok) {
|
| 74 |
-
setMsg({ type: 'success', text:
|
| 75 |
setStatus({ ...status, has_proof: true });
|
| 76 |
setShowProofForm(false);
|
|
|
|
|
|
|
|
|
|
| 77 |
}
|
| 78 |
-
} catch
|
| 79 |
-
setMsg({ type: 'error', text:
|
| 80 |
} finally {
|
| 81 |
setApplying(false);
|
| 82 |
}
|
| 83 |
};
|
| 84 |
|
| 85 |
if (loading) return <>{children}</>;
|
| 86 |
-
|
| 87 |
-
const isLocked = status?.plan === 'free';
|
| 88 |
|
| 89 |
return (
|
| 90 |
<div className="relative w-full h-full min-h-[400px]">
|
| 91 |
{children}
|
| 92 |
|
| 93 |
{isLocked && (
|
| 94 |
-
<div className="absolute inset-0 z-50 flex items-center justify-center p-4 overflow-
|
| 95 |
{/* Glass Backdrop */}
|
| 96 |
-
<div className="absolute inset-0 bg-background/
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
<div className="
|
| 100 |
-
|
| 101 |
-
<div className="relative w-full max-w-[400px] bg-card/80 border border-white/10 p-8 rounded-[40px] shadow-2xl flex flex-col items-center text-center space-y-6 animate-in zoom-in-95 duration-500">
|
| 102 |
-
<div className="relative">
|
| 103 |
-
<div className="absolute inset-0 bg-indigo-500 blur-xl opacity-20 animate-pulse" />
|
| 104 |
-
<div className="relative w-16 h-16 rounded-3xl bg-gradient-to-br from-indigo-600 to-indigo-400 flex items-center justify-center text-white shadow-xl">
|
| 105 |
-
<Lock size={28} />
|
| 106 |
-
</div>
|
| 107 |
-
</div>
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
Arkitel <span className="text-indigo-400">Premium Vault</span>
|
| 112 |
</h2>
|
| 113 |
-
<p className="text-foreground/
|
| 114 |
-
|
| 115 |
</p>
|
| 116 |
</div>
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
</div>
|
| 128 |
-
<
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
</div>
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
<input
|
| 150 |
-
type="text"
|
| 151 |
-
placeholder="Voucher..."
|
| 152 |
-
value={couponCode}
|
| 153 |
-
onChange={(e) => setCouponCode(e.target.value.toUpperCase())}
|
| 154 |
-
className="w-full bg-white/5 border border-white/10 rounded-xl pl-9 pr-3 py-3 text-xs font-bold focus:ring-1 focus:ring-indigo-500/50 outline-none"
|
| 155 |
-
/>
|
| 156 |
</div>
|
| 157 |
-
|
| 158 |
-
onClick={applyCoupon}
|
| 159 |
-
disabled={applying || !couponCode}
|
| 160 |
-
className="px-4 rounded-xl bg-white/5 border border-white/5 text-foreground/60 text-xs font-bold hover:bg-indigo-500 hover:text-white transition-all disabled:opacity-30 active:scale-95"
|
| 161 |
-
>
|
| 162 |
-
{applying ? '...' : 'Apply'}
|
| 163 |
-
</button>
|
| 164 |
-
</div>
|
| 165 |
-
</>
|
| 166 |
-
) : (
|
| 167 |
-
<div className="bg-white/5 border border-white/10 p-5 rounded-3xl space-y-4 animate-in slide-in-from-bottom-2 duration-300">
|
| 168 |
-
<div className="flex items-center justify-between px-1">
|
| 169 |
-
<h3 className="font-bold text-xs uppercase tracking-widest text-foreground/40">Proof Submission</h3>
|
| 170 |
-
<button onClick={() => setShowProofForm(false)} className="text-foreground/40 hover:text-foreground"><X size={14} /></button>
|
| 171 |
-
</div>
|
| 172 |
-
<div className="space-y-2">
|
| 173 |
-
<input
|
| 174 |
-
placeholder="Account Name Used"
|
| 175 |
-
className="w-full bg-black/40 border border-white/5 rounded-xl px-4 py-3 text-xs outline-none focus:border-indigo-500/50"
|
| 176 |
-
onChange={(e) => setProof({...proof, name: e.target.value})}
|
| 177 |
-
/>
|
| 178 |
-
<input
|
| 179 |
-
placeholder="Your Bank Name"
|
| 180 |
-
className="w-full bg-black/40 border border-white/5 rounded-xl px-4 py-3 text-xs outline-none focus:border-indigo-500/50"
|
| 181 |
-
onChange={(e) => setProof({...proof, bank: e.target.value})}
|
| 182 |
-
/>
|
| 183 |
-
</div>
|
| 184 |
-
<button
|
| 185 |
-
onClick={submitProof}
|
| 186 |
-
className="w-full bg-emerald-500 hover:bg-emerald-400 text-black font-bold py-3 rounded-xl transition-all text-xs shadow-lg shadow-emerald-500/20 active:scale-95"
|
| 187 |
-
>
|
| 188 |
-
Confirm Deposit
|
| 189 |
-
</button>
|
| 190 |
</div>
|
| 191 |
-
)
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
</div>
|
| 201 |
-
)}
|
| 202 |
|
| 203 |
-
|
| 204 |
-
<div className=
|
| 205 |
-
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
</div>
|
| 208 |
-
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
</div>
|
| 211 |
</div>
|
| 212 |
)}
|
|
|
|
| 2 |
|
| 3 |
import React, { useState, useEffect } from 'react';
|
| 4 |
import { apiFetch } from '@/lib/auth';
|
| 5 |
+
import { Lock, Ticket, CreditCard, CheckCircle2, X, AlertCircle, Zap, Star, Crown } from 'lucide-react';
|
| 6 |
|
| 7 |
interface MonetizationOverlayProps {
|
| 8 |
children: React.ReactNode;
|
| 9 |
featureName: string;
|
| 10 |
}
|
| 11 |
|
| 12 |
+
const PLANS = [
|
| 13 |
+
{
|
| 14 |
+
key: 'basic',
|
| 15 |
+
name: 'Basic',
|
| 16 |
+
price: 2000,
|
| 17 |
+
icon: Zap,
|
| 18 |
+
color: 'from-emerald-600 to-emerald-400',
|
| 19 |
+
glow: 'shadow-emerald-500/20',
|
| 20 |
+
badge: 'text-emerald-400 bg-emerald-500/10 border-emerald-500/30',
|
| 21 |
+
perks: ['50 campaigns / day', '1 Telegram account', '50 leads per search', '10 keyword searches / day'],
|
| 22 |
+
paystackUrl: 'https://paystack.com/pay/arkitel-basic',
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
key: 'standard',
|
| 26 |
+
name: 'Standard',
|
| 27 |
+
price: 3500,
|
| 28 |
+
icon: Star,
|
| 29 |
+
color: 'from-amber-600 to-amber-400',
|
| 30 |
+
glow: 'shadow-amber-500/20',
|
| 31 |
+
badge: 'text-amber-400 bg-amber-500/10 border-amber-500/30',
|
| 32 |
+
perks: ['150 campaigns / day', '2 Telegram accounts', '150 leads per search', '15 keyword searches / day'],
|
| 33 |
+
paystackUrl: 'https://paystack.com/pay/arkitel-standard',
|
| 34 |
+
popular: true,
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
key: 'premium',
|
| 38 |
+
name: 'Premium',
|
| 39 |
+
price: 5000,
|
| 40 |
+
icon: Crown,
|
| 41 |
+
color: 'from-indigo-600 to-indigo-400',
|
| 42 |
+
glow: 'shadow-indigo-500/20',
|
| 43 |
+
badge: 'text-indigo-400 bg-indigo-500/10 border-indigo-500/30',
|
| 44 |
+
perks: ['300 campaigns / day', '3 Telegram accounts', '350 leads per search', '30 keyword searches / day'],
|
| 45 |
+
paystackUrl: 'https://paystack.com/pay/arkitel-premium',
|
| 46 |
+
},
|
| 47 |
+
];
|
| 48 |
+
|
| 49 |
export const MonetizationOverlay: React.FC<MonetizationOverlayProps> = ({ children, featureName }) => {
|
| 50 |
const [status, setStatus] = useState<any>(null);
|
| 51 |
const [loading, setLoading] = useState(true);
|
| 52 |
+
const [selectedPlan, setSelectedPlan] = useState('standard');
|
| 53 |
const [couponCode, setCouponCode] = useState('');
|
| 54 |
const [applying, setApplying] = useState(false);
|
| 55 |
const [msg, setMsg] = useState({ type: '', text: '' });
|
| 56 |
const [showProofForm, setShowProofForm] = useState(false);
|
| 57 |
+
const [appliedDiscount, setAppliedDiscount] = useState<number | null>(null);
|
| 58 |
+
const [proof, setProof] = useState({ name: '', bank: '' });
|
| 59 |
|
| 60 |
const fetchStatus = async () => {
|
| 61 |
try {
|
|
|
|
| 71 |
}
|
| 72 |
};
|
| 73 |
|
| 74 |
+
useEffect(() => { fetchStatus(); }, []);
|
|
|
|
|
|
|
| 75 |
|
| 76 |
const applyCoupon = async () => {
|
| 77 |
+
if (!couponCode.trim()) return;
|
| 78 |
setApplying(true);
|
| 79 |
setMsg({ type: '', text: '' });
|
| 80 |
try {
|
| 81 |
+
const res = await apiFetch(`/api/monetization/apply-coupon?code=${encodeURIComponent(couponCode.trim())}`, { method: 'POST' });
|
| 82 |
const data = await res.json();
|
| 83 |
if (res.ok) {
|
| 84 |
if (data.discount === 'free') {
|
| 85 |
+
setMsg({ type: 'success', text: '🎉 Access Granted! Reloading...' });
|
| 86 |
setTimeout(() => window.location.reload(), 2000);
|
| 87 |
} else {
|
| 88 |
+
setAppliedDiscount(data.new_price);
|
| 89 |
setMsg({ type: 'success', text: data.message });
|
| 90 |
+
setShowProofForm(true);
|
| 91 |
}
|
| 92 |
} else {
|
| 93 |
+
setMsg({ type: 'error', text: data.detail || 'Invalid or expired coupon code.' });
|
| 94 |
}
|
| 95 |
+
} catch {
|
| 96 |
+
setMsg({ type: 'error', text: 'Server error. Please try again.' });
|
| 97 |
} finally {
|
| 98 |
setApplying(false);
|
| 99 |
}
|
| 100 |
};
|
| 101 |
|
| 102 |
+
const handlePayNow = () => {
|
| 103 |
+
const plan = PLANS.find(p => p.key === selectedPlan)!;
|
| 104 |
+
window.open(plan.paystackUrl, '_blank');
|
| 105 |
+
setShowProofForm(true);
|
| 106 |
+
setMsg({ type: '', text: '' });
|
| 107 |
+
};
|
| 108 |
+
|
| 109 |
const submitProof = async () => {
|
| 110 |
+
if (!proof.name.trim() || !proof.bank.trim()) {
|
| 111 |
+
setMsg({ type: 'error', text: 'Please fill in your name and bank name.' });
|
| 112 |
+
return;
|
| 113 |
+
}
|
| 114 |
setApplying(true);
|
| 115 |
try {
|
| 116 |
+
const plan = PLANS.find(p => p.key === selectedPlan)!;
|
| 117 |
+
const finalAmount = appliedDiscount ?? plan.price;
|
| 118 |
+
const proofStr = `[${plan.name}] ${proof.name} | ${proof.bank} | ₦${finalAmount.toLocaleString()}`;
|
| 119 |
const res = await apiFetch('/api/monetization/submit-proof', {
|
| 120 |
method: 'POST',
|
| 121 |
+
body: JSON.stringify({ proof_details: proofStr, amount: finalAmount })
|
| 122 |
});
|
| 123 |
if (res.ok) {
|
| 124 |
+
setMsg({ type: 'success', text: 'Proof submitted! Admin will verify within minutes.' });
|
| 125 |
setStatus({ ...status, has_proof: true });
|
| 126 |
setShowProofForm(false);
|
| 127 |
+
} else {
|
| 128 |
+
const err = await res.json();
|
| 129 |
+
setMsg({ type: 'error', text: err.detail || 'Submission failed.' });
|
| 130 |
}
|
| 131 |
+
} catch {
|
| 132 |
+
setMsg({ type: 'error', text: 'Failed to submit. Please try again.' });
|
| 133 |
} finally {
|
| 134 |
setApplying(false);
|
| 135 |
}
|
| 136 |
};
|
| 137 |
|
| 138 |
if (loading) return <>{children}</>;
|
| 139 |
+
const isLocked = !status || status?.plan === 'free' || !status?.plan;
|
|
|
|
| 140 |
|
| 141 |
return (
|
| 142 |
<div className="relative w-full h-full min-h-[400px]">
|
| 143 |
{children}
|
| 144 |
|
| 145 |
{isLocked && (
|
| 146 |
+
<div className="absolute inset-0 z-50 flex items-center justify-center p-4 overflow-y-auto rounded-[inherit]">
|
| 147 |
{/* Glass Backdrop */}
|
| 148 |
+
<div className="absolute inset-0 bg-background/70 backdrop-blur-xl" />
|
| 149 |
+
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[500px] h-[500px] bg-indigo-500/8 rounded-full blur-[120px] pointer-events-none" />
|
| 150 |
+
|
| 151 |
+
<div className="relative w-full max-w-[480px] my-4 animate-in zoom-in-95 duration-400">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
+
{/* Header */}
|
| 154 |
+
<div className="text-center mb-5">
|
| 155 |
+
<div className="relative inline-flex mb-3">
|
| 156 |
+
<div className="absolute inset-0 bg-indigo-500 blur-2xl opacity-25 animate-pulse rounded-full" />
|
| 157 |
+
<div className="relative w-14 h-14 rounded-2xl bg-gradient-to-br from-indigo-600 to-violet-500 flex items-center justify-center text-white shadow-xl shadow-indigo-500/30">
|
| 158 |
+
<Lock size={24} />
|
| 159 |
+
</div>
|
| 160 |
+
</div>
|
| 161 |
+
<h2 className="text-xl font-black tracking-tight text-white leading-none">
|
| 162 |
Arkitel <span className="text-indigo-400">Premium Vault</span>
|
| 163 |
</h2>
|
| 164 |
+
<p className="text-foreground/35 text-[10px] font-bold uppercase tracking-[0.2em] mt-1">
|
| 165 |
+
{featureName} — Paid Plans Only
|
| 166 |
</p>
|
| 167 |
</div>
|
| 168 |
|
| 169 |
+
{status?.has_proof ? (
|
| 170 |
+
/* === PENDING VERIFICATION STATE === */
|
| 171 |
+
<div className="bg-emerald-500/5 border border-emerald-500/15 p-6 rounded-3xl flex flex-col items-center space-y-3 text-center">
|
| 172 |
+
<div className="w-10 h-10 rounded-full bg-emerald-500/10 flex items-center justify-center text-emerald-400">
|
| 173 |
+
<CheckCircle2 size={20} />
|
| 174 |
+
</div>
|
| 175 |
+
<p className="font-bold text-sm text-emerald-400">Payment Proof Submitted</p>
|
| 176 |
+
<p className="text-[10px] text-foreground/30 max-w-[220px] uppercase tracking-wider leading-relaxed font-bold">
|
| 177 |
+
Your payment is being verified. Access will be granted shortly.
|
| 178 |
+
</p>
|
| 179 |
+
</div>
|
| 180 |
+
) : showProofForm ? (
|
| 181 |
+
/* === PROOF SUBMISSION FORM === */
|
| 182 |
+
<div className="bg-card/80 border border-white/10 p-6 rounded-3xl space-y-4">
|
| 183 |
+
<div className="flex items-center justify-between">
|
| 184 |
+
<h3 className="font-bold text-sm text-white">Confirm Your Payment</h3>
|
| 185 |
+
<button onClick={() => setShowProofForm(false)} className="text-foreground/30 hover:text-foreground transition-colors">
|
| 186 |
+
<X size={16} />
|
| 187 |
+
</button>
|
| 188 |
+
</div>
|
| 189 |
+
<p className="text-[10px] text-foreground/30 leading-relaxed">
|
| 190 |
+
After paying on Paystack, enter the name and bank you used so the admin can verify your payment.
|
| 191 |
+
</p>
|
| 192 |
+
<div className="space-y-2.5">
|
| 193 |
+
<input
|
| 194 |
+
placeholder="Full Name Used on Payment"
|
| 195 |
+
className="w-full bg-white/5 border border-white/10 rounded-xl px-4 py-3 text-xs text-foreground outline-none focus:border-indigo-500/60 placeholder:text-foreground/25 transition-colors"
|
| 196 |
+
value={proof.name}
|
| 197 |
+
onChange={(e) => setProof({ ...proof, name: e.target.value })}
|
| 198 |
+
/>
|
| 199 |
+
<input
|
| 200 |
+
placeholder="Your Bank Name (e.g. GTBank, Opay)"
|
| 201 |
+
className="w-full bg-white/5 border border-white/10 rounded-xl px-4 py-3 text-xs text-foreground outline-none focus:border-indigo-500/60 placeholder:text-foreground/25 transition-colors"
|
| 202 |
+
value={proof.bank}
|
| 203 |
+
onChange={(e) => setProof({ ...proof, bank: e.target.value })}
|
| 204 |
+
/>
|
| 205 |
+
</div>
|
| 206 |
+
{appliedDiscount !== null && (
|
| 207 |
+
<div className="text-center text-xs font-bold text-emerald-400 bg-emerald-500/10 py-2 rounded-xl border border-emerald-500/20">
|
| 208 |
+
✅ Coupon Applied — Amount: ₦{appliedDiscount.toLocaleString()}
|
| 209 |
+
</div>
|
| 210 |
+
)}
|
| 211 |
+
<button
|
| 212 |
+
onClick={submitProof}
|
| 213 |
+
disabled={applying}
|
| 214 |
+
className="w-full bg-indigo-500 hover:bg-indigo-400 disabled:opacity-50 text-white font-bold py-3 rounded-xl transition-all text-sm shadow-lg shadow-indigo-500/20 active:scale-95"
|
| 215 |
+
>
|
| 216 |
+
{applying ? 'Submitting...' : 'Submit Proof of Payment'}
|
| 217 |
+
</button>
|
| 218 |
+
{/* Pay again button */}
|
| 219 |
+
<button
|
| 220 |
+
onClick={handlePayNow}
|
| 221 |
+
className="w-full text-foreground/30 text-[10px] font-bold hover:text-indigo-400 transition-colors py-1"
|
| 222 |
+
>
|
| 223 |
+
Haven't paid yet? Click to Pay
|
| 224 |
+
</button>
|
| 225 |
+
</div>
|
| 226 |
+
) : (
|
| 227 |
+
/* === PLAN SELECTION + COUPON === */
|
| 228 |
+
<div className="space-y-3">
|
| 229 |
+
{/* Plan Cards */}
|
| 230 |
+
<div className="grid grid-cols-3 gap-2">
|
| 231 |
+
{PLANS.map((plan) => {
|
| 232 |
+
const Icon = plan.icon;
|
| 233 |
+
const isSelected = selectedPlan === plan.key;
|
| 234 |
+
return (
|
| 235 |
+
<button
|
| 236 |
+
key={plan.key}
|
| 237 |
+
onClick={() => setSelectedPlan(plan.key)}
|
| 238 |
+
className={`relative flex flex-col items-center p-3 rounded-2xl border transition-all duration-200 text-left
|
| 239 |
+
${isSelected
|
| 240 |
+
? 'bg-white/8 border-white/20 scale-[1.03] shadow-xl'
|
| 241 |
+
: 'bg-white/3 border-white/6 hover:border-white/12 hover:bg-white/5'
|
| 242 |
+
}`}
|
| 243 |
+
>
|
| 244 |
+
{plan.popular && (
|
| 245 |
+
<div className="absolute -top-2 left-1/2 -translate-x-1/2 text-[8px] font-black uppercase tracking-widest bg-amber-500 text-black px-2 py-0.5 rounded-full whitespace-nowrap">
|
| 246 |
+
Popular
|
| 247 |
+
</div>
|
| 248 |
+
)}
|
| 249 |
+
<div className={`w-8 h-8 rounded-xl bg-gradient-to-br ${plan.color} flex items-center justify-center text-white mb-2 shadow-lg ${plan.glow}`}>
|
| 250 |
+
<Icon size={14} />
|
| 251 |
</div>
|
| 252 |
+
<div className="font-black text-[11px] text-white">{plan.name}</div>
|
| 253 |
+
<div className="text-[10px] font-bold text-foreground/40 mt-0.5">₦{plan.price.toLocaleString()}</div>
|
| 254 |
+
{isSelected && (
|
| 255 |
+
<div className="absolute bottom-2 right-2">
|
| 256 |
+
<CheckCircle2 size={10} className="text-white/60" />
|
| 257 |
+
</div>
|
| 258 |
+
)}
|
| 259 |
+
</button>
|
| 260 |
+
);
|
| 261 |
+
})}
|
| 262 |
+
</div>
|
| 263 |
|
| 264 |
+
{/* Selected Plan Perks */}
|
| 265 |
+
{(() => {
|
| 266 |
+
const plan = PLANS.find(p => p.key === selectedPlan)!;
|
| 267 |
+
const Icon = plan.icon;
|
| 268 |
+
return (
|
| 269 |
+
<div className="bg-white/3 border border-white/6 rounded-2xl p-3 space-y-1.5">
|
| 270 |
+
<div className="flex items-center gap-1.5 mb-2">
|
| 271 |
+
<Icon size={11} className="text-white/40" />
|
| 272 |
+
<span className="text-[9px] font-black uppercase tracking-widest text-foreground/30">{plan.name} Includes</span>
|
| 273 |
</div>
|
| 274 |
+
{plan.perks.map((perk) => (
|
| 275 |
+
<div key={perk} className="flex items-center gap-2 text-[10px] text-foreground/50">
|
| 276 |
+
<div className="w-1 h-1 rounded-full bg-foreground/30 flex-shrink-0" />
|
| 277 |
+
{perk}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
</div>
|
| 279 |
+
))}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
</div>
|
| 281 |
+
);
|
| 282 |
+
})()}
|
| 283 |
+
|
| 284 |
+
{/* Pay Button */}
|
| 285 |
+
<button
|
| 286 |
+
onClick={handlePayNow}
|
| 287 |
+
className="w-full bg-indigo-500 hover:bg-indigo-400 text-white font-bold py-3.5 rounded-xl transition-all flex items-center justify-center gap-2 text-sm shadow-lg shadow-indigo-500/25 active:scale-95"
|
| 288 |
+
>
|
| 289 |
+
<CreditCard size={15} />
|
| 290 |
+
Pay ₦{PLANS.find(p => p.key === selectedPlan)?.price.toLocaleString()} via Paystack
|
| 291 |
+
</button>
|
| 292 |
+
|
| 293 |
+
{/* Divider */}
|
| 294 |
+
<div className="flex items-center gap-3">
|
| 295 |
+
<div className="h-px flex-1 bg-white/5" />
|
| 296 |
+
<span className="text-[9px] font-bold text-foreground/20 uppercase tracking-widest">Have a coupon?</span>
|
| 297 |
+
<div className="h-px flex-1 bg-white/5" />
|
| 298 |
</div>
|
|
|
|
| 299 |
|
| 300 |
+
{/* Coupon */}
|
| 301 |
+
<div className="flex gap-2">
|
| 302 |
+
<div className="relative flex-1">
|
| 303 |
+
<Ticket className="absolute left-3 top-1/2 -translate-y-1/2 text-foreground/25" size={13} />
|
| 304 |
+
<input
|
| 305 |
+
type="text"
|
| 306 |
+
placeholder="Enter coupon code..."
|
| 307 |
+
value={couponCode}
|
| 308 |
+
onChange={(e) => { setCouponCode(e.target.value.toUpperCase()); setMsg({ type: '', text: '' }); }}
|
| 309 |
+
onKeyDown={(e) => e.key === 'Enter' && applyCoupon()}
|
| 310 |
+
className="w-full bg-white/5 border border-white/8 rounded-xl pl-9 pr-3 py-2.5 text-[11px] font-bold outline-none focus:border-indigo-500/50 placeholder:text-foreground/20 text-white transition-colors"
|
| 311 |
+
/>
|
| 312 |
+
</div>
|
| 313 |
+
<button
|
| 314 |
+
onClick={applyCoupon}
|
| 315 |
+
disabled={applying || !couponCode.trim()}
|
| 316 |
+
className="px-4 rounded-xl bg-white/5 border border-white/8 text-foreground/50 text-[11px] font-bold hover:bg-indigo-500 hover:text-white hover:border-transparent transition-all disabled:opacity-30 active:scale-95 whitespace-nowrap"
|
| 317 |
+
>
|
| 318 |
+
{applying ? '...' : 'Apply'}
|
| 319 |
+
</button>
|
| 320 |
</div>
|
| 321 |
+
|
| 322 |
+
{/* Feedback Message */}
|
| 323 |
+
{msg.text && (
|
| 324 |
+
<div className={`flex items-center gap-2 p-3 rounded-xl text-[10px] font-bold ${msg.type === 'error' ? 'bg-red-500/10 text-red-400 border border-red-500/15' : 'bg-emerald-500/10 text-emerald-400 border border-emerald-500/15'}`}>
|
| 325 |
+
{msg.type === 'error' ? <AlertCircle size={12} /> : <CheckCircle2 size={12} />}
|
| 326 |
+
{msg.text}
|
| 327 |
+
</div>
|
| 328 |
+
)}
|
| 329 |
+
</div>
|
| 330 |
+
)}
|
| 331 |
+
|
| 332 |
+
{/* Footer Message below proof form too */}
|
| 333 |
+
{msg.text && showProofForm && (
|
| 334 |
+
<div className={`mt-3 flex items-center gap-2 p-3 rounded-xl text-[10px] font-bold ${msg.type === 'error' ? 'bg-red-500/10 text-red-400 border border-red-500/15' : 'bg-emerald-500/10 text-emerald-400 border border-emerald-500/15'}`}>
|
| 335 |
+
{msg.type === 'error' ? <AlertCircle size={12} /> : <CheckCircle2 size={12} />}
|
| 336 |
+
{msg.text}
|
| 337 |
+
</div>
|
| 338 |
+
)}
|
| 339 |
</div>
|
| 340 |
</div>
|
| 341 |
)}
|
frontend/src/components/Sidebar.tsx
CHANGED
|
@@ -228,6 +228,7 @@ export function Sidebar({ children }: { children: React.ReactNode }) {
|
|
| 228 |
<div className="flex items-center justify-between">
|
| 229 |
<div className="text-[10px] text-foreground/30 uppercase tracking-[0.2em] font-bold">System Status</div>
|
| 230 |
<span className={`text-[9px] font-black px-2 py-0.5 rounded-full border border-current uppercase ${
|
|
|
|
| 231 |
status?.plan === 'premium' ? 'text-indigo-400 bg-indigo-500/10' :
|
| 232 |
status?.plan === 'standard' ? 'text-amber-400 bg-amber-500/10' :
|
| 233 |
status?.plan === 'basic' ? 'text-emerald-400 bg-emerald-500/10' :
|
|
|
|
| 228 |
<div className="flex items-center justify-between">
|
| 229 |
<div className="text-[10px] text-foreground/30 uppercase tracking-[0.2em] font-bold">System Status</div>
|
| 230 |
<span className={`text-[9px] font-black px-2 py-0.5 rounded-full border border-current uppercase ${
|
| 231 |
+
status?.plan === 'unlimited' ? 'text-rose-400 bg-rose-500/10' :
|
| 232 |
status?.plan === 'premium' ? 'text-indigo-400 bg-indigo-500/10' :
|
| 233 |
status?.plan === 'standard' ? 'text-amber-400 bg-amber-500/10' :
|
| 234 |
status?.plan === 'basic' ? 'text-emerald-400 bg-emerald-500/10' :
|