Spaces:
Paused
Paused
CBV01 commited on
Commit ·
aa58c7d
1
Parent(s): 7b38420
feat: complete package entitlements enforcement, database telemetry tracking, coupon reversion, and verification desk redesign
Browse files- backend/database.py +29 -1
- backend/main.py +371 -47
- frontend/src/app/admin/page.tsx +337 -56
- frontend/src/app/campaigns/page.tsx +89 -21
- frontend/src/app/templates/page.tsx +17 -3
- frontend/src/components/MonetizationOverlay.tsx +171 -84
- frontend/src/components/Sidebar.tsx +144 -2
- frontend/src/components/SpintaxModal.tsx +41 -13
backend/database.py
CHANGED
|
@@ -440,9 +440,37 @@ def init_db():
|
|
| 440 |
conn.execute("UPDATE plans SET max_daily_keywords = 50, max_templates = 10 WHERE key = 'premium'")
|
| 441 |
conn.execute("UPDATE plans SET max_daily_keywords = 100, max_templates = 999 WHERE key = 'unlimited'")
|
| 442 |
if hasattr(conn, "commit"): conn.commit()
|
| 443 |
-
except Exception
|
| 444 |
pass
|
| 445 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
# Fast path: check if database schema and seed data already exist to avoid 50+ sequential network round-trips
|
| 447 |
try:
|
| 448 |
plans_check = conn.execute("SELECT COUNT(*) FROM plans").fetchone()
|
|
|
|
| 440 |
conn.execute("UPDATE plans SET max_daily_keywords = 50, max_templates = 10 WHERE key = 'premium'")
|
| 441 |
conn.execute("UPDATE plans SET max_daily_keywords = 100, max_templates = 999 WHERE key = 'unlimited'")
|
| 442 |
if hasattr(conn, "commit"): conn.commit()
|
| 443 |
+
except Exception:
|
| 444 |
pass
|
| 445 |
|
| 446 |
+
# Ensure coupon table has new fields: target_plan, duration_hours, max_accounts, max_templates
|
| 447 |
+
for col_name, col_type in [
|
| 448 |
+
("target_plan", "TEXT DEFAULT 'premium'"),
|
| 449 |
+
("duration_hours", "INTEGER DEFAULT 0"),
|
| 450 |
+
("max_accounts", "INTEGER"),
|
| 451 |
+
("max_templates", "INTEGER")
|
| 452 |
+
]:
|
| 453 |
+
try:
|
| 454 |
+
conn.execute(f"ALTER TABLE coupons ADD COLUMN {col_name} {col_type}")
|
| 455 |
+
except Exception:
|
| 456 |
+
pass
|
| 457 |
+
|
| 458 |
+
# Ensure users table has coupon and plan tracking fields:
|
| 459 |
+
for col_name, col_type in [
|
| 460 |
+
("original_plan", "TEXT DEFAULT 'free'"),
|
| 461 |
+
("active_coupon_code", "TEXT"),
|
| 462 |
+
("coupon_expires_at", "TEXT"),
|
| 463 |
+
("max_accounts", "INTEGER"),
|
| 464 |
+
("max_templates", "INTEGER"),
|
| 465 |
+
("max_daily_campaigns", "INTEGER"),
|
| 466 |
+
("max_daily_keywords", "INTEGER"),
|
| 467 |
+
("scrape_limit", "INTEGER")
|
| 468 |
+
]:
|
| 469 |
+
try:
|
| 470 |
+
conn.execute(f"ALTER TABLE users ADD COLUMN {col_name} {col_type}")
|
| 471 |
+
except Exception:
|
| 472 |
+
pass
|
| 473 |
+
|
| 474 |
# Fast path: check if database schema and seed data already exist to avoid 50+ sequential network round-trips
|
| 475 |
try:
|
| 476 |
plans_check = conn.execute("SELECT COUNT(*) FROM plans").fetchone()
|
backend/main.py
CHANGED
|
@@ -3629,11 +3629,30 @@ async def get_coupons_admin(admin_id: str = Depends(get_current_admin)):
|
|
| 3629 |
def _safe(r, k):
|
| 3630 |
try: return r[k]
|
| 3631 |
except: return None
|
| 3632 |
-
return {"coupons": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3633 |
|
| 3634 |
class CouponCreateRequest(BaseModel):
|
| 3635 |
code: str
|
| 3636 |
-
price: int
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3637 |
max_daily_campaigns: Optional[int] = None
|
| 3638 |
max_daily_keywords: Optional[int] = None
|
| 3639 |
scrape_limit: Optional[int] = None
|
|
@@ -3642,10 +3661,12 @@ class CouponCreateRequest(BaseModel):
|
|
| 3642 |
async def create_coupon_admin(req: CouponCreateRequest, admin_id: str = Depends(get_current_admin)):
|
| 3643 |
conn = get_db_connection()
|
| 3644 |
try:
|
|
|
|
|
|
|
| 3645 |
conn.execute(
|
| 3646 |
-
"""INSERT INTO coupons (code, price, max_daily_campaigns, max_daily_keywords, scrape_limit)
|
| 3647 |
-
VALUES (?, ?, ?, ?, ?)""",
|
| 3648 |
-
(req.
|
| 3649 |
)
|
| 3650 |
if hasattr(conn, "commit"): conn.commit()
|
| 3651 |
return {"status": "success"}
|
|
@@ -3654,13 +3675,61 @@ async def create_coupon_admin(req: CouponCreateRequest, admin_id: str = Depends(
|
|
| 3654 |
finally:
|
| 3655 |
if hasattr(conn, "close"): conn.close()
|
| 3656 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3657 |
@app.delete("/api/admin/monetization/coupons/{code}")
|
| 3658 |
async def delete_coupon_admin(code: str, admin_id: str = Depends(get_current_admin)):
|
| 3659 |
conn = get_db_connection()
|
| 3660 |
-
|
| 3661 |
-
|
| 3662 |
-
|
| 3663 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3664 |
|
| 3665 |
# --- User Side Monetization ---
|
| 3666 |
|
|
@@ -3668,11 +3737,13 @@ async def delete_coupon_admin(code: str, admin_id: str = Depends(get_current_adm
|
|
| 3668 |
async def get_user_status(user_id: str = Depends(get_current_user_id)):
|
| 3669 |
if user_id == "admin_virtual_id":
|
| 3670 |
cfg = get_plan_configs()["unlimited"]
|
| 3671 |
-
# Fetch 'unlimited' config
|
| 3672 |
cfg = get_plan_configs().get("unlimited", get_plan_configs()["free"])
|
| 3673 |
return {
|
| 3674 |
"status": "success",
|
| 3675 |
"plan": "unlimited",
|
|
|
|
|
|
|
|
|
|
| 3676 |
"scrape_limit": cfg["scrape_limit"],
|
| 3677 |
"max_accounts": cfg["max_accounts"],
|
| 3678 |
"max_daily_campaigns": cfg["max_daily_campaigns"],
|
|
@@ -3684,45 +3755,96 @@ async def get_user_status(user_id: str = Depends(get_current_user_id)):
|
|
| 3684 |
"email": "admin@arkitel.app",
|
| 3685 |
"country": "Nigeria",
|
| 3686 |
"is_approved": 1,
|
| 3687 |
-
"has_proof": True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3688 |
}
|
| 3689 |
|
| 3690 |
conn = get_db_connection()
|
| 3691 |
try:
|
| 3692 |
row = conn.execute("SELECT * FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 3693 |
-
if row:
|
| 3694 |
-
# Reset daily counts if needed
|
| 3695 |
-
check_and_reset_daily_limits(conn, user_id, row)
|
| 3696 |
-
# Fetch latest count after possible reset
|
| 3697 |
-
row = conn.execute("SELECT * FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 3698 |
-
|
| 3699 |
if not row:
|
| 3700 |
raise HTTPException(status_code=404, detail="User not found")
|
| 3701 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3702 |
t_count = conn.execute("SELECT COUNT(*) FROM templates WHERE user_id = ?", (user_id,)).fetchone()[0]
|
| 3703 |
finally:
|
| 3704 |
if hasattr(conn, "close"): conn.close()
|
| 3705 |
|
| 3706 |
# Tier mapping
|
| 3707 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3708 |
|
| 3709 |
return {
|
| 3710 |
"status": "success",
|
| 3711 |
-
"plan":
|
|
|
|
|
|
|
|
|
|
| 3712 |
"username": row["username"],
|
| 3713 |
"email": row["email"] or f"{row['username']}@arkitel.app",
|
| 3714 |
"country": row["country"] if ("country" in row.keys() and row["country"]) else "Nigeria",
|
| 3715 |
-
"scrape_limit":
|
| 3716 |
-
"max_accounts":
|
| 3717 |
-
"max_daily_campaigns":
|
| 3718 |
"daily_campaign_count": row["daily_campaign_count"] or 0,
|
| 3719 |
-
"max_daily_keywords":
|
| 3720 |
"daily_keyword_count": row["daily_keyword_count"] or 0,
|
| 3721 |
-
"max_templates":
|
| 3722 |
"template_count": t_count,
|
| 3723 |
"is_approved": row["is_approved"],
|
| 3724 |
"has_proof": bool(row["payment_proof"]),
|
| 3725 |
-
"plan_expires_at": row["plan_expires_at"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3726 |
}
|
| 3727 |
|
| 3728 |
@app.post("/api/monetization/apply-coupon")
|
|
@@ -3734,27 +3856,87 @@ async def apply_coupon(code: str, user_id: str = Depends(get_current_user_id)):
|
|
| 3734 |
if not coupon:
|
| 3735 |
raise HTTPException(status_code=400, detail="Invalid or expired coupon code. Please check and try again.")
|
| 3736 |
|
| 3737 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3738 |
if price == 0:
|
| 3739 |
-
# FREE access code - unlock
|
| 3740 |
-
# Set limits to NULL so they fall back to PLAN_CONFIGS
|
| 3741 |
conn.execute(
|
| 3742 |
"""UPDATE users SET
|
| 3743 |
-
|
| 3744 |
-
|
| 3745 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3746 |
WHERE id = ?""",
|
| 3747 |
-
(
|
| 3748 |
)
|
| 3749 |
-
# Deactivate coupon
|
| 3750 |
-
|
|
|
|
| 3751 |
if hasattr(conn, "commit"): conn.commit()
|
| 3752 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3753 |
else:
|
| 3754 |
# Discount code - deactivate so it can't be reused, user still needs to pay 'price'
|
| 3755 |
conn.execute("UPDATE coupons SET is_active = 0 WHERE UPPER(code) = ?", (code,))
|
| 3756 |
if hasattr(conn, "commit"): conn.commit()
|
| 3757 |
-
return {"status": "success", "message": f"Coupon applied! Pay only
|
| 3758 |
finally:
|
| 3759 |
if hasattr(conn, "close"): conn.close()
|
| 3760 |
|
|
@@ -4247,14 +4429,14 @@ async def create_template(req: TemplateRequest, user_id: str = Depends(get_curre
|
|
| 4247 |
conn = get_db_connection()
|
| 4248 |
try:
|
| 4249 |
# Check limits
|
| 4250 |
-
u_row = conn.execute("SELECT plan FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 4251 |
plan = u_row["plan"] if u_row else "free"
|
| 4252 |
plan_cfg = get_plan_configs().get(plan, get_plan_configs()["free"])
|
| 4253 |
-
max_templates = plan_cfg.get("max_templates", 1)
|
| 4254 |
|
| 4255 |
current_count = conn.execute("SELECT COUNT(*) FROM templates WHERE user_id = ?", (user_id,)).fetchone()[0]
|
| 4256 |
if plan != "unlimited" and current_count >= max_templates:
|
| 4257 |
-
raise HTTPException(status_code=403, detail=f"Your
|
| 4258 |
|
| 4259 |
conn.execute("INSERT INTO templates (user_id, name, content, media_url) VALUES (?, ?, ?, ?)", (user_id, req.name, req.content, req.media_url))
|
| 4260 |
if hasattr(conn, "commit"): conn.commit()
|
|
@@ -4473,29 +4655,59 @@ async def create_campaign(req: CampaignRequest, user_id: str = Depends(get_curre
|
|
| 4473 |
|
| 4474 |
if current_daily >= max_daily and plan != "unlimited":
|
| 4475 |
if hasattr(conn, "close"): conn.close()
|
| 4476 |
-
raise HTTPException(status_code=403, detail=f"Daily limit reached ({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4477 |
|
| 4478 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4479 |
|
| 4480 |
try:
|
| 4481 |
now_utc = datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M')
|
| 4482 |
camp_name = req.name or "Broadcast Campaign"
|
| 4483 |
camp_groups = req.groups or []
|
| 4484 |
camp_exclude = req.exclude_groups or []
|
| 4485 |
-
camp_speed = req.speed_mode or "balanced"
|
| 4486 |
-
|
| 4487 |
-
clean_time = req.schedule_time
|
| 4488 |
if 'T' in clean_time:
|
| 4489 |
parts = clean_time.split(':')
|
| 4490 |
if len(parts) > 2:
|
| 4491 |
clean_time = f"{parts[0]}:{parts[1]}"
|
|
|
|
| 4492 |
|
| 4493 |
conn.execute(
|
| 4494 |
"INSERT INTO tasks (user_id, name, phone_number, scheduled_time, message_text, target_groups, status, interval_hours, interval_minutes, total_targets, sent_count, batch_number, failed_groups, exclude_groups, media_url, speed_mode, sweep_status, deleted_groups) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
| 4495 |
(user_id, camp_name, req.phone_number, clean_time, req.message, str(camp_groups), "pending", req.interval_hours or 0, req.interval_minutes or 0, len(camp_groups), 0, 1, "[]", str(camp_exclude), req.media_url, camp_speed, "idle", "[]")
|
| 4496 |
)
|
| 4497 |
if hasattr(conn, "commit"): conn.commit()
|
| 4498 |
-
return {"status": "success", "message": f"Campaign scheduled for {
|
| 4499 |
except Exception as e:
|
| 4500 |
print(f"CAMPAIGNS: Error in create_campaign: {e}")
|
| 4501 |
raise HTTPException(status_code=400, detail=str(e))
|
|
@@ -4918,9 +5130,10 @@ async def suggest_ai_keywords(req: AISuggestRequest, user_id: str = Depends(get_
|
|
| 4918 |
# Enforce tiered keyword limits:
|
| 4919 |
# Free: 5, Basic: 15, Standard: 30, Premium: 50, Unlimited: 100
|
| 4920 |
conn_u = get_db_connection()
|
| 4921 |
-
u_row = conn_u.execute("SELECT plan FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 4922 |
if hasattr(conn_u, "close"): conn_u.close()
|
| 4923 |
user_plan = u_row[0] if u_row and u_row[0] else "free"
|
|
|
|
| 4924 |
|
| 4925 |
KEYWORD_LIMITS = {
|
| 4926 |
"free": 5,
|
|
@@ -4929,7 +5142,7 @@ async def suggest_ai_keywords(req: AISuggestRequest, user_id: str = Depends(get_
|
|
| 4929 |
"premium": 50,
|
| 4930 |
"unlimited": 100
|
| 4931 |
}
|
| 4932 |
-
max_allowed = KEYWORD_LIMITS.get(user_plan, 5)
|
| 4933 |
target_count = min(max_allowed, max(5, req.count or max_allowed))
|
| 4934 |
selected_model = (req.model or "").strip() or "meta-llama/llama-3.3-70b-instruct"
|
| 4935 |
|
|
@@ -5119,6 +5332,16 @@ def format_spintax_layout(text: str) -> str:
|
|
| 5119 |
@app.post("/api/ai/spintax")
|
| 5120 |
async def generate_ai_spintax(req: AISpintaxRequest, user_id: str = Depends(get_current_user_id)):
|
| 5121 |
"""Transforms standard text into natural, anti-ban Spintax using the configured AI model with clean paragraph structure."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5122 |
input_text = (req.text or "").strip()
|
| 5123 |
if not input_text:
|
| 5124 |
raise HTTPException(status_code=400, detail="Text to spintax is required.")
|
|
@@ -6336,6 +6559,107 @@ async def admin_get_vps_health(admin_id: str = Depends(get_current_admin)):
|
|
| 6336 |
health = get_vps_health()
|
| 6337 |
return {**health, "vps_health": health}
|
| 6338 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6339 |
@app.get("/api/admin/stats")
|
| 6340 |
async def admin_get_stats(admin_id: str = Depends(get_current_admin)):
|
| 6341 |
conn = get_db_connection()
|
|
|
|
| 3629 |
def _safe(r, k):
|
| 3630 |
try: return r[k]
|
| 3631 |
except: return None
|
| 3632 |
+
return {"coupons": [
|
| 3633 |
+
dict(
|
| 3634 |
+
id=r["id"],
|
| 3635 |
+
code=r["code"],
|
| 3636 |
+
price=r["price"],
|
| 3637 |
+
is_active=r["is_active"],
|
| 3638 |
+
created_at=r["created_at"],
|
| 3639 |
+
target_plan=_safe(r, "target_plan") or "premium",
|
| 3640 |
+
duration_hours=_safe(r, "duration_hours") or 0,
|
| 3641 |
+
max_accounts=_safe(r, "max_accounts"),
|
| 3642 |
+
max_templates=_safe(r, "max_templates"),
|
| 3643 |
+
max_daily_campaigns=_safe(r, "max_daily_campaigns"),
|
| 3644 |
+
max_daily_keywords=_safe(r, "max_daily_keywords"),
|
| 3645 |
+
scrape_limit=_safe(r, "scrape_limit")
|
| 3646 |
+
) for r in rows
|
| 3647 |
+
]}
|
| 3648 |
|
| 3649 |
class CouponCreateRequest(BaseModel):
|
| 3650 |
code: str
|
| 3651 |
+
price: int = 0
|
| 3652 |
+
target_plan: Optional[str] = "premium"
|
| 3653 |
+
duration_hours: Optional[int] = 0
|
| 3654 |
+
max_accounts: Optional[int] = None
|
| 3655 |
+
max_templates: Optional[int] = None
|
| 3656 |
max_daily_campaigns: Optional[int] = None
|
| 3657 |
max_daily_keywords: Optional[int] = None
|
| 3658 |
scrape_limit: Optional[int] = None
|
|
|
|
| 3661 |
async def create_coupon_admin(req: CouponCreateRequest, admin_id: str = Depends(get_current_admin)):
|
| 3662 |
conn = get_db_connection()
|
| 3663 |
try:
|
| 3664 |
+
clean_code = req.code.strip().upper()
|
| 3665 |
+
target_plan = (req.target_plan or "premium").strip().lower()
|
| 3666 |
conn.execute(
|
| 3667 |
+
"""INSERT INTO coupons (code, price, target_plan, duration_hours, max_accounts, max_templates, max_daily_campaigns, max_daily_keywords, scrape_limit)
|
| 3668 |
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
| 3669 |
+
(clean_code, req.price, target_plan, req.duration_hours or 0, req.max_accounts, req.max_templates, req.max_daily_campaigns, req.max_daily_keywords, req.scrape_limit)
|
| 3670 |
)
|
| 3671 |
if hasattr(conn, "commit"): conn.commit()
|
| 3672 |
return {"status": "success"}
|
|
|
|
| 3675 |
finally:
|
| 3676 |
if hasattr(conn, "close"): conn.close()
|
| 3677 |
|
| 3678 |
+
@app.post("/api/admin/monetization/coupons/{code}/toggle")
|
| 3679 |
+
async def toggle_coupon_admin(code: str, admin_id: str = Depends(get_current_admin)):
|
| 3680 |
+
conn = get_db_connection()
|
| 3681 |
+
try:
|
| 3682 |
+
code_clean = code.strip().upper()
|
| 3683 |
+
c = conn.execute("SELECT is_active FROM coupons WHERE UPPER(code) = ?", (code_clean,)).fetchone()
|
| 3684 |
+
if not c:
|
| 3685 |
+
raise HTTPException(status_code=404, detail="Coupon not found")
|
| 3686 |
+
new_active = 0 if c["is_active"] else 1
|
| 3687 |
+
conn.execute("UPDATE coupons SET is_active = ? WHERE UPPER(code) = ?", (new_active, code_clean))
|
| 3688 |
+
|
| 3689 |
+
# If pausing (deactivating), revert active users back to their original plan immediately!
|
| 3690 |
+
if new_active == 0:
|
| 3691 |
+
conn.execute(
|
| 3692 |
+
"""UPDATE users SET
|
| 3693 |
+
plan = COALESCE(original_plan, 'free'),
|
| 3694 |
+
active_coupon_code = NULL,
|
| 3695 |
+
coupon_expires_at = NULL,
|
| 3696 |
+
max_daily_campaigns = NULL,
|
| 3697 |
+
max_daily_keywords = NULL,
|
| 3698 |
+
scrape_limit = NULL,
|
| 3699 |
+
max_accounts = NULL,
|
| 3700 |
+
max_templates = NULL
|
| 3701 |
+
WHERE UPPER(active_coupon_code) = ?""",
|
| 3702 |
+
(code_clean,)
|
| 3703 |
+
)
|
| 3704 |
+
if hasattr(conn, "commit"): conn.commit()
|
| 3705 |
+
return {"status": "success", "is_active": new_active}
|
| 3706 |
+
finally:
|
| 3707 |
+
if hasattr(conn, "close"): conn.close()
|
| 3708 |
+
|
| 3709 |
@app.delete("/api/admin/monetization/coupons/{code}")
|
| 3710 |
async def delete_coupon_admin(code: str, admin_id: str = Depends(get_current_admin)):
|
| 3711 |
conn = get_db_connection()
|
| 3712 |
+
try:
|
| 3713 |
+
code_clean = code.strip().upper()
|
| 3714 |
+
# Automatically revert all users with this coupon active back to their original baseline plan!
|
| 3715 |
+
conn.execute(
|
| 3716 |
+
"""UPDATE users SET
|
| 3717 |
+
plan = COALESCE(original_plan, 'free'),
|
| 3718 |
+
active_coupon_code = NULL,
|
| 3719 |
+
coupon_expires_at = NULL,
|
| 3720 |
+
max_daily_campaigns = NULL,
|
| 3721 |
+
max_daily_keywords = NULL,
|
| 3722 |
+
scrape_limit = NULL,
|
| 3723 |
+
max_accounts = NULL,
|
| 3724 |
+
max_templates = NULL
|
| 3725 |
+
WHERE UPPER(active_coupon_code) = ?""",
|
| 3726 |
+
(code_clean,)
|
| 3727 |
+
)
|
| 3728 |
+
conn.execute("DELETE FROM coupons WHERE UPPER(code) = ?", (code_clean,))
|
| 3729 |
+
if hasattr(conn, "commit"): conn.commit()
|
| 3730 |
+
return {"status": "success"}
|
| 3731 |
+
finally:
|
| 3732 |
+
if hasattr(conn, "close"): conn.close()
|
| 3733 |
|
| 3734 |
# --- User Side Monetization ---
|
| 3735 |
|
|
|
|
| 3737 |
async def get_user_status(user_id: str = Depends(get_current_user_id)):
|
| 3738 |
if user_id == "admin_virtual_id":
|
| 3739 |
cfg = get_plan_configs()["unlimited"]
|
|
|
|
| 3740 |
cfg = get_plan_configs().get("unlimited", get_plan_configs()["free"])
|
| 3741 |
return {
|
| 3742 |
"status": "success",
|
| 3743 |
"plan": "unlimited",
|
| 3744 |
+
"original_plan": "unlimited",
|
| 3745 |
+
"active_coupon_code": None,
|
| 3746 |
+
"coupon_expires_at": None,
|
| 3747 |
"scrape_limit": cfg["scrape_limit"],
|
| 3748 |
"max_accounts": cfg["max_accounts"],
|
| 3749 |
"max_daily_campaigns": cfg["max_daily_campaigns"],
|
|
|
|
| 3755 |
"email": "admin@arkitel.app",
|
| 3756 |
"country": "Nigeria",
|
| 3757 |
"is_approved": 1,
|
| 3758 |
+
"has_proof": True,
|
| 3759 |
+
"allowed_speeds": ["balanced", "turbo", "stealth", "ultra"],
|
| 3760 |
+
"has_spintax": True,
|
| 3761 |
+
"has_fleet_compare": True,
|
| 3762 |
+
"can_export_csv": True,
|
| 3763 |
+
"ai_keyword_cap": 100
|
| 3764 |
}
|
| 3765 |
|
| 3766 |
conn = get_db_connection()
|
| 3767 |
try:
|
| 3768 |
row = conn.execute("SELECT * FROM users WHERE id = ?", (user_id,)).fetchone()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3769 |
if not row:
|
| 3770 |
raise HTTPException(status_code=404, detail="User not found")
|
| 3771 |
|
| 3772 |
+
# Reset daily counts if needed
|
| 3773 |
+
check_and_reset_daily_limits(conn, user_id, row)
|
| 3774 |
+
|
| 3775 |
+
# Check if active coupon has expired
|
| 3776 |
+
try:
|
| 3777 |
+
exp_str = row["coupon_expires_at"]
|
| 3778 |
+
if exp_str:
|
| 3779 |
+
exp_dt = datetime.fromisoformat(exp_str)
|
| 3780 |
+
if datetime.now(timezone.utc) > exp_dt:
|
| 3781 |
+
revert_p = row["original_plan"] or "free"
|
| 3782 |
+
conn.execute(
|
| 3783 |
+
"""UPDATE users SET
|
| 3784 |
+
plan = ?,
|
| 3785 |
+
active_coupon_code = NULL,
|
| 3786 |
+
coupon_expires_at = NULL,
|
| 3787 |
+
max_daily_campaigns = NULL,
|
| 3788 |
+
max_daily_keywords = NULL,
|
| 3789 |
+
scrape_limit = NULL,
|
| 3790 |
+
max_accounts = NULL,
|
| 3791 |
+
max_templates = NULL
|
| 3792 |
+
WHERE id = ?""",
|
| 3793 |
+
(revert_p, user_id)
|
| 3794 |
+
)
|
| 3795 |
+
if hasattr(conn, "commit"): conn.commit()
|
| 3796 |
+
except Exception as e:
|
| 3797 |
+
pass
|
| 3798 |
+
|
| 3799 |
+
# Fetch latest row after possible reset or coupon revert
|
| 3800 |
+
row = conn.execute("SELECT * FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 3801 |
t_count = conn.execute("SELECT COUNT(*) FROM templates WHERE user_id = ?", (user_id,)).fetchone()[0]
|
| 3802 |
finally:
|
| 3803 |
if hasattr(conn, "close"): conn.close()
|
| 3804 |
|
| 3805 |
# Tier mapping
|
| 3806 |
+
active_plan = row["plan"] or "free"
|
| 3807 |
+
p_cfg = get_plan_configs().get(active_plan, get_plan_configs()["free"])
|
| 3808 |
+
|
| 3809 |
+
allowed_speeds = ["balanced"]
|
| 3810 |
+
if active_plan == "basic":
|
| 3811 |
+
allowed_speeds = ["balanced", "turbo"]
|
| 3812 |
+
elif active_plan == "standard":
|
| 3813 |
+
allowed_speeds = ["balanced", "turbo", "stealth"]
|
| 3814 |
+
elif active_plan in ["premium", "unlimited"]:
|
| 3815 |
+
allowed_speeds = ["balanced", "turbo", "stealth", "ultra"]
|
| 3816 |
+
|
| 3817 |
+
max_camps = row["max_daily_campaigns"] or p_cfg["max_daily_campaigns"]
|
| 3818 |
+
max_kws = row["max_daily_keywords"] or p_cfg["max_daily_keywords"]
|
| 3819 |
+
scrape_lim = row["scrape_limit"] or p_cfg["scrape_limit"]
|
| 3820 |
+
max_accs = row["max_accounts"] or p_cfg["max_accounts"]
|
| 3821 |
+
max_tpls = row["max_templates"] or p_cfg.get("max_templates", 1)
|
| 3822 |
|
| 3823 |
return {
|
| 3824 |
"status": "success",
|
| 3825 |
+
"plan": active_plan,
|
| 3826 |
+
"original_plan": row["original_plan"] or "free",
|
| 3827 |
+
"active_coupon_code": row["active_coupon_code"],
|
| 3828 |
+
"coupon_expires_at": row["coupon_expires_at"],
|
| 3829 |
"username": row["username"],
|
| 3830 |
"email": row["email"] or f"{row['username']}@arkitel.app",
|
| 3831 |
"country": row["country"] if ("country" in row.keys() and row["country"]) else "Nigeria",
|
| 3832 |
+
"scrape_limit": scrape_lim,
|
| 3833 |
+
"max_accounts": max_accs,
|
| 3834 |
+
"max_daily_campaigns": max_camps,
|
| 3835 |
"daily_campaign_count": row["daily_campaign_count"] or 0,
|
| 3836 |
+
"max_daily_keywords": max_kws,
|
| 3837 |
"daily_keyword_count": row["daily_keyword_count"] or 0,
|
| 3838 |
+
"max_templates": max_tpls,
|
| 3839 |
"template_count": t_count,
|
| 3840 |
"is_approved": row["is_approved"],
|
| 3841 |
"has_proof": bool(row["payment_proof"]),
|
| 3842 |
+
"plan_expires_at": row["plan_expires_at"],
|
| 3843 |
+
"allowed_speeds": allowed_speeds,
|
| 3844 |
+
"has_spintax": active_plan != "free",
|
| 3845 |
+
"has_fleet_compare": active_plan != "free",
|
| 3846 |
+
"can_export_csv": True,
|
| 3847 |
+
"ai_keyword_cap": max_kws
|
| 3848 |
}
|
| 3849 |
|
| 3850 |
@app.post("/api/monetization/apply-coupon")
|
|
|
|
| 3856 |
if not coupon:
|
| 3857 |
raise HTTPException(status_code=400, detail="Invalid or expired coupon code. Please check and try again.")
|
| 3858 |
|
| 3859 |
+
user_row = conn.execute("SELECT * FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 3860 |
+
if not user_row:
|
| 3861 |
+
raise HTTPException(status_code=404, detail="User not found")
|
| 3862 |
+
|
| 3863 |
+
orig_plan = "free"
|
| 3864 |
+
try:
|
| 3865 |
+
if user_row["original_plan"]:
|
| 3866 |
+
orig_plan = user_row["original_plan"]
|
| 3867 |
+
elif user_row["plan"] and user_row["plan"] != "premium":
|
| 3868 |
+
orig_plan = user_row["plan"]
|
| 3869 |
+
except Exception:
|
| 3870 |
+
orig_plan = user_row["plan"] or "free"
|
| 3871 |
+
|
| 3872 |
+
price = int(coupon["price"] or 0)
|
| 3873 |
+
target_plan = "premium"
|
| 3874 |
+
try:
|
| 3875 |
+
if coupon["target_plan"]:
|
| 3876 |
+
target_plan = coupon["target_plan"].lower()
|
| 3877 |
+
except Exception:
|
| 3878 |
+
pass
|
| 3879 |
+
|
| 3880 |
+
duration_hours = 0
|
| 3881 |
+
try:
|
| 3882 |
+
if coupon["duration_hours"]:
|
| 3883 |
+
duration_hours = int(coupon["duration_hours"])
|
| 3884 |
+
except Exception:
|
| 3885 |
+
pass
|
| 3886 |
+
|
| 3887 |
+
expires_at_str = None
|
| 3888 |
+
if duration_hours > 0:
|
| 3889 |
+
expires_at = datetime.now(timezone.utc) + timedelta(hours=duration_hours)
|
| 3890 |
+
expires_at_str = expires_at.isoformat()
|
| 3891 |
+
|
| 3892 |
+
def _safe_val(c_row, key):
|
| 3893 |
+
try:
|
| 3894 |
+
v = c_row[key]
|
| 3895 |
+
return int(v) if v is not None and v != "" else None
|
| 3896 |
+
except Exception:
|
| 3897 |
+
return None
|
| 3898 |
+
|
| 3899 |
+
c_camps = _safe_val(coupon, "max_daily_campaigns")
|
| 3900 |
+
c_kws = _safe_val(coupon, "max_daily_keywords")
|
| 3901 |
+
c_scrape = _safe_val(coupon, "scrape_limit")
|
| 3902 |
+
c_accs = _safe_val(coupon, "max_accounts")
|
| 3903 |
+
c_tpls = _safe_val(coupon, "max_templates")
|
| 3904 |
+
|
| 3905 |
if price == 0:
|
| 3906 |
+
# FREE access code - unlock plan immediately with coupon's custom allowances
|
|
|
|
| 3907 |
conn.execute(
|
| 3908 |
"""UPDATE users SET
|
| 3909 |
+
original_plan = COALESCE(original_plan, ?),
|
| 3910 |
+
plan = ?,
|
| 3911 |
+
active_coupon_code = ?,
|
| 3912 |
+
coupon_expires_at = ?,
|
| 3913 |
+
max_daily_campaigns = ?,
|
| 3914 |
+
max_daily_keywords = ?,
|
| 3915 |
+
scrape_limit = ?,
|
| 3916 |
+
max_accounts = ?,
|
| 3917 |
+
max_templates = ?,
|
| 3918 |
+
is_approved = 1
|
| 3919 |
WHERE id = ?""",
|
| 3920 |
+
(orig_plan, target_plan, code, expires_at_str, c_camps, c_kws, c_scrape, c_accs, c_tpls, user_id)
|
| 3921 |
)
|
| 3922 |
+
# Deactivate single-use coupon if duration is 0
|
| 3923 |
+
if duration_hours == 0:
|
| 3924 |
+
conn.execute("UPDATE coupons SET is_active = 0 WHERE UPPER(code) = ?", (code,))
|
| 3925 |
if hasattr(conn, "commit"): conn.commit()
|
| 3926 |
+
|
| 3927 |
+
dur_msg = f" (Access active for {duration_hours} hours)" if duration_hours > 0 else ""
|
| 3928 |
+
return {
|
| 3929 |
+
"status": "success",
|
| 3930 |
+
"message": f"{target_plan.capitalize()} plan privileges activated successfully!{dur_msg}",
|
| 3931 |
+
"discount": "free",
|
| 3932 |
+
"plan": target_plan,
|
| 3933 |
+
"coupon_expires_at": expires_at_str
|
| 3934 |
+
}
|
| 3935 |
else:
|
| 3936 |
# Discount code - deactivate so it can't be reused, user still needs to pay 'price'
|
| 3937 |
conn.execute("UPDATE coupons SET is_active = 0 WHERE UPPER(code) = ?", (code,))
|
| 3938 |
if hasattr(conn, "commit"): conn.commit()
|
| 3939 |
+
return {"status": "success", "message": f"Coupon applied! Pay only ₦{price:,} instead.", "discount": "partial", "new_price": price}
|
| 3940 |
finally:
|
| 3941 |
if hasattr(conn, "close"): conn.close()
|
| 3942 |
|
|
|
|
| 4429 |
conn = get_db_connection()
|
| 4430 |
try:
|
| 4431 |
# Check limits
|
| 4432 |
+
u_row = conn.execute("SELECT plan, max_templates FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 4433 |
plan = u_row["plan"] if u_row else "free"
|
| 4434 |
plan_cfg = get_plan_configs().get(plan, get_plan_configs()["free"])
|
| 4435 |
+
max_templates = (u_row["max_templates"] if u_row and u_row["max_templates"] is not None else None) or plan_cfg.get("max_templates", 1)
|
| 4436 |
|
| 4437 |
current_count = conn.execute("SELECT COUNT(*) FROM templates WHERE user_id = ?", (user_id,)).fetchone()[0]
|
| 4438 |
if plan != "unlimited" and current_count >= max_templates:
|
| 4439 |
+
raise HTTPException(status_code=403, detail=f"Your plan allows a maximum of {max_templates} template(s). Upgrade to save more templates.")
|
| 4440 |
|
| 4441 |
conn.execute("INSERT INTO templates (user_id, name, content, media_url) VALUES (?, ?, ?, ?)", (user_id, req.name, req.content, req.media_url))
|
| 4442 |
if hasattr(conn, "commit"): conn.commit()
|
|
|
|
| 4655 |
|
| 4656 |
if current_daily >= max_daily and plan != "unlimited":
|
| 4657 |
if hasattr(conn, "close"): conn.close()
|
| 4658 |
+
raise HTTPException(status_code=403, detail=f"Daily broadcast limit reached ({current_daily}/{max_daily}). Upgrade your plan to send more campaigns today.")
|
| 4659 |
+
|
| 4660 |
+
# Sender Phone validation
|
| 4661 |
+
if not req.phone_number:
|
| 4662 |
+
if hasattr(conn, "close"): conn.close()
|
| 4663 |
+
raise HTTPException(status_code=400, detail="Please select a sender phone account before deploying.")
|
| 4664 |
+
|
| 4665 |
+
# Speed Mode Plan Gating
|
| 4666 |
+
camp_speed = (req.speed_mode or "balanced").lower()
|
| 4667 |
+
allowed_speeds = ["balanced"]
|
| 4668 |
+
if plan == "basic":
|
| 4669 |
+
allowed_speeds = ["balanced", "turbo"]
|
| 4670 |
+
elif plan == "standard":
|
| 4671 |
+
allowed_speeds = ["balanced", "turbo", "stealth"]
|
| 4672 |
+
elif plan in ["premium", "unlimited"]:
|
| 4673 |
+
allowed_speeds = ["balanced", "turbo", "stealth", "ultra"]
|
| 4674 |
|
| 4675 |
+
if camp_speed not in allowed_speeds:
|
| 4676 |
+
req_plan = "Growth Basic" if camp_speed == "turbo" else ("Pro Standard" if camp_speed == "stealth" else "Enterprise Premium")
|
| 4677 |
+
if hasattr(conn, "close"): conn.close()
|
| 4678 |
+
raise HTTPException(
|
| 4679 |
+
status_code=403,
|
| 4680 |
+
detail=f"The '{camp_speed.capitalize()}' delivery speed is locked on your current plan. Upgrade to {req_plan} or higher to use this speed."
|
| 4681 |
+
)
|
| 4682 |
+
|
| 4683 |
+
# Spintax Gating for Free Tier
|
| 4684 |
+
if plan == "free" and req.message and ("{" in req.message and "|" in req.message and "}" in req.message):
|
| 4685 |
+
if hasattr(conn, "close"): conn.close()
|
| 4686 |
+
raise HTTPException(
|
| 4687 |
+
status_code=403,
|
| 4688 |
+
detail="Dynamic Spintax rotation is a premium feature. Upgrade to Growth Basic or higher to deploy campaigns with Spintax syntax."
|
| 4689 |
+
)
|
| 4690 |
|
| 4691 |
try:
|
| 4692 |
now_utc = datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M')
|
| 4693 |
camp_name = req.name or "Broadcast Campaign"
|
| 4694 |
camp_groups = req.groups or []
|
| 4695 |
camp_exclude = req.exclude_groups or []
|
| 4696 |
+
camp_speed = (req.speed_mode or "balanced").lower()
|
| 4697 |
+
|
| 4698 |
+
clean_time = req.schedule_time or now_utc
|
| 4699 |
if 'T' in clean_time:
|
| 4700 |
parts = clean_time.split(':')
|
| 4701 |
if len(parts) > 2:
|
| 4702 |
clean_time = f"{parts[0]}:{parts[1]}"
|
| 4703 |
+
print(f"CAMPAIGN: New campaign '{camp_name}' | Speed: {camp_speed} | Scheduled(UTC): {clean_time} | Server UTC now: {now_utc}")
|
| 4704 |
|
| 4705 |
conn.execute(
|
| 4706 |
"INSERT INTO tasks (user_id, name, phone_number, scheduled_time, message_text, target_groups, status, interval_hours, interval_minutes, total_targets, sent_count, batch_number, failed_groups, exclude_groups, media_url, speed_mode, sweep_status, deleted_groups) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
| 4707 |
(user_id, camp_name, req.phone_number, clean_time, req.message, str(camp_groups), "pending", req.interval_hours or 0, req.interval_minutes or 0, len(camp_groups), 0, 1, "[]", str(camp_exclude), req.media_url, camp_speed, "idle", "[]")
|
| 4708 |
)
|
| 4709 |
if hasattr(conn, "commit"): conn.commit()
|
| 4710 |
+
return {"status": "success", "message": f"Campaign '{camp_name}' scheduled for {clean_time} UTC with {camp_speed} delivery speed."}
|
| 4711 |
except Exception as e:
|
| 4712 |
print(f"CAMPAIGNS: Error in create_campaign: {e}")
|
| 4713 |
raise HTTPException(status_code=400, detail=str(e))
|
|
|
|
| 5130 |
# Enforce tiered keyword limits:
|
| 5131 |
# Free: 5, Basic: 15, Standard: 30, Premium: 50, Unlimited: 100
|
| 5132 |
conn_u = get_db_connection()
|
| 5133 |
+
u_row = conn_u.execute("SELECT plan, max_daily_keywords FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 5134 |
if hasattr(conn_u, "close"): conn_u.close()
|
| 5135 |
user_plan = u_row[0] if u_row and u_row[0] else "free"
|
| 5136 |
+
custom_keywords_cap = u_row[1] if u_row and len(u_row) > 1 and u_row[1] is not None else None
|
| 5137 |
|
| 5138 |
KEYWORD_LIMITS = {
|
| 5139 |
"free": 5,
|
|
|
|
| 5142 |
"premium": 50,
|
| 5143 |
"unlimited": 100
|
| 5144 |
}
|
| 5145 |
+
max_allowed = int(custom_keywords_cap) if (custom_keywords_cap and int(custom_keywords_cap) > 0) else KEYWORD_LIMITS.get(user_plan, 5)
|
| 5146 |
target_count = min(max_allowed, max(5, req.count or max_allowed))
|
| 5147 |
selected_model = (req.model or "").strip() or "meta-llama/llama-3.3-70b-instruct"
|
| 5148 |
|
|
|
|
| 5332 |
@app.post("/api/ai/spintax")
|
| 5333 |
async def generate_ai_spintax(req: AISpintaxRequest, user_id: str = Depends(get_current_user_id)):
|
| 5334 |
"""Transforms standard text into natural, anti-ban Spintax using the configured AI model with clean paragraph structure."""
|
| 5335 |
+
conn_u = get_db_connection()
|
| 5336 |
+
u_row = conn_u.execute("SELECT plan FROM users WHERE id = ?", (user_id,)).fetchone()
|
| 5337 |
+
if hasattr(conn_u, "close"): conn_u.close()
|
| 5338 |
+
user_plan = u_row[0] if u_row and u_row[0] else "free"
|
| 5339 |
+
if user_plan == 'free':
|
| 5340 |
+
raise HTTPException(
|
| 5341 |
+
status_code=403,
|
| 5342 |
+
detail="Dynamic AI Spintax generation is locked on the Free Starter plan. Please upgrade to Growth Basic or higher to use Spintax."
|
| 5343 |
+
)
|
| 5344 |
+
|
| 5345 |
input_text = (req.text or "").strip()
|
| 5346 |
if not input_text:
|
| 5347 |
raise HTTPException(status_code=400, detail="Text to spintax is required.")
|
|
|
|
| 6559 |
health = get_vps_health()
|
| 6560 |
return {**health, "vps_health": health}
|
| 6561 |
|
| 6562 |
+
@app.get("/api/admin/database-health")
|
| 6563 |
+
async def admin_get_database_health(admin_id: str = Depends(get_current_admin)):
|
| 6564 |
+
"""Provides detailed database telemetry, table row counts, size on disk, and capacity limits."""
|
| 6565 |
+
conn = get_db_connection()
|
| 6566 |
+
try:
|
| 6567 |
+
db_url = os.getenv("DATABASE_URL", "")
|
| 6568 |
+
is_cloud = db_url.startswith("libsql://") or db_url.startswith("https://")
|
| 6569 |
+
|
| 6570 |
+
tables = [
|
| 6571 |
+
"users", "accounts", "tasks", "scraped_groups", "leads",
|
| 6572 |
+
"templates", "coupons", "payments", "payment_requests", "broadcasts"
|
| 6573 |
+
]
|
| 6574 |
+
table_counts = {}
|
| 6575 |
+
total_rows = 0
|
| 6576 |
+
for tbl in tables:
|
| 6577 |
+
try:
|
| 6578 |
+
c = conn.execute(f"SELECT COUNT(*) FROM {tbl}").fetchone()[0]
|
| 6579 |
+
table_counts[tbl] = c
|
| 6580 |
+
total_rows += c
|
| 6581 |
+
except Exception:
|
| 6582 |
+
table_counts[tbl] = 0
|
| 6583 |
+
|
| 6584 |
+
db_size_bytes = 0
|
| 6585 |
+
page_size = 4096
|
| 6586 |
+
page_count = 0
|
| 6587 |
+
freelist_count = 0
|
| 6588 |
+
integrity = "ok"
|
| 6589 |
+
|
| 6590 |
+
local_path = db_url.replace("file:", "") if db_url else "./telegram_app.db"
|
| 6591 |
+
if not is_cloud and os.path.exists(local_path):
|
| 6592 |
+
try:
|
| 6593 |
+
db_size_bytes = os.path.getsize(local_path)
|
| 6594 |
+
except Exception:
|
| 6595 |
+
pass
|
| 6596 |
+
try:
|
| 6597 |
+
prg_ps = conn.execute("PRAGMA page_size").fetchone()
|
| 6598 |
+
if prg_ps: page_size = prg_ps[0]
|
| 6599 |
+
prg_pc = conn.execute("PRAGMA page_count").fetchone()
|
| 6600 |
+
if prg_pc: page_count = prg_pc[0]
|
| 6601 |
+
prg_fc = conn.execute("PRAGMA freelist_count").fetchone()
|
| 6602 |
+
if prg_fc: freelist_count = prg_fc[0]
|
| 6603 |
+
prg_int = conn.execute("PRAGMA integrity_check").fetchone()
|
| 6604 |
+
if prg_int: integrity = str(prg_int[0])
|
| 6605 |
+
except Exception:
|
| 6606 |
+
pass
|
| 6607 |
+
else:
|
| 6608 |
+
db_size_bytes = max(1048576, total_rows * 1024)
|
| 6609 |
+
page_count = db_size_bytes // page_size
|
| 6610 |
+
|
| 6611 |
+
max_storage_bytes = 1024 * 1024 * 1024 # 1 GB
|
| 6612 |
+
used_mb = round(db_size_bytes / (1024 * 1024), 2)
|
| 6613 |
+
max_mb = 1024.0
|
| 6614 |
+
used_percent = min(100.0, round((db_size_bytes / max_storage_bytes) * 100, 2))
|
| 6615 |
+
reclaimable_mb = round((freelist_count * page_size) / (1024 * 1024), 2)
|
| 6616 |
+
|
| 6617 |
+
health_status = "Healthy"
|
| 6618 |
+
if used_percent > 85:
|
| 6619 |
+
health_status = "Critical"
|
| 6620 |
+
elif used_percent > 65:
|
| 6621 |
+
health_status = "Warning"
|
| 6622 |
+
|
| 6623 |
+
return {
|
| 6624 |
+
"status": "success",
|
| 6625 |
+
"engine": "LibSQL Cloud (Turso)" if is_cloud else "SQLite 3 Engine",
|
| 6626 |
+
"is_cloud": is_cloud,
|
| 6627 |
+
"health_status": health_status,
|
| 6628 |
+
"integrity": integrity,
|
| 6629 |
+
"size_bytes": db_size_bytes,
|
| 6630 |
+
"size_mb": used_mb,
|
| 6631 |
+
"max_mb": max_mb,
|
| 6632 |
+
"percent_used": used_percent,
|
| 6633 |
+
"reclaimable_mb": reclaimable_mb,
|
| 6634 |
+
"page_size": page_size,
|
| 6635 |
+
"page_count": page_count,
|
| 6636 |
+
"freelist_count": freelist_count,
|
| 6637 |
+
"total_rows": total_rows,
|
| 6638 |
+
"table_counts": table_counts
|
| 6639 |
+
}
|
| 6640 |
+
except Exception as e:
|
| 6641 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 6642 |
+
finally:
|
| 6643 |
+
if hasattr(conn, "close"): conn.close()
|
| 6644 |
+
|
| 6645 |
+
@app.post("/api/admin/database-optimize")
|
| 6646 |
+
async def admin_optimize_database(admin_id: str = Depends(get_current_admin)):
|
| 6647 |
+
"""Compacts the SQLite database, reclaims fragmented disk pages, and optimizes table indexes."""
|
| 6648 |
+
conn = get_db_connection()
|
| 6649 |
+
try:
|
| 6650 |
+
try:
|
| 6651 |
+
conn.execute("VACUUM")
|
| 6652 |
+
except Exception:
|
| 6653 |
+
pass
|
| 6654 |
+
try:
|
| 6655 |
+
conn.execute("ANALYZE")
|
| 6656 |
+
except Exception:
|
| 6657 |
+
pass
|
| 6658 |
+
if hasattr(conn, "commit"): conn.commit()
|
| 6659 |
+
return {"status": "success", "message": "Database optimized and defragmented successfully."}
|
| 6660 |
+
finally:
|
| 6661 |
+
if hasattr(conn, "close"): conn.close()
|
| 6662 |
+
|
| 6663 |
@app.get("/api/admin/stats")
|
| 6664 |
async def admin_get_stats(admin_id: str = Depends(get_current_admin)):
|
| 6665 |
conn = get_db_connection()
|
frontend/src/app/admin/page.tsx
CHANGED
|
@@ -75,7 +75,19 @@ export default function AdminDashboard() {
|
|
| 75 |
const [coupons, setCoupons] = useState<any[]>([]);
|
| 76 |
const [monetizationUsers, setMonetizationUsers] = useState<any[]>([]);
|
| 77 |
const [loadingMonetization, setLoadingMonetization] = useState(false);
|
| 78 |
-
const [newCoupon, setNewCoupon] = useState({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
const [editingPlan, setEditingPlan] = useState<any>(null);
|
| 80 |
const [viewingTemplate, setViewingTemplate] = useState<any>(null);
|
| 81 |
const [maintenanceLoading, setMaintenanceLoading] = useState<string | null>(null);
|
|
@@ -214,6 +226,7 @@ export default function AdminDashboard() {
|
|
| 214 |
console.error("Critical fetch error in admin dashboard:", err);
|
| 215 |
setErrorMsg(`Connection Error: ${err.message || 'Unknown error'}`);
|
| 216 |
} finally {
|
|
|
|
| 217 |
setLoading(false);
|
| 218 |
}
|
| 219 |
};
|
|
@@ -282,22 +295,24 @@ export default function AdminDashboard() {
|
|
| 282 |
if (res.ok) {
|
| 283 |
const data = await res.json();
|
| 284 |
const healthObj = (data?.vps_health && data.vps_health.cpu) ? data.vps_health : (data?.cpu ? data : (data?.vps_health || data));
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
|
|
|
|
|
|
| 301 |
}
|
| 302 |
} catch (e) {
|
| 303 |
console.error("VPS health fetch error:", e);
|
|
@@ -306,13 +321,51 @@ export default function AdminDashboard() {
|
|
| 306 |
}
|
| 307 |
};
|
| 308 |
|
| 309 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
useEffect(() => {
|
| 311 |
-
if (activeTab === 'overview'
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
}
|
| 317 |
}, [activeTab, vpsAutoRefresh]);
|
| 318 |
|
|
@@ -1340,6 +1393,110 @@ export default function AdminDashboard() {
|
|
| 1340 |
);
|
| 1341 |
})()}
|
| 1342 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1343 |
{/* Per-User Activity Table with Search, Scroll, and Pagination */}
|
| 1344 |
<div className="bg-white/5 border border-white/10 rounded-3xl overflow-hidden shadow-2xl">
|
| 1345 |
<div className="p-6 border-b border-white/10 flex flex-col sm:flex-row sm:items-center justify-between gap-4 bg-white/[0.01]">
|
|
@@ -1764,6 +1921,10 @@ export default function AdminDashboard() {
|
|
| 1764 |
<span className="text-foreground/40 font-bold uppercase tracking-widest">Telegram Accounts</span>
|
| 1765 |
<span className="font-mono text-white">{plan.max_accounts}</span>
|
| 1766 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1767 |
<div className="flex justify-between text-xs">
|
| 1768 |
<span className="text-foreground/40 font-bold uppercase tracking-widest">Scrape Limit</span>
|
| 1769 |
<span className="font-mono text-white">{plan.scrape_limit}</span>
|
|
@@ -1876,6 +2037,32 @@ export default function AdminDashboard() {
|
|
| 1876 |
</div>
|
| 1877 |
</div>
|
| 1878 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1879 |
<button
|
| 1880 |
onClick={async () => {
|
| 1881 |
try {
|
|
@@ -1948,58 +2135,102 @@ export default function AdminDashboard() {
|
|
| 1948 |
<div className="grid grid-cols-1 lg:grid-cols-12 gap-4 items-start">
|
| 1949 |
{/* Left: Input Form Controls (8 Cols) */}
|
| 1950 |
<div className="lg:col-span-8 space-y-2.5">
|
| 1951 |
-
<div className="grid grid-cols-1 sm:grid-cols-
|
| 1952 |
-
<div className="space-y-1">
|
| 1953 |
<label className="text-[10px] font-bold text-foreground/50 uppercase tracking-wider px-1">Coupon Code</label>
|
| 1954 |
<input
|
| 1955 |
type="text"
|
| 1956 |
-
placeholder="e.g.
|
| 1957 |
value={newCoupon.code}
|
| 1958 |
onChange={(e) => setNewCoupon({...newCoupon, code: e.target.value.toUpperCase()})}
|
| 1959 |
-
className="w-full bg-white/5 border border-white/10 rounded-lg px-
|
| 1960 |
/>
|
| 1961 |
</div>
|
| 1962 |
-
<div className="space-y-1">
|
| 1963 |
-
<label className="text-[10px] font-bold text-foreground/50 uppercase tracking-wider px-1">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1964 |
<input
|
| 1965 |
type="number"
|
| 1966 |
placeholder="0"
|
| 1967 |
value={newCoupon.price}
|
| 1968 |
onChange={(e) => setNewCoupon({...newCoupon, price: parseInt(e.target.value) || 0})}
|
| 1969 |
-
className="w-full bg-white/5 border border-white/10 rounded-lg px-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1970 |
/>
|
| 1971 |
</div>
|
| 1972 |
</div>
|
| 1973 |
|
| 1974 |
-
<div className="grid grid-cols-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1975 |
<div className="space-y-1">
|
| 1976 |
-
<label className="text-[9px] font-bold text-foreground/45 uppercase tracking-wider px-1">Max
|
| 1977 |
<input
|
| 1978 |
type="number"
|
| 1979 |
-
placeholder="
|
| 1980 |
value={newCoupon.max_daily_campaigns}
|
| 1981 |
onChange={(e) => setNewCoupon({...newCoupon, max_daily_campaigns: e.target.value})}
|
| 1982 |
-
className="w-full bg-white/5 border border-white/10 rounded-lg px-2
|
| 1983 |
/>
|
| 1984 |
</div>
|
| 1985 |
<div className="space-y-1">
|
| 1986 |
-
<label className="text-[9px] font-bold text-foreground/45 uppercase tracking-wider px-1">Max
|
| 1987 |
<input
|
| 1988 |
type="number"
|
| 1989 |
-
placeholder="
|
| 1990 |
value={newCoupon.max_daily_keywords}
|
| 1991 |
onChange={(e) => setNewCoupon({...newCoupon, max_daily_keywords: e.target.value})}
|
| 1992 |
-
className="w-full bg-white/5 border border-white/10 rounded-lg px-2
|
| 1993 |
/>
|
| 1994 |
</div>
|
| 1995 |
-
<div className="space-y-1">
|
| 1996 |
<label className="text-[9px] font-bold text-foreground/45 uppercase tracking-wider px-1">Scrape Limit</label>
|
| 1997 |
<input
|
| 1998 |
type="number"
|
| 1999 |
-
placeholder="
|
| 2000 |
value={newCoupon.scrape_limit}
|
| 2001 |
onChange={(e) => setNewCoupon({...newCoupon, scrape_limit: e.target.value})}
|
| 2002 |
-
className="w-full bg-white/5 border border-white/10 rounded-lg px-2
|
| 2003 |
/>
|
| 2004 |
</div>
|
| 2005 |
</div>
|
|
@@ -2013,8 +2244,21 @@ export default function AdminDashboard() {
|
|
| 2013 |
});
|
| 2014 |
if (res.ok) {
|
| 2015 |
setSuccessMsg(`Coupon ${newCoupon.code} generated successfully.`);
|
| 2016 |
-
setNewCoupon({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2017 |
fetchMonetizationData();
|
|
|
|
|
|
|
|
|
|
| 2018 |
}
|
| 2019 |
}}
|
| 2020 |
className="w-full py-2 bg-indigo-500 hover:bg-indigo-400 text-white font-bold rounded-lg transition-all shadow-md text-xs uppercase tracking-wider cursor-pointer active:scale-95"
|
|
@@ -2029,23 +2273,60 @@ export default function AdminDashboard() {
|
|
| 2029 |
<span>Active Keys</span>
|
| 2030 |
<span className="font-mono text-indigo-400">{coupons.length}</span>
|
| 2031 |
</h4>
|
| 2032 |
-
<div className="space-y-1.5 max-h-
|
| 2033 |
{coupons.map((c) => (
|
| 2034 |
-
<div key={c.id || c.code} className="
|
| 2035 |
-
<div>
|
| 2036 |
-
<
|
| 2037 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2038 |
</div>
|
| 2039 |
-
<
|
| 2040 |
-
|
| 2041 |
-
|
| 2042 |
-
|
| 2043 |
-
|
| 2044 |
-
className="
|
| 2045 |
-
|
| 2046 |
-
|
| 2047 |
-
|
| 2048 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2049 |
</div>
|
| 2050 |
))}
|
| 2051 |
{coupons.length === 0 && <div className="text-[10px] text-center text-foreground/30 italic py-3">No active coupons issued</div>}
|
|
|
|
| 75 |
const [coupons, setCoupons] = useState<any[]>([]);
|
| 76 |
const [monetizationUsers, setMonetizationUsers] = useState<any[]>([]);
|
| 77 |
const [loadingMonetization, setLoadingMonetization] = useState(false);
|
| 78 |
+
const [newCoupon, setNewCoupon] = useState({
|
| 79 |
+
code: '',
|
| 80 |
+
price: 0,
|
| 81 |
+
target_plan: 'premium',
|
| 82 |
+
duration_hours: 0,
|
| 83 |
+
max_accounts: '',
|
| 84 |
+
max_templates: '',
|
| 85 |
+
max_daily_campaigns: '',
|
| 86 |
+
max_daily_keywords: '',
|
| 87 |
+
scrape_limit: ''
|
| 88 |
+
});
|
| 89 |
+
const [dbHealth, setDbHealth] = useState<any>(null);
|
| 90 |
+
const [dbOptimizing, setDbOptimizing] = useState(false);
|
| 91 |
const [editingPlan, setEditingPlan] = useState<any>(null);
|
| 92 |
const [viewingTemplate, setViewingTemplate] = useState<any>(null);
|
| 93 |
const [maintenanceLoading, setMaintenanceLoading] = useState<string | null>(null);
|
|
|
|
| 226 |
console.error("Critical fetch error in admin dashboard:", err);
|
| 227 |
setErrorMsg(`Connection Error: ${err.message || 'Unknown error'}`);
|
| 228 |
} finally {
|
| 229 |
+
fetchDatabaseHealth();
|
| 230 |
setLoading(false);
|
| 231 |
}
|
| 232 |
};
|
|
|
|
| 295 |
if (res.ok) {
|
| 296 |
const data = await res.json();
|
| 297 |
const healthObj = (data?.vps_health && data.vps_health.cpu) ? data.vps_health : (data?.cpu ? data : (data?.vps_health || data));
|
| 298 |
+
if (healthObj && (healthObj.cpu || healthObj.memory)) {
|
| 299 |
+
setVpsHealth(healthObj);
|
| 300 |
+
const curCpu = Number(healthObj.cpu?.percent ?? 0);
|
| 301 |
+
const curMem = Number(healthObj.memory?.percent ?? 0);
|
| 302 |
+
const now = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
| 303 |
+
setVpsHistory(prev => {
|
| 304 |
+
if (prev.length === 0) {
|
| 305 |
+
return [
|
| 306 |
+
{ time: 'T-40s', cpu: Math.max(2, curCpu - 3), memory: Math.max(5, curMem - 1.2) },
|
| 307 |
+
{ time: 'T-30s', cpu: Math.max(2, curCpu + 2), memory: Math.max(5, curMem - 0.4) },
|
| 308 |
+
{ time: 'T-20s', cpu: Math.max(2, curCpu - 1), memory: Math.max(5, curMem + 0.3) },
|
| 309 |
+
{ time: 'T-10s', cpu: Math.max(2, curCpu + 1), memory: Math.max(5, curMem - 0.1) },
|
| 310 |
+
{ time: now, cpu: curCpu, memory: curMem }
|
| 311 |
+
];
|
| 312 |
+
}
|
| 313 |
+
return [...prev, { time: now, cpu: curCpu, memory: curMem }].slice(-15);
|
| 314 |
+
});
|
| 315 |
+
}
|
| 316 |
}
|
| 317 |
} catch (e) {
|
| 318 |
console.error("VPS health fetch error:", e);
|
|
|
|
| 321 |
}
|
| 322 |
};
|
| 323 |
|
| 324 |
+
const fetchDatabaseHealth = async () => {
|
| 325 |
+
try {
|
| 326 |
+
const res = await apiFetch('/api/admin/database-health');
|
| 327 |
+
if (res.ok) {
|
| 328 |
+
const data = await res.json();
|
| 329 |
+
setDbHealth(data);
|
| 330 |
+
}
|
| 331 |
+
} catch (e) {
|
| 332 |
+
console.error("Database health fetch error:", e);
|
| 333 |
+
}
|
| 334 |
+
};
|
| 335 |
+
|
| 336 |
+
const handleOptimizeDatabase = async () => {
|
| 337 |
+
setDbOptimizing(true);
|
| 338 |
+
try {
|
| 339 |
+
const res = await apiFetch('/api/admin/database-optimize', { method: 'POST' });
|
| 340 |
+
if (res.ok) {
|
| 341 |
+
const data = await res.json();
|
| 342 |
+
setSuccessMsg(data.message || "Database optimized and defragmented successfully.");
|
| 343 |
+
setTimeout(() => setSuccessMsg(''), 5000);
|
| 344 |
+
fetchDatabaseHealth();
|
| 345 |
+
} else {
|
| 346 |
+
const errData = await res.json().catch(() => ({}));
|
| 347 |
+
setErrorMsg(errData.detail || "Database optimization failed.");
|
| 348 |
+
setTimeout(() => setErrorMsg(''), 5000);
|
| 349 |
+
}
|
| 350 |
+
} catch (e: any) {
|
| 351 |
+
setErrorMsg(e.message || "Database optimization request failed");
|
| 352 |
+
setTimeout(() => setErrorMsg(''), 5000);
|
| 353 |
+
} finally {
|
| 354 |
+
setDbOptimizing(false);
|
| 355 |
+
}
|
| 356 |
+
};
|
| 357 |
+
|
| 358 |
+
// Auto-refresh VPS health & Database telemetry every 10s when Overview tab is active
|
| 359 |
useEffect(() => {
|
| 360 |
+
if (activeTab === 'overview') {
|
| 361 |
+
fetchDatabaseHealth();
|
| 362 |
+
if (vpsAutoRefresh) {
|
| 363 |
+
const timer = setInterval(() => {
|
| 364 |
+
fetchVpsHealth();
|
| 365 |
+
fetchDatabaseHealth();
|
| 366 |
+
}, 10000);
|
| 367 |
+
return () => clearInterval(timer);
|
| 368 |
+
}
|
| 369 |
}
|
| 370 |
}, [activeTab, vpsAutoRefresh]);
|
| 371 |
|
|
|
|
| 1393 |
);
|
| 1394 |
})()}
|
| 1395 |
|
| 1396 |
+
{/* Database Engine & Storage Telemetry Card */}
|
| 1397 |
+
<div className="bg-white/5 border border-white/10 rounded-3xl p-6 sm:p-7 shadow-2xl relative overflow-hidden space-y-6">
|
| 1398 |
+
<div className="absolute -right-20 -top-20 w-72 h-72 bg-indigo-500/10 rounded-full blur-3xl pointer-events-none" />
|
| 1399 |
+
|
| 1400 |
+
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 border-b border-white/10 pb-5">
|
| 1401 |
+
<div className="flex items-center gap-3">
|
| 1402 |
+
<div className="p-3 bg-indigo-500/10 border border-indigo-500/20 rounded-2xl text-indigo-400">
|
| 1403 |
+
<Database size={24} />
|
| 1404 |
+
</div>
|
| 1405 |
+
<div>
|
| 1406 |
+
<div className="flex items-center gap-2">
|
| 1407 |
+
<h2 className="text-lg font-bold text-foreground">Database Engine & Storage Telemetry</h2>
|
| 1408 |
+
<span className={`px-2 py-0.5 rounded-full text-[10px] font-mono font-bold uppercase border ${
|
| 1409 |
+
dbHealth?.health_status === 'CRITICAL'
|
| 1410 |
+
? 'bg-red-500/10 text-red-400 border-red-500/30'
|
| 1411 |
+
: dbHealth?.health_status === 'WARNING'
|
| 1412 |
+
? 'bg-amber-500/10 text-amber-400 border-amber-500/30'
|
| 1413 |
+
: 'bg-emerald-500/10 text-emerald-400 border-emerald-500/30'
|
| 1414 |
+
}`}>
|
| 1415 |
+
{dbHealth?.health_status || 'HEALTHY'}
|
| 1416 |
+
</span>
|
| 1417 |
+
</div>
|
| 1418 |
+
<p className="text-xs text-foreground/45 mt-0.5">Live storage footprint, disk quota, integrity index, and fragmentation engine</p>
|
| 1419 |
+
</div>
|
| 1420 |
+
</div>
|
| 1421 |
+
|
| 1422 |
+
<div className="flex items-center gap-2 self-start sm:self-auto">
|
| 1423 |
+
<div className="text-right hidden sm:block mr-2">
|
| 1424 |
+
<div className="text-[10px] text-foreground/40 font-mono">ENGINE</div>
|
| 1425 |
+
<div className="text-xs font-mono font-bold text-foreground/80">{dbHealth?.engine || 'SQLite 3 (Local Core)'}</div>
|
| 1426 |
+
</div>
|
| 1427 |
+
<button
|
| 1428 |
+
onClick={handleOptimizeDatabase}
|
| 1429 |
+
disabled={dbOptimizing}
|
| 1430 |
+
className="px-3.5 py-2 bg-white/5 hover:bg-indigo-500/20 border border-white/10 hover:border-indigo-500/40 text-foreground/80 hover:text-indigo-300 rounded-xl text-xs font-bold transition-all flex items-center gap-2 cursor-pointer disabled:opacity-50"
|
| 1431 |
+
title="Defragment and vacuum free space"
|
| 1432 |
+
>
|
| 1433 |
+
<RefreshCw size={13} className={dbOptimizing ? 'animate-spin text-indigo-400' : ''} />
|
| 1434 |
+
<span>{dbOptimizing ? 'Optimizing...' : 'Optimize & Defrag'}</span>
|
| 1435 |
+
</button>
|
| 1436 |
+
</div>
|
| 1437 |
+
</div>
|
| 1438 |
+
|
| 1439 |
+
{/* Storage Usage Progress Bar & Primary Metrics */}
|
| 1440 |
+
<div className="space-y-3">
|
| 1441 |
+
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 text-xs">
|
| 1442 |
+
<div className="flex items-center gap-2">
|
| 1443 |
+
<span className="font-bold text-foreground/70 uppercase tracking-wider text-[11px]">Storage Allocation:</span>
|
| 1444 |
+
<span className="font-mono font-bold text-indigo-400 text-sm">
|
| 1445 |
+
{dbHealth?.size_mb ?? 0} MB
|
| 1446 |
+
</span>
|
| 1447 |
+
<span className="text-foreground/40 text-xs">/ {dbHealth?.max_mb ?? 1024} MB Quota</span>
|
| 1448 |
+
</div>
|
| 1449 |
+
<div className="flex items-center gap-3 text-xs font-mono">
|
| 1450 |
+
<span className="text-foreground/50">Used: <b className="text-white">{dbHealth?.percent_used ?? 0}%</b></span>
|
| 1451 |
+
<span className="text-foreground/30">•</span>
|
| 1452 |
+
<span className="text-foreground/50">Reclaimable: <b className="text-amber-400">{dbHealth?.reclaimable_mb ?? 0} MB</b></span>
|
| 1453 |
+
<span className="text-foreground/30">•</span>
|
| 1454 |
+
<span className="text-foreground/50">Integrity: <b className="text-emerald-400">{dbHealth?.integrity || 'OK'}</b></span>
|
| 1455 |
+
</div>
|
| 1456 |
+
</div>
|
| 1457 |
+
|
| 1458 |
+
{/* Progress Bar */}
|
| 1459 |
+
<div className="w-full h-3 bg-black/40 rounded-full overflow-hidden p-0.5 border border-white/10">
|
| 1460 |
+
<div
|
| 1461 |
+
className={`h-full rounded-full transition-all duration-700 ${
|
| 1462 |
+
Number(dbHealth?.percent_used ?? 0) > 85
|
| 1463 |
+
? 'bg-gradient-to-r from-red-600 to-red-400 shadow-[0_0_12px_rgba(239,68,68,0.5)]'
|
| 1464 |
+
: Number(dbHealth?.percent_used ?? 0) > 65
|
| 1465 |
+
? 'bg-gradient-to-r from-amber-500 to-amber-300 shadow-[0_0_12px_rgba(245,158,11,0.5)]'
|
| 1466 |
+
: 'bg-gradient-to-r from-indigo-500 via-cyan-400 to-emerald-400 shadow-[0_0_12px_rgba(99,102,241,0.4)]'
|
| 1467 |
+
}`}
|
| 1468 |
+
style={{ width: `${Math.min(100, Math.max(3, Number(dbHealth?.percent_used ?? 1)))}%` }}
|
| 1469 |
+
/>
|
| 1470 |
+
</div>
|
| 1471 |
+
</div>
|
| 1472 |
+
|
| 1473 |
+
{/* Database Table Row Breakdown Grid */}
|
| 1474 |
+
<div className="space-y-2.5">
|
| 1475 |
+
<div className="flex items-center justify-between">
|
| 1476 |
+
<span className="text-[11px] font-bold uppercase tracking-wider text-foreground/40">Active Table Records</span>
|
| 1477 |
+
<span className="text-[11px] font-mono text-foreground/50">Total Rows: <b className="text-white font-bold">{(dbHealth?.total_rows ?? 0).toLocaleString()}</b></span>
|
| 1478 |
+
</div>
|
| 1479 |
+
|
| 1480 |
+
<div className="grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-8 gap-2.5">
|
| 1481 |
+
{[
|
| 1482 |
+
{ label: 'Users', count: dbHealth?.table_counts?.users ?? users.length, color: 'text-indigo-400' },
|
| 1483 |
+
{ label: 'Accounts', count: dbHealth?.table_counts?.accounts ?? stats?.total_accounts ?? 0, color: 'text-cyan-400' },
|
| 1484 |
+
{ label: 'Tasks', count: dbHealth?.table_counts?.tasks ?? stats?.total_tasks ?? 0, color: 'text-emerald-400' },
|
| 1485 |
+
{ label: 'Leads', count: dbHealth?.table_counts?.leads ?? stats?.total_leads ?? 0, color: 'text-amber-400' },
|
| 1486 |
+
{ label: 'Groups', count: dbHealth?.table_counts?.scraped_groups ?? 0, color: 'text-pink-400' },
|
| 1487 |
+
{ label: 'Templates', count: dbHealth?.table_counts?.templates ?? globalTemplates.length, color: 'text-purple-400' },
|
| 1488 |
+
{ label: 'Coupons', count: dbHealth?.table_counts?.coupons ?? coupons.length, color: 'text-rose-400' },
|
| 1489 |
+
{ label: 'Payments', count: dbHealth?.table_counts?.payments ?? 0, color: 'text-teal-400' },
|
| 1490 |
+
].map((t, idx) => (
|
| 1491 |
+
<div key={idx} className="bg-black/20 border border-white/5 rounded-xl p-2.5 flex flex-col justify-between hover:border-white/15 transition-all">
|
| 1492 |
+
<span className="text-[10px] text-foreground/40 font-bold uppercase truncate">{t.label}</span>
|
| 1493 |
+
<span className={`text-sm font-mono font-bold mt-1 ${t.color}`}>{(t.count ?? 0).toLocaleString()}</span>
|
| 1494 |
+
</div>
|
| 1495 |
+
))}
|
| 1496 |
+
</div>
|
| 1497 |
+
</div>
|
| 1498 |
+
</div>
|
| 1499 |
+
|
| 1500 |
{/* Per-User Activity Table with Search, Scroll, and Pagination */}
|
| 1501 |
<div className="bg-white/5 border border-white/10 rounded-3xl overflow-hidden shadow-2xl">
|
| 1502 |
<div className="p-6 border-b border-white/10 flex flex-col sm:flex-row sm:items-center justify-between gap-4 bg-white/[0.01]">
|
|
|
|
| 1921 |
<span className="text-foreground/40 font-bold uppercase tracking-widest">Telegram Accounts</span>
|
| 1922 |
<span className="font-mono text-white">{plan.max_accounts}</span>
|
| 1923 |
</div>
|
| 1924 |
+
<div className="flex justify-between text-xs">
|
| 1925 |
+
<span className="text-foreground/40 font-bold uppercase tracking-widest">AI Keywords / Day</span>
|
| 1926 |
+
<span className="font-mono text-indigo-400 font-bold">{plan.max_daily_keywords ?? (plan.key === 'free' ? 5 : plan.key === 'basic' ? 15 : plan.key === 'standard' ? 30 : plan.key === 'premium' ? 50 : 100)}</span>
|
| 1927 |
+
</div>
|
| 1928 |
<div className="flex justify-between text-xs">
|
| 1929 |
<span className="text-foreground/40 font-bold uppercase tracking-widest">Scrape Limit</span>
|
| 1930 |
<span className="font-mono text-white">{plan.scrape_limit}</span>
|
|
|
|
| 2037 |
</div>
|
| 2038 |
</div>
|
| 2039 |
|
| 2040 |
+
<div className="grid grid-cols-2 gap-4">
|
| 2041 |
+
<div className="space-y-2">
|
| 2042 |
+
<label className="text-xs font-bold text-foreground/30 uppercase tracking-widest">AI Keywords / Day</label>
|
| 2043 |
+
<input
|
| 2044 |
+
type="number"
|
| 2045 |
+
value={editingPlan.max_daily_keywords ?? ''}
|
| 2046 |
+
onChange={(e) => setEditingPlan({...editingPlan, max_daily_keywords: parseInt(e.target.value) || 0})}
|
| 2047 |
+
className="w-full bg-white/5 border border-white/10 rounded-2xl px-5 py-4 text-sm font-bold outline-none focus:border-indigo-500 transition-all font-mono"
|
| 2048 |
+
/>
|
| 2049 |
+
</div>
|
| 2050 |
+
<div className="space-y-2">
|
| 2051 |
+
<label className="text-xs font-bold text-foreground/30 uppercase tracking-widest">Premium Features</label>
|
| 2052 |
+
<div className="flex items-center h-[52px]">
|
| 2053 |
+
<label className="flex items-center gap-3 cursor-pointer">
|
| 2054 |
+
<input
|
| 2055 |
+
type="checkbox"
|
| 2056 |
+
checked={editingPlan.has_premium_access === 1 || editingPlan.has_premium_access === true}
|
| 2057 |
+
onChange={(e) => setEditingPlan({...editingPlan, has_premium_access: e.target.checked})}
|
| 2058 |
+
className="w-5 h-5 rounded text-indigo-600 focus:ring-indigo-500 bg-white/10 border-white/20"
|
| 2059 |
+
/>
|
| 2060 |
+
<span className="text-xs font-semibold text-foreground/70">Enable Premium Features</span>
|
| 2061 |
+
</label>
|
| 2062 |
+
</div>
|
| 2063 |
+
</div>
|
| 2064 |
+
</div>
|
| 2065 |
+
|
| 2066 |
<button
|
| 2067 |
onClick={async () => {
|
| 2068 |
try {
|
|
|
|
| 2135 |
<div className="grid grid-cols-1 lg:grid-cols-12 gap-4 items-start">
|
| 2136 |
{/* Left: Input Form Controls (8 Cols) */}
|
| 2137 |
<div className="lg:col-span-8 space-y-2.5">
|
| 2138 |
+
<div className="grid grid-cols-1 sm:grid-cols-4 gap-2.5">
|
| 2139 |
+
<div className="space-y-1 sm:col-span-1">
|
| 2140 |
<label className="text-[10px] font-bold text-foreground/50 uppercase tracking-wider px-1">Coupon Code</label>
|
| 2141 |
<input
|
| 2142 |
type="text"
|
| 2143 |
+
placeholder="e.g. ARKITEL_VIP"
|
| 2144 |
value={newCoupon.code}
|
| 2145 |
onChange={(e) => setNewCoupon({...newCoupon, code: e.target.value.toUpperCase()})}
|
| 2146 |
+
className="w-full bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-xs font-mono font-bold focus:ring-1 focus:ring-indigo-500/50 outline-none"
|
| 2147 |
/>
|
| 2148 |
</div>
|
| 2149 |
+
<div className="space-y-1 sm:col-span-1">
|
| 2150 |
+
<label className="text-[10px] font-bold text-foreground/50 uppercase tracking-wider px-1">Target Plan</label>
|
| 2151 |
+
<select
|
| 2152 |
+
value={newCoupon.target_plan}
|
| 2153 |
+
onChange={(e) => setNewCoupon({...newCoupon, target_plan: e.target.value})}
|
| 2154 |
+
className="w-full bg-[#111115] border border-white/10 rounded-lg px-2.5 py-1.5 text-xs font-bold text-indigo-300 focus:ring-1 focus:ring-indigo-500/50 outline-none cursor-pointer"
|
| 2155 |
+
>
|
| 2156 |
+
<option value="free">Free Starter</option>
|
| 2157 |
+
<option value="basic">Growth Basic</option>
|
| 2158 |
+
<option value="standard">Pro Standard</option>
|
| 2159 |
+
<option value="premium">Enterprise Premium</option>
|
| 2160 |
+
<option value="unlimited">Owner Unlimited</option>
|
| 2161 |
+
</select>
|
| 2162 |
+
</div>
|
| 2163 |
+
<div className="space-y-1 sm:col-span-1">
|
| 2164 |
+
<label className="text-[10px] font-bold text-foreground/50 uppercase tracking-wider px-1">Price (#) <span className="text-foreground/30 font-normal lowercase">(0=free)</span></label>
|
| 2165 |
<input
|
| 2166 |
type="number"
|
| 2167 |
placeholder="0"
|
| 2168 |
value={newCoupon.price}
|
| 2169 |
onChange={(e) => setNewCoupon({...newCoupon, price: parseInt(e.target.value) || 0})}
|
| 2170 |
+
className="w-full bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-xs font-mono focus:ring-1 focus:ring-indigo-500/50 outline-none"
|
| 2171 |
+
/>
|
| 2172 |
+
</div>
|
| 2173 |
+
<div className="space-y-1 sm:col-span-1">
|
| 2174 |
+
<label className="text-[10px] font-bold text-foreground/50 uppercase tracking-wider px-1">Duration <span className="text-foreground/30 font-normal lowercase">(0=life)</span></label>
|
| 2175 |
+
<input
|
| 2176 |
+
type="number"
|
| 2177 |
+
placeholder="Hours (0 = perm)"
|
| 2178 |
+
value={newCoupon.duration_hours}
|
| 2179 |
+
onChange={(e) => setNewCoupon({...newCoupon, duration_hours: parseInt(e.target.value) || 0})}
|
| 2180 |
+
className="w-full bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-xs font-mono focus:ring-1 focus:ring-indigo-500/50 outline-none"
|
| 2181 |
/>
|
| 2182 |
</div>
|
| 2183 |
</div>
|
| 2184 |
|
| 2185 |
+
<div className="grid grid-cols-2 sm:grid-cols-5 gap-2">
|
| 2186 |
+
<div className="space-y-1">
|
| 2187 |
+
<label className="text-[9px] font-bold text-foreground/45 uppercase tracking-wider px-1">Max Accounts</label>
|
| 2188 |
+
<input
|
| 2189 |
+
type="number"
|
| 2190 |
+
placeholder="Plan Def"
|
| 2191 |
+
value={newCoupon.max_accounts}
|
| 2192 |
+
onChange={(e) => setNewCoupon({...newCoupon, max_accounts: e.target.value})}
|
| 2193 |
+
className="w-full bg-white/5 border border-white/10 rounded-lg px-2 py-1.5 text-xs font-mono focus:ring-1 focus:ring-indigo-500/50 outline-none"
|
| 2194 |
+
/>
|
| 2195 |
+
</div>
|
| 2196 |
+
<div className="space-y-1">
|
| 2197 |
+
<label className="text-[9px] font-bold text-foreground/45 uppercase tracking-wider px-1">Max Templates</label>
|
| 2198 |
+
<input
|
| 2199 |
+
type="number"
|
| 2200 |
+
placeholder="Plan Def"
|
| 2201 |
+
value={newCoupon.max_templates}
|
| 2202 |
+
onChange={(e) => setNewCoupon({...newCoupon, max_templates: e.target.value})}
|
| 2203 |
+
className="w-full bg-white/5 border border-white/10 rounded-lg px-2 py-1.5 text-xs font-mono focus:ring-1 focus:ring-indigo-500/50 outline-none"
|
| 2204 |
+
/>
|
| 2205 |
+
</div>
|
| 2206 |
<div className="space-y-1">
|
| 2207 |
+
<label className="text-[9px] font-bold text-foreground/45 uppercase tracking-wider px-1">Max Campaigns</label>
|
| 2208 |
<input
|
| 2209 |
type="number"
|
| 2210 |
+
placeholder="Plan Def"
|
| 2211 |
value={newCoupon.max_daily_campaigns}
|
| 2212 |
onChange={(e) => setNewCoupon({...newCoupon, max_daily_campaigns: e.target.value})}
|
| 2213 |
+
className="w-full bg-white/5 border border-white/10 rounded-lg px-2 py-1.5 text-xs font-mono focus:ring-1 focus:ring-indigo-500/50 outline-none"
|
| 2214 |
/>
|
| 2215 |
</div>
|
| 2216 |
<div className="space-y-1">
|
| 2217 |
+
<label className="text-[9px] font-bold text-foreground/45 uppercase tracking-wider px-1">Max Keywords</label>
|
| 2218 |
<input
|
| 2219 |
type="number"
|
| 2220 |
+
placeholder="Plan Def"
|
| 2221 |
value={newCoupon.max_daily_keywords}
|
| 2222 |
onChange={(e) => setNewCoupon({...newCoupon, max_daily_keywords: e.target.value})}
|
| 2223 |
+
className="w-full bg-white/5 border border-white/10 rounded-lg px-2 py-1.5 text-xs font-mono focus:ring-1 focus:ring-indigo-500/50 outline-none"
|
| 2224 |
/>
|
| 2225 |
</div>
|
| 2226 |
+
<div className="space-y-1 col-span-2 sm:col-span-1">
|
| 2227 |
<label className="text-[9px] font-bold text-foreground/45 uppercase tracking-wider px-1">Scrape Limit</label>
|
| 2228 |
<input
|
| 2229 |
type="number"
|
| 2230 |
+
placeholder="Plan Def"
|
| 2231 |
value={newCoupon.scrape_limit}
|
| 2232 |
onChange={(e) => setNewCoupon({...newCoupon, scrape_limit: e.target.value})}
|
| 2233 |
+
className="w-full bg-white/5 border border-white/10 rounded-lg px-2 py-1.5 text-xs font-mono focus:ring-1 focus:ring-indigo-500/50 outline-none"
|
| 2234 |
/>
|
| 2235 |
</div>
|
| 2236 |
</div>
|
|
|
|
| 2244 |
});
|
| 2245 |
if (res.ok) {
|
| 2246 |
setSuccessMsg(`Coupon ${newCoupon.code} generated successfully.`);
|
| 2247 |
+
setNewCoupon({
|
| 2248 |
+
code: '',
|
| 2249 |
+
price: 0,
|
| 2250 |
+
target_plan: 'premium',
|
| 2251 |
+
duration_hours: 0,
|
| 2252 |
+
max_accounts: '',
|
| 2253 |
+
max_templates: '',
|
| 2254 |
+
max_daily_campaigns: '',
|
| 2255 |
+
max_daily_keywords: '',
|
| 2256 |
+
scrape_limit: ''
|
| 2257 |
+
});
|
| 2258 |
fetchMonetizationData();
|
| 2259 |
+
} else {
|
| 2260 |
+
const err = await res.json().catch(() => ({}));
|
| 2261 |
+
setErrorMsg(err.detail || "Failed to create coupon");
|
| 2262 |
}
|
| 2263 |
}}
|
| 2264 |
className="w-full py-2 bg-indigo-500 hover:bg-indigo-400 text-white font-bold rounded-lg transition-all shadow-md text-xs uppercase tracking-wider cursor-pointer active:scale-95"
|
|
|
|
| 2273 |
<span>Active Keys</span>
|
| 2274 |
<span className="font-mono text-indigo-400">{coupons.length}</span>
|
| 2275 |
</h4>
|
| 2276 |
+
<div className="space-y-1.5 max-h-48 overflow-y-auto custom-scrollbar pr-1">
|
| 2277 |
{coupons.map((c) => (
|
| 2278 |
+
<div key={c.id || c.code} className="p-2 bg-white/5 rounded-lg border border-white/5 text-xs space-y-1">
|
| 2279 |
+
<div className="flex items-center justify-between">
|
| 2280 |
+
<div className="flex items-center gap-1.5">
|
| 2281 |
+
<span className="font-mono font-bold text-indigo-400 text-xs">{c.code}</span>
|
| 2282 |
+
<span className="px-1.5 py-0.2 rounded text-[9px] font-bold uppercase bg-indigo-500/20 text-indigo-300 border border-indigo-500/30">
|
| 2283 |
+
{c.target_plan || 'premium'}
|
| 2284 |
+
</span>
|
| 2285 |
+
{c.is_active === 0 && (
|
| 2286 |
+
<span className="px-1 py-0.2 rounded text-[8px] font-bold uppercase bg-amber-500/20 text-amber-300 border border-amber-500/30">
|
| 2287 |
+
PAUSED
|
| 2288 |
+
</span>
|
| 2289 |
+
)}
|
| 2290 |
+
</div>
|
| 2291 |
+
<div className="flex items-center gap-1">
|
| 2292 |
+
<button
|
| 2293 |
+
onClick={async () => {
|
| 2294 |
+
await apiFetch(`/api/admin/monetization/coupons/${c.code}/toggle`, { method: 'POST' });
|
| 2295 |
+
fetchMonetizationData();
|
| 2296 |
+
}}
|
| 2297 |
+
className="p-1 hover:bg-white/10 text-foreground/50 hover:text-white rounded transition-all cursor-pointer"
|
| 2298 |
+
title={c.is_active === 0 ? "Activate Coupon" : "Pause Coupon (reverts active users to base plan)"}
|
| 2299 |
+
>
|
| 2300 |
+
{c.is_active === 0 ? <Play size={12} className="text-emerald-400" /> : <Pause size={12} className="text-amber-400" />}
|
| 2301 |
+
</button>
|
| 2302 |
+
<button
|
| 2303 |
+
onClick={async () => {
|
| 2304 |
+
if (!confirm(`Delete coupon ${c.code}? Any user currently on this coupon will revert to their base plan.`)) return;
|
| 2305 |
+
await apiFetch(`/api/admin/monetization/coupons/${c.code}`, { method: 'DELETE' });
|
| 2306 |
+
fetchMonetizationData();
|
| 2307 |
+
}}
|
| 2308 |
+
className="p-1 hover:bg-red-500/10 text-red-500/40 hover:text-red-500 rounded transition-all cursor-pointer"
|
| 2309 |
+
title="Revoke & Delete Coupon"
|
| 2310 |
+
>
|
| 2311 |
+
<Trash2 size={12} />
|
| 2312 |
+
</button>
|
| 2313 |
+
</div>
|
| 2314 |
</div>
|
| 2315 |
+
<div className="flex items-center justify-between text-[9px] text-foreground/45 font-mono">
|
| 2316 |
+
<span>#{c.price?.toLocaleString?.() ?? 0} • {Number(c.duration_hours) > 0 ? `${c.duration_hours}h trial` : 'Perpetual'}</span>
|
| 2317 |
+
<span>{c.claimed_by ? <b className="text-emerald-400">Claimed: {c.claimed_by}</b> : 'Available'}</span>
|
| 2318 |
+
</div>
|
| 2319 |
+
{(c.max_accounts || c.max_templates || c.max_daily_campaigns || c.max_daily_keywords || c.scrape_limit) && (
|
| 2320 |
+
<div className="text-[8px] font-mono text-indigo-300/70 truncate">
|
| 2321 |
+
Caps: {[
|
| 2322 |
+
c.max_accounts ? `Accts:${c.max_accounts}` : null,
|
| 2323 |
+
c.max_templates ? `Tmpl:${c.max_templates}` : null,
|
| 2324 |
+
c.max_daily_campaigns ? `Camp:${c.max_daily_campaigns}` : null,
|
| 2325 |
+
c.max_daily_keywords ? `Key:${c.max_daily_keywords}` : null,
|
| 2326 |
+
c.scrape_limit ? `Scrape:${c.scrape_limit}` : null,
|
| 2327 |
+
].filter(Boolean).join(' | ')}
|
| 2328 |
+
</div>
|
| 2329 |
+
)}
|
| 2330 |
</div>
|
| 2331 |
))}
|
| 2332 |
{coupons.length === 0 && <div className="text-[10px] text-center text-foreground/30 italic py-3">No active coupons issued</div>}
|
frontend/src/app/campaigns/page.tsx
CHANGED
|
@@ -439,16 +439,49 @@ export default function CampaignsPage() {
|
|
| 439 |
|
| 440 |
const handleSubmit = async (e: React.FormEvent) => {
|
| 441 |
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
if (selectedGroups.length === 0) {
|
| 443 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
return;
|
| 445 |
}
|
| 446 |
|
| 447 |
-
const
|
| 448 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
|
| 450 |
setLoading(true);
|
| 451 |
-
setCreationError("");
|
| 452 |
try {
|
| 453 |
const uploadedUrls: string[] = [];
|
| 454 |
|
|
@@ -1639,16 +1672,28 @@ export default function CampaignsPage() {
|
|
| 1639 |
</button>
|
| 1640 |
</div>
|
| 1641 |
<div className="relative">
|
| 1642 |
-
|
| 1643 |
-
|
| 1644 |
-
|
| 1645 |
-
|
| 1646 |
-
|
| 1647 |
-
|
| 1648 |
-
|
| 1649 |
-
|
| 1650 |
-
|
| 1651 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1652 |
<ChevronDown size={14} className="absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground/40 pointer-events-none" />
|
| 1653 |
</div>
|
| 1654 |
</div>
|
|
@@ -1821,11 +1866,17 @@ export default function CampaignsPage() {
|
|
| 1821 |
</button>
|
| 1822 |
<button
|
| 1823 |
type="button"
|
| 1824 |
-
onClick={() =>
|
| 1825 |
-
|
| 1826 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1827 |
>
|
| 1828 |
-
<Sparkles size={10} /> Spintax
|
| 1829 |
</button>
|
| 1830 |
<TemplatePickerDropdown
|
| 1831 |
templates={templates}
|
|
@@ -2111,9 +2162,26 @@ export default function CampaignsPage() {
|
|
| 2111 |
</div>
|
| 2112 |
|
| 2113 |
{creationError && (
|
| 2114 |
-
<div className="
|
| 2115 |
-
<
|
| 2116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2117 |
</div>
|
| 2118 |
)}
|
| 2119 |
|
|
|
|
| 439 |
|
| 440 |
const handleSubmit = async (e: React.FormEvent) => {
|
| 441 |
e.preventDefault();
|
| 442 |
+
setCreationError("");
|
| 443 |
+
|
| 444 |
+
if (!campaignData.phone_number && accounts.length > 0) {
|
| 445 |
+
campaignData.phone_number = accounts[0].phone_number;
|
| 446 |
+
}
|
| 447 |
+
if (!campaignData.phone_number) {
|
| 448 |
+
setCreationError("Please select a sender Telegram phone account before deploying.");
|
| 449 |
+
return;
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
if (selectedGroups.length === 0) {
|
| 453 |
+
setCreationError("Please select at least one target group/channel.");
|
| 454 |
+
return;
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
const userPlan = (userStatus?.plan || 'free').toLowerCase();
|
| 458 |
+
const allowedSpeeds = userStatus?.allowed_speeds || (userPlan === 'basic' ? ['balanced', 'turbo'] : userPlan === 'free' ? ['balanced'] : ['balanced', 'turbo', 'stealth', 'ultra']);
|
| 459 |
+
const selectedSpeed = (campaignData.speed_mode || 'balanced').toLowerCase();
|
| 460 |
+
if (!allowedSpeeds.includes(selectedSpeed)) {
|
| 461 |
+
const reqTier = selectedSpeed === 'turbo' ? 'Growth Basic' : (selectedSpeed === 'stealth' ? 'Pro Standard' : 'Enterprise Premium');
|
| 462 |
+
setCreationError(`Speed mode '${selectedSpeed.toUpperCase()}' is locked. Please upgrade to ${reqTier} or select 'Balanced' to deploy.`);
|
| 463 |
return;
|
| 464 |
}
|
| 465 |
|
| 466 |
+
const hasSpintax = campaignData.message && (campaignData.message.includes('{') && campaignData.message.includes('|') && campaignData.message.includes('}'));
|
| 467 |
+
if (userPlan === 'free' && hasSpintax) {
|
| 468 |
+
setCreationError("Dynamic Spintax rotation requires a Basic plan or higher. Upgrade to Growth Basic or remove Spintax brackets to deploy.");
|
| 469 |
+
return;
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
let utcScheduleTime = new Date().toISOString().slice(0, 16);
|
| 473 |
+
if (campaignData.schedule_time && campaignData.schedule_time.trim()) {
|
| 474 |
+
try {
|
| 475 |
+
const localDate = new Date(campaignData.schedule_time);
|
| 476 |
+
if (!isNaN(localDate.getTime())) {
|
| 477 |
+
utcScheduleTime = localDate.toISOString().slice(0, 16);
|
| 478 |
+
}
|
| 479 |
+
} catch (err) {
|
| 480 |
+
utcScheduleTime = new Date().toISOString().slice(0, 16);
|
| 481 |
+
}
|
| 482 |
+
}
|
| 483 |
|
| 484 |
setLoading(true);
|
|
|
|
| 485 |
try {
|
| 486 |
const uploadedUrls: string[] = [];
|
| 487 |
|
|
|
|
| 1672 |
</button>
|
| 1673 |
</div>
|
| 1674 |
<div className="relative">
|
| 1675 |
+
{(() => {
|
| 1676 |
+
const curPlan = (userStatus?.plan || 'free').toLowerCase();
|
| 1677 |
+
const allowed = userStatus?.allowed_speeds || (curPlan === 'basic' ? ['balanced', 'turbo'] : curPlan === 'free' ? ['balanced'] : ['balanced', 'turbo', 'stealth', 'ultra']);
|
| 1678 |
+
return (
|
| 1679 |
+
<select
|
| 1680 |
+
value={campaignData.speed_mode || 'balanced'}
|
| 1681 |
+
onChange={(e) => setCampaignData(prev => ({ ...prev, speed_mode: e.target.value }))}
|
| 1682 |
+
className="w-full bg-input border border-border/70 rounded-xl py-2 px-3 text-xs text-foreground focus:ring-2 focus:ring-indigo-500/20 outline-none transition-all appearance-none cursor-pointer pr-8 font-medium"
|
| 1683 |
+
>
|
| 1684 |
+
<option value="balanced">⚖️ Balanced (25s - 40s) — All Plans</option>
|
| 1685 |
+
<option value="turbo" disabled={!allowed.includes('turbo')} className={!allowed.includes('turbo') ? 'text-foreground/40 bg-background/90' : ''}>
|
| 1686 |
+
{allowed.includes('turbo') ? '⚡ Turbo (20s - 30s) — Fastest' : '🔒 ⚡ Turbo (Requires Growth Basic+)'}
|
| 1687 |
+
</option>
|
| 1688 |
+
<option value="stealth" disabled={!allowed.includes('stealth')} className={!allowed.includes('stealth') ? 'text-foreground/40 bg-background/90' : ''}>
|
| 1689 |
+
{allowed.includes('stealth') ? '🛡️ Stealth (45s - 70s) — Safe Spacing' : '🔒 🛡️ Stealth (Requires Pro Standard+)'}
|
| 1690 |
+
</option>
|
| 1691 |
+
<option value="ultra" disabled={!allowed.includes('ultra')} className={!allowed.includes('ultra') ? 'text-foreground/40 bg-background/90' : ''}>
|
| 1692 |
+
{allowed.includes('ultra') ? '🐢 Ultra-Safe (75s - 120s) — Max Guard' : '🔒 🐢 Ultra-Safe (Requires Premium+)'}
|
| 1693 |
+
</option>
|
| 1694 |
+
</select>
|
| 1695 |
+
);
|
| 1696 |
+
})()}
|
| 1697 |
<ChevronDown size={14} className="absolute right-2.5 top-1/2 -translate-y-1/2 text-foreground/40 pointer-events-none" />
|
| 1698 |
</div>
|
| 1699 |
</div>
|
|
|
|
| 1866 |
</button>
|
| 1867 |
<button
|
| 1868 |
type="button"
|
| 1869 |
+
onClick={() => {
|
| 1870 |
+
if ((userStatus?.plan || 'free') === 'free') {
|
| 1871 |
+
setCreationError("Dynamic Spintax rotation requires a Growth Basic plan or higher. Upgrade to unlock Spintax variation generator.");
|
| 1872 |
+
return;
|
| 1873 |
+
}
|
| 1874 |
+
setIsSpintaxModalOpen(true);
|
| 1875 |
+
}}
|
| 1876 |
+
className={`px-2 py-0.5 rounded-md text-[10px] font-bold border transition-all flex items-center gap-1 cursor-pointer active:scale-95 shrink-0 ${(userStatus?.plan || 'free') === 'free' ? 'bg-foreground/5 text-foreground/40 border-border/50 hover:bg-foreground/10' : 'bg-indigo-500/10 text-indigo-400 border-indigo-500/25 hover:bg-indigo-500/20'}`}
|
| 1877 |
+
title={(userStatus?.plan || 'free') === 'free' ? "Spintax requires Basic plan or higher" : "Launch Spintax Message Assistant"}
|
| 1878 |
>
|
| 1879 |
+
{(userStatus?.plan || 'free') === 'free' ? <span>🔒 Spintax (Basic+)</span> : <><Sparkles size={10} /> Spintax</>}
|
| 1880 |
</button>
|
| 1881 |
<TemplatePickerDropdown
|
| 1882 |
templates={templates}
|
|
|
|
| 2162 |
</div>
|
| 2163 |
|
| 2164 |
{creationError && (
|
| 2165 |
+
<div className="p-3 bg-red-500/10 border border-red-500/20 rounded-xl text-xs space-y-2">
|
| 2166 |
+
<div className="flex items-center gap-2 text-red-500 font-semibold">
|
| 2167 |
+
<AlertCircle size={15} className="shrink-0 text-red-400" />
|
| 2168 |
+
<span className="flex-1">{creationError}</span>
|
| 2169 |
+
</div>
|
| 2170 |
+
{(creationError.toLowerCase().includes('upgrade') || creationError.toLowerCase().includes('locked') || creationError.toLowerCase().includes('limit')) && (
|
| 2171 |
+
<div className="pt-1 flex items-center justify-between border-t border-red-500/15">
|
| 2172 |
+
<span className="text-[11px] text-foreground/50">Unlock higher limits with an upgraded tier</span>
|
| 2173 |
+
<button
|
| 2174 |
+
type="button"
|
| 2175 |
+
onClick={() => {
|
| 2176 |
+
window.dispatchEvent(new Event('open-monetization-modal'));
|
| 2177 |
+
}}
|
| 2178 |
+
className="inline-flex items-center gap-1.5 px-3 py-1 bg-indigo-500 hover:bg-indigo-600 text-white font-bold text-[11px] rounded-lg transition-all cursor-pointer shadow-sm active:scale-95"
|
| 2179 |
+
>
|
| 2180 |
+
<Sparkles size={11} />
|
| 2181 |
+
<span>Upgrade Plan</span>
|
| 2182 |
+
</button>
|
| 2183 |
+
</div>
|
| 2184 |
+
)}
|
| 2185 |
</div>
|
| 2186 |
)}
|
| 2187 |
|
frontend/src/app/templates/page.tsx
CHANGED
|
@@ -615,9 +615,23 @@ export default function TemplatesPage() {
|
|
| 615 |
</div>
|
| 616 |
|
| 617 |
{error && (
|
| 618 |
-
<div className="flex items-center gap-2 p-
|
| 619 |
-
<
|
| 620 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 621 |
</div>
|
| 622 |
)}
|
| 623 |
|
|
|
|
| 615 |
</div>
|
| 616 |
|
| 617 |
{error && (
|
| 618 |
+
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 p-3 bg-red-500/10 border border-red-500/20 rounded-xl text-red-400 text-xs font-semibold">
|
| 619 |
+
<div className="flex items-center gap-2">
|
| 620 |
+
<AlertCircle size={15} className="shrink-0 text-red-400" />
|
| 621 |
+
<span>{error}</span>
|
| 622 |
+
</div>
|
| 623 |
+
{error.toLowerCase().includes('upgrade') && (
|
| 624 |
+
<button
|
| 625 |
+
type="button"
|
| 626 |
+
onClick={() => {
|
| 627 |
+
setIsCreating(false);
|
| 628 |
+
window.dispatchEvent(new CustomEvent('open_upgrade_modal'));
|
| 629 |
+
}}
|
| 630 |
+
className="px-3 py-1 bg-gradient-to-r from-indigo-500 to-purple-600 hover:from-indigo-600 hover:to-purple-700 text-white font-bold rounded-lg text-[11px] shadow-md transition-all self-start sm:self-auto shrink-0 cursor-pointer"
|
| 631 |
+
>
|
| 632 |
+
Upgrade Plan
|
| 633 |
+
</button>
|
| 634 |
+
)}
|
| 635 |
</div>
|
| 636 |
)}
|
| 637 |
|
frontend/src/components/MonetizationOverlay.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
| 5 |
Lock, CreditCard, CheckCircle2, X, AlertCircle,
|
| 6 |
Zap, Star, Crown, Copy, Check, ExternalLink, ShieldCheck,
|
| 7 |
Building2, Coins, ArrowRight, MessageCircle, Globe,
|
| 8 |
-
ArrowLeft, Mail, Clock, Sparkles, Send
|
| 9 |
} from 'lucide-react';
|
| 10 |
|
| 11 |
interface MonetizationOverlayProps {
|
|
@@ -239,6 +239,8 @@ export const MonetizationOverlay: React.FC<MonetizationOverlayProps> = ({ childr
|
|
| 239 |
const [senderRef, setSenderRef] = useState('');
|
| 240 |
const [copiedKey, setCopiedKey] = useState<string | null>(null);
|
| 241 |
const [copiedNotification, setCopiedNotification] = useState<string | null>(null);
|
|
|
|
|
|
|
| 242 |
|
| 243 |
const fetchStatus = async () => {
|
| 244 |
try {
|
|
@@ -977,146 +979,231 @@ export const MonetizationOverlay: React.FC<MonetizationOverlayProps> = ({ childr
|
|
| 977 |
</div>
|
| 978 |
</div>
|
| 979 |
) : (
|
| 980 |
-
/* Step 2: Redesigned Receipt Verification Desk */
|
| 981 |
-
<div className="overflow-y-auto custom-scrollbar flex-1 max-h-[calc(92vh-140px)] pr-2 py-1 space-y-4 max-w-2xl mx-auto w-full animate-in fade-in duration-200">
|
| 982 |
|
| 983 |
-
{/* Stepper Progress
|
| 984 |
-
<div className="flex items-center justify-between max-w-md mx-auto px-4 py-2 rounded-xl bg-white/[0.
|
| 985 |
<div className="flex items-center gap-1.5 text-emerald-400 font-bold">
|
| 986 |
<div className="w-5 h-5 rounded-full bg-emerald-500/20 border border-emerald-500/40 flex items-center justify-center text-[10px]">✓</div>
|
| 987 |
-
<span>
|
| 988 |
</div>
|
| 989 |
-
<div className="h-0.5 w-10 bg-emerald-500/
|
| 990 |
<div className="flex items-center gap-1.5 text-indigo-400 font-bold">
|
| 991 |
-
<div className="w-5 h-5 rounded-full bg-indigo-500/20 border border-indigo-500/
|
| 992 |
-
<span>
|
| 993 |
</div>
|
| 994 |
<div className="h-0.5 w-10 bg-white/10" />
|
| 995 |
<div className="flex items-center gap-1.5 text-slate-400 font-medium">
|
| 996 |
<div className="w-5 h-5 rounded-full bg-white/5 border border-white/10 flex items-center justify-center text-[10px]">3</div>
|
| 997 |
-
<span>
|
| 998 |
</div>
|
| 999 |
</div>
|
| 1000 |
|
| 1001 |
-
{/*
|
| 1002 |
-
<div className="bg-[#
|
| 1003 |
-
|
|
|
|
| 1004 |
<div className="flex items-center gap-2">
|
| 1005 |
-
<span className="
|
| 1006 |
-
|
|
|
|
| 1007 |
</span>
|
| 1008 |
-
<span className="text-xs text-slate-400 font-medium">Monthly Access (30 Days)</span>
|
| 1009 |
</div>
|
| 1010 |
-
<div className="flex items-center gap-
|
| 1011 |
-
<span className="
|
| 1012 |
-
|
|
|
|
|
|
|
| 1013 |
</div>
|
| 1014 |
</div>
|
| 1015 |
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
<span className="font-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1020 |
</div>
|
| 1021 |
-
|
| 1022 |
-
|
| 1023 |
-
<
|
|
|
|
| 1024 |
<CurrencyFlag currency={paymentMethod === 'bank' ? selectedCurrency : selectedCrypto} />
|
| 1025 |
-
<span
|
|
|
|
|
|
|
| 1026 |
</div>
|
| 1027 |
</div>
|
| 1028 |
-
|
| 1029 |
-
|
| 1030 |
-
<span className="font-bold
|
|
|
|
| 1031 |
{paymentMethod === 'bank' ? `Bank (${selectedCurrency})` : `Crypto (${selectedCrypto})`}
|
| 1032 |
</span>
|
| 1033 |
</div>
|
| 1034 |
-
|
| 1035 |
-
|
| 1036 |
-
<span className="
|
| 1037 |
-
|
|
|
|
| 1038 |
</span>
|
| 1039 |
</div>
|
| 1040 |
</div>
|
| 1041 |
-
</div>
|
| 1042 |
|
| 1043 |
-
|
| 1044 |
-
|
| 1045 |
-
|
| 1046 |
-
<
|
| 1047 |
-
<
|
| 1048 |
-
</label>
|
| 1049 |
-
<div className="relative">
|
| 1050 |
-
<input
|
| 1051 |
-
type="text"
|
| 1052 |
-
placeholder="e.g. Victor Adeleye or Bank Transfer Ref #09812..."
|
| 1053 |
-
value={senderRef}
|
| 1054 |
-
onChange={(e) => setSenderRef(e.target.value)}
|
| 1055 |
-
className="w-full bg-black/40 border border-white/15 rounded-xl px-4 py-3 text-xs sm:text-sm text-white placeholder:text-slate-500 focus:outline-none focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500 transition-all font-medium"
|
| 1056 |
-
/>
|
| 1057 |
</div>
|
| 1058 |
-
<p className="text-[11px] text-slate-400 leading-normal">
|
| 1059 |
-
Providing your account name or transfer reference allows our desk team to confirm and upgrade your account immediately.
|
| 1060 |
-
</p>
|
| 1061 |
-
</div>
|
| 1062 |
|
| 1063 |
-
|
| 1064 |
-
|
| 1065 |
-
|
| 1066 |
-
<
|
| 1067 |
-
|
| 1068 |
-
|
| 1069 |
-
|
| 1070 |
-
|
| 1071 |
-
|
| 1072 |
-
|
| 1073 |
-
|
| 1074 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1075 |
)}
|
| 1076 |
-
|
| 1077 |
-
>
|
| 1078 |
-
<Copy size={12} />
|
| 1079 |
-
<span>Copy Message</span>
|
| 1080 |
-
</button>
|
| 1081 |
-
</div>
|
| 1082 |
-
<div className="p-3 rounded-xl bg-black/40 border border-white/5 font-mono text-[11px] text-slate-300 leading-relaxed whitespace-pre-line select-all">
|
| 1083 |
-
{`Hello ArkiTel Desk,\n\nI have made payment for the *${plans.find(p => p.key === selectedPlan)?.name}* plan (${getConvertedPrice(paymentMethod === 'bank' ? selectedCurrency : selectedCrypto)}).\nUsername: *${status?.username || 'My Account'}*` + (senderRef.trim() ? `\nReference / Sender: *${senderRef.trim()}*` : '') + `\n\nPayment receipt is attached below. Kindly verify and activate!`}
|
| 1084 |
</div>
|
| 1085 |
</div>
|
| 1086 |
|
| 1087 |
-
{/* Primary VIP WhatsApp
|
| 1088 |
<div className="space-y-3 pt-1">
|
| 1089 |
<button
|
| 1090 |
type="button"
|
| 1091 |
onClick={handleWhatsAppSubmit}
|
| 1092 |
disabled={applying}
|
| 1093 |
-
className="w-full bg-[#25D366] hover:
|
| 1094 |
>
|
| 1095 |
<MessageCircle size={20} className="fill-black" />
|
| 1096 |
-
<span>{applying ? 'Opening
|
| 1097 |
<ExternalLink size={16} />
|
| 1098 |
</button>
|
| 1099 |
|
| 1100 |
-
{/* Alternative Desks &
|
| 1101 |
-
<div className="
|
| 1102 |
<a
|
| 1103 |
href="https://t.me/arkitel_support"
|
| 1104 |
target="_blank"
|
| 1105 |
rel="noopener noreferrer"
|
| 1106 |
-
className="flex items-center
|
| 1107 |
>
|
| 1108 |
-
<
|
| 1109 |
-
|
|
|
|
|
|
|
|
|
|
| 1110 |
</a>
|
| 1111 |
|
| 1112 |
<a
|
| 1113 |
href={`mailto:${SUPPORT_EMAIL}?subject=ArkiTel%20Payment%20Receipt%20-%20${encodeURIComponent(status?.username || '')}&body=${encodeURIComponent(`Hello ArkiTel Support,\n\nI have attached my receipt for the ${plans.find(p => p.key === selectedPlan)?.name} plan.\nUsername: ${status?.username || ''}\nEmail: ${status?.email || ''}`)}`}
|
| 1114 |
-
className="flex items-center
|
| 1115 |
>
|
| 1116 |
-
<
|
| 1117 |
-
|
|
|
|
|
|
|
|
|
|
| 1118 |
</a>
|
| 1119 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1120 |
</div>
|
| 1121 |
</div>
|
| 1122 |
)}
|
|
|
|
| 5 |
Lock, CreditCard, CheckCircle2, X, AlertCircle,
|
| 6 |
Zap, Star, Crown, Copy, Check, ExternalLink, ShieldCheck,
|
| 7 |
Building2, Coins, ArrowRight, MessageCircle, Globe,
|
| 8 |
+
ArrowLeft, Mail, Clock, Sparkles, Send, Upload, FileText
|
| 9 |
} from 'lucide-react';
|
| 10 |
|
| 11 |
interface MonetizationOverlayProps {
|
|
|
|
| 239 |
const [senderRef, setSenderRef] = useState('');
|
| 240 |
const [copiedKey, setCopiedKey] = useState<string | null>(null);
|
| 241 |
const [copiedNotification, setCopiedNotification] = useState<string | null>(null);
|
| 242 |
+
const [receiptFileName, setReceiptFileName] = useState<string>('');
|
| 243 |
+
const [receiptPreview, setReceiptPreview] = useState<string | null>(null);
|
| 244 |
|
| 245 |
const fetchStatus = async () => {
|
| 246 |
try {
|
|
|
|
| 979 |
</div>
|
| 980 |
</div>
|
| 981 |
) : (
|
| 982 |
+
/* Step 2: Luxury Redesigned Receipt Verification Desk */
|
| 983 |
+
<div className="overflow-y-auto custom-scrollbar flex-1 max-h-[calc(92vh-140px)] pr-2 py-1 space-y-4 max-w-2xl mx-auto w-full animate-in fade-in zoom-in-95 duration-200">
|
| 984 |
|
| 985 |
+
{/* Stepper Progress Bar */}
|
| 986 |
+
<div className="flex items-center justify-between max-w-md mx-auto px-4 py-2 rounded-xl bg-white/[0.04] border border-white/10 text-xs">
|
| 987 |
<div className="flex items-center gap-1.5 text-emerald-400 font-bold">
|
| 988 |
<div className="w-5 h-5 rounded-full bg-emerald-500/20 border border-emerald-500/40 flex items-center justify-center text-[10px]">✓</div>
|
| 989 |
+
<span>Payment Sent</span>
|
| 990 |
</div>
|
| 991 |
+
<div className="h-0.5 w-10 bg-emerald-500/40" />
|
| 992 |
<div className="flex items-center gap-1.5 text-indigo-400 font-bold">
|
| 993 |
+
<div className="w-5 h-5 rounded-full bg-indigo-500/20 border border-indigo-500/60 flex items-center justify-center text-[10px] animate-pulse">2</div>
|
| 994 |
+
<span>Verification Desk</span>
|
| 995 |
</div>
|
| 996 |
<div className="h-0.5 w-10 bg-white/10" />
|
| 997 |
<div className="flex items-center gap-1.5 text-slate-400 font-medium">
|
| 998 |
<div className="w-5 h-5 rounded-full bg-white/5 border border-white/10 flex items-center justify-center text-[10px]">3</div>
|
| 999 |
+
<span>Account Active</span>
|
| 1000 |
</div>
|
| 1001 |
</div>
|
| 1002 |
|
| 1003 |
+
{/* Luxury Digital Voucher / Clearing Pass */}
|
| 1004 |
+
<div className="relative bg-[#0d1222] border border-indigo-500/40 ring-1 ring-indigo-500/20 rounded-2xl shadow-2xl overflow-hidden">
|
| 1005 |
+
{/* Top Holographic Watermark Bar */}
|
| 1006 |
+
<div className="bg-gradient-to-r from-indigo-950/80 via-[#151c34] to-indigo-950/80 px-4 py-3 border-b border-white/10 flex flex-wrap items-center justify-between gap-2">
|
| 1007 |
<div className="flex items-center gap-2">
|
| 1008 |
+
<span className="w-2.5 h-2.5 rounded-full bg-indigo-400 shadow-sm shadow-indigo-400/50" />
|
| 1009 |
+
<span className="text-[11px] font-black uppercase tracking-wider text-indigo-200">
|
| 1010 |
+
ArkiTel Financial Clearing Voucher
|
| 1011 |
</span>
|
|
|
|
| 1012 |
</div>
|
| 1013 |
+
<div className="flex items-center gap-2">
|
| 1014 |
+
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-emerald-500/15 border border-emerald-500/30 text-[10px] font-extrabold text-emerald-400">
|
| 1015 |
+
<span className="w-1.5 h-1.5 rounded-full bg-emerald-400 animate-ping" />
|
| 1016 |
+
<span>Concierge Active (< 5 min SLA)</span>
|
| 1017 |
+
</span>
|
| 1018 |
</div>
|
| 1019 |
</div>
|
| 1020 |
|
| 1021 |
+
{/* Voucher Grid: 4 Core Parameters */}
|
| 1022 |
+
<div className="p-4 sm:p-5 grid grid-cols-2 sm:grid-cols-4 gap-3 bg-black/20">
|
| 1023 |
+
<div className="p-3 rounded-xl bg-white/[0.03] border border-white/5 space-y-1">
|
| 1024 |
+
<span className="text-[10px] font-bold uppercase tracking-wider text-slate-400 block">Selected Tier</span>
|
| 1025 |
+
<div className="flex items-center gap-1.5">
|
| 1026 |
+
<Sparkles size={13} className="text-indigo-400 shrink-0" />
|
| 1027 |
+
<span className="font-extrabold text-white text-xs sm:text-sm truncate">
|
| 1028 |
+
{plans.find(p => p.key === selectedPlan)?.name}
|
| 1029 |
+
</span>
|
| 1030 |
+
</div>
|
| 1031 |
</div>
|
| 1032 |
+
|
| 1033 |
+
<div className="p-3 rounded-xl bg-white/[0.03] border border-white/5 space-y-1">
|
| 1034 |
+
<span className="text-[10px] font-bold uppercase tracking-wider text-slate-400 block">Amount Sent</span>
|
| 1035 |
+
<div className="flex items-center gap-1.5">
|
| 1036 |
<CurrencyFlag currency={paymentMethod === 'bank' ? selectedCurrency : selectedCrypto} />
|
| 1037 |
+
<span className="font-extrabold text-emerald-400 text-xs sm:text-sm truncate">
|
| 1038 |
+
{getConvertedPrice(paymentMethod === 'bank' ? selectedCurrency : selectedCrypto)}
|
| 1039 |
+
</span>
|
| 1040 |
</div>
|
| 1041 |
</div>
|
| 1042 |
+
|
| 1043 |
+
<div className="p-3 rounded-xl bg-white/[0.03] border border-white/5 space-y-1">
|
| 1044 |
+
<span className="text-[10px] font-bold uppercase tracking-wider text-slate-400 block">Channel</span>
|
| 1045 |
+
<span className="font-bold text-slate-200 text-xs sm:text-sm truncate block">
|
| 1046 |
{paymentMethod === 'bank' ? `Bank (${selectedCurrency})` : `Crypto (${selectedCrypto})`}
|
| 1047 |
</span>
|
| 1048 |
</div>
|
| 1049 |
+
|
| 1050 |
+
<div className="p-3 rounded-xl bg-white/[0.03] border border-white/5 space-y-1">
|
| 1051 |
+
<span className="text-[10px] font-bold uppercase tracking-wider text-slate-400 block">Account ID</span>
|
| 1052 |
+
<span className="font-mono font-bold text-indigo-300 text-xs sm:text-sm truncate block">
|
| 1053 |
+
@{status?.username || 'Current Operator'}
|
| 1054 |
</span>
|
| 1055 |
</div>
|
| 1056 |
</div>
|
|
|
|
| 1057 |
|
| 1058 |
+
{/* Perforated Voucher Tear Line */}
|
| 1059 |
+
<div className="relative flex items-center justify-between px-2 py-1">
|
| 1060 |
+
<div className="w-4 h-4 rounded-full bg-[#0B0F1C] -ml-4 border-r border-white/10" />
|
| 1061 |
+
<div className="flex-1 border-t-2 border-dashed border-white/10 mx-2" />
|
| 1062 |
+
<div className="w-4 h-4 rounded-full bg-[#0B0F1C] -mr-4 border-l border-white/10" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1063 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1064 |
|
| 1065 |
+
{/* Interactive Proof Submission Controls */}
|
| 1066 |
+
<div className="p-4 sm:p-5 space-y-4">
|
| 1067 |
+
{/* Payer Name / Reference Input */}
|
| 1068 |
+
<div className="space-y-1.5">
|
| 1069 |
+
<div className="flex items-center justify-between text-xs">
|
| 1070 |
+
<label htmlFor="payer-ref-input" className="font-bold text-white flex items-center gap-1.5">
|
| 1071 |
+
<span>Transfer Reference / Payer Account Name</span>
|
| 1072 |
+
<span className="text-slate-400 text-[10px] font-normal">(Optional)</span>
|
| 1073 |
+
</label>
|
| 1074 |
+
<span className="text-[10px] font-semibold text-emerald-400">Speeds Up Immediate Unlock</span>
|
| 1075 |
+
</div>
|
| 1076 |
+
<div className="relative">
|
| 1077 |
+
<input
|
| 1078 |
+
id="payer-ref-input"
|
| 1079 |
+
type="text"
|
| 1080 |
+
placeholder="e.g., Victor Adeleye - Access Bank Ref #91823"
|
| 1081 |
+
value={senderRef}
|
| 1082 |
+
onChange={(e) => setSenderRef(e.target.value)}
|
| 1083 |
+
className="w-full bg-black/50 border border-white/15 focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500/40 rounded-xl px-4 py-3 text-xs sm:text-sm text-white placeholder:text-slate-500 outline-none transition-all font-medium"
|
| 1084 |
+
/>
|
| 1085 |
+
</div>
|
| 1086 |
+
</div>
|
| 1087 |
+
|
| 1088 |
+
{/* Simulated / Interactive Receipt Dropzone */}
|
| 1089 |
+
<div className="space-y-1.5">
|
| 1090 |
+
<label className="text-xs font-bold text-white flex items-center justify-between">
|
| 1091 |
+
<span>Attach Payment Proof / Screenshot</span>
|
| 1092 |
+
<span className="text-[10px] text-slate-400">PNG, JPG, PDF up to 10MB</span>
|
| 1093 |
+
</label>
|
| 1094 |
+
|
| 1095 |
+
<input
|
| 1096 |
+
type="file"
|
| 1097 |
+
id="receipt-file-picker"
|
| 1098 |
+
accept="image/*,.pdf"
|
| 1099 |
+
className="hidden"
|
| 1100 |
+
onChange={(e) => {
|
| 1101 |
+
if (e.target.files && e.target.files[0]) {
|
| 1102 |
+
const f = e.target.files[0];
|
| 1103 |
+
setReceiptFileName(f.name);
|
| 1104 |
+
setReceiptPreview(URL.createObjectURL(f));
|
| 1105 |
+
}
|
| 1106 |
+
}}
|
| 1107 |
+
/>
|
| 1108 |
+
|
| 1109 |
+
{receiptFileName ? (
|
| 1110 |
+
<div className="p-3.5 rounded-xl bg-emerald-500/10 border border-emerald-500/30 flex items-center justify-between gap-3 animate-in fade-in duration-150">
|
| 1111 |
+
<div className="flex items-center gap-2.5 min-w-0">
|
| 1112 |
+
<CheckCircle2 size={18} className="text-emerald-400 shrink-0" />
|
| 1113 |
+
<div className="min-w-0">
|
| 1114 |
+
<div className="text-xs font-bold text-white truncate">{receiptFileName}</div>
|
| 1115 |
+
<div className="text-[10px] text-emerald-400 font-medium">Receipt ready for transmission to WhatsApp Desk</div>
|
| 1116 |
+
</div>
|
| 1117 |
+
</div>
|
| 1118 |
+
<button
|
| 1119 |
+
type="button"
|
| 1120 |
+
onClick={() => {
|
| 1121 |
+
setReceiptFileName('');
|
| 1122 |
+
setReceiptPreview(null);
|
| 1123 |
+
}}
|
| 1124 |
+
className="px-2.5 py-1 rounded-lg bg-white/5 hover:bg-white/10 text-[11px] text-slate-300 transition-colors cursor-pointer shrink-0"
|
| 1125 |
+
>
|
| 1126 |
+
Remove
|
| 1127 |
+
</button>
|
| 1128 |
+
</div>
|
| 1129 |
+
) : (
|
| 1130 |
+
<label
|
| 1131 |
+
htmlFor="receipt-file-picker"
|
| 1132 |
+
className="p-4 rounded-xl border border-dashed border-white/20 hover:border-indigo-400/60 bg-white/[0.02] hover:bg-indigo-500/[0.04] transition-all flex items-center justify-center gap-3 cursor-pointer group"
|
| 1133 |
+
>
|
| 1134 |
+
<div className="p-2 rounded-lg bg-indigo-500/10 text-indigo-400 group-hover:bg-indigo-500/20 transition-colors">
|
| 1135 |
+
<Upload size={16} />
|
| 1136 |
+
</div>
|
| 1137 |
+
<div className="text-left">
|
| 1138 |
+
<div className="text-xs font-bold text-slate-200 group-hover:text-white transition-colors">
|
| 1139 |
+
Click to attach receipt or drag screenshot here
|
| 1140 |
+
</div>
|
| 1141 |
+
<div className="text-[10px] text-slate-400">
|
| 1142 |
+
Transmits directly to our 24/7 verification team
|
| 1143 |
+
</div>
|
| 1144 |
+
</div>
|
| 1145 |
+
</label>
|
| 1146 |
)}
|
| 1147 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1148 |
</div>
|
| 1149 |
</div>
|
| 1150 |
|
| 1151 |
+
{/* Primary VIP WhatsApp Activation Action */}
|
| 1152 |
<div className="space-y-3 pt-1">
|
| 1153 |
<button
|
| 1154 |
type="button"
|
| 1155 |
onClick={handleWhatsAppSubmit}
|
| 1156 |
disabled={applying}
|
| 1157 |
+
className="w-full bg-gradient-to-r from-[#25D366] to-[#1ebe5b] hover:from-[#20ba59] hover:to-[#17a54e] text-black font-black py-4 rounded-xl transition-all flex items-center justify-center gap-2.5 text-sm shadow-xl shadow-[#25D366]/20 active:scale-[0.99] cursor-pointer disabled:opacity-50"
|
| 1158 |
>
|
| 1159 |
<MessageCircle size={20} className="fill-black" />
|
| 1160 |
+
<span>{applying ? 'Opening VIP Desk...' : 'Transmit Proof to WhatsApp Concierge (Fast-Track)'}</span>
|
| 1161 |
<ExternalLink size={16} />
|
| 1162 |
</button>
|
| 1163 |
|
| 1164 |
+
{/* Alternative Desks Grid & 1-Click Message Copy */}
|
| 1165 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2 text-xs">
|
| 1166 |
<a
|
| 1167 |
href="https://t.me/arkitel_support"
|
| 1168 |
target="_blank"
|
| 1169 |
rel="noopener noreferrer"
|
| 1170 |
+
className="p-2.5 rounded-xl bg-white/[0.03] hover:bg-white/[0.07] border border-white/10 flex items-center justify-between text-slate-300 hover:text-cyan-400 transition-all cursor-pointer group"
|
| 1171 |
>
|
| 1172 |
+
<span className="flex items-center gap-2">
|
| 1173 |
+
<Send size={14} className="text-cyan-400" />
|
| 1174 |
+
<span className="font-semibold">Telegram VIP Desk</span>
|
| 1175 |
+
</span>
|
| 1176 |
+
<span className="text-[11px] text-slate-500 group-hover:text-cyan-300">@arkitel_support</span>
|
| 1177 |
</a>
|
| 1178 |
|
| 1179 |
<a
|
| 1180 |
href={`mailto:${SUPPORT_EMAIL}?subject=ArkiTel%20Payment%20Receipt%20-%20${encodeURIComponent(status?.username || '')}&body=${encodeURIComponent(`Hello ArkiTel Support,\n\nI have attached my receipt for the ${plans.find(p => p.key === selectedPlan)?.name} plan.\nUsername: ${status?.username || ''}\nEmail: ${status?.email || ''}`)}`}
|
| 1181 |
+
className="p-2.5 rounded-xl bg-white/[0.03] hover:bg-white/[0.07] border border-white/10 flex items-center justify-between text-slate-300 hover:text-amber-400 transition-all cursor-pointer group"
|
| 1182 |
>
|
| 1183 |
+
<span className="flex items-center gap-2">
|
| 1184 |
+
<Mail size={14} className="text-amber-400" />
|
| 1185 |
+
<span className="font-semibold">Email Desk</span>
|
| 1186 |
+
</span>
|
| 1187 |
+
<span className="text-[11px] text-slate-500 group-hover:text-amber-300">arkilostudios@gmail.com</span>
|
| 1188 |
</a>
|
| 1189 |
</div>
|
| 1190 |
+
|
| 1191 |
+
{/* 1-Click Verification Message Copy */}
|
| 1192 |
+
<div className="flex items-center justify-between pt-1 px-1">
|
| 1193 |
+
<span className="text-[11px] text-slate-400">Prefer manual chat message?</span>
|
| 1194 |
+
<button
|
| 1195 |
+
type="button"
|
| 1196 |
+
onClick={() => copyToClipboard(
|
| 1197 |
+
`Hello ArkiTel Desk,\n\nI have made payment for the *${plans.find(p => p.key === selectedPlan)?.name}* plan (${getConvertedPrice(paymentMethod === 'bank' ? selectedCurrency : selectedCrypto)}).\nUsername: *${status?.username || 'My Account'}*\n${senderRef.trim() ? `Reference / Sender: *${senderRef.trim()}*\n` : ''}${receiptFileName ? `Proof File: *${receiptFileName}*\n` : ''}\nPayment receipt is attached. Kindly verify and activate!`,
|
| 1198 |
+
'copy-preview-msg',
|
| 1199 |
+
'Verification message text copied!'
|
| 1200 |
+
)}
|
| 1201 |
+
className="text-[11px] font-bold text-indigo-400 hover:text-indigo-300 flex items-center gap-1 transition-colors cursor-pointer"
|
| 1202 |
+
>
|
| 1203 |
+
<Copy size={12} />
|
| 1204 |
+
<span>Copy Formatted Voucher Text</span>
|
| 1205 |
+
</button>
|
| 1206 |
+
</div>
|
| 1207 |
</div>
|
| 1208 |
</div>
|
| 1209 |
)}
|
frontend/src/components/Sidebar.tsx
CHANGED
|
@@ -28,7 +28,11 @@ import {
|
|
| 28 |
MessageCircle,
|
| 29 |
Send,
|
| 30 |
Mail,
|
| 31 |
-
ExternalLink
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
} from "lucide-react";
|
| 33 |
import { getToken, removeToken, apiFetch } from "@/lib/auth";
|
| 34 |
import { BroadcastBanner } from "./BroadcastBanner";
|
|
@@ -38,6 +42,7 @@ export function Sidebar({ children }: { children: React.ReactNode }) {
|
|
| 38 |
const [isCollapsed, setIsCollapsed] = useState(false);
|
| 39 |
const [isFooterCollapsed, setIsFooterCollapsed] = useState(false);
|
| 40 |
const [footerHeight, setFooterHeight] = useState<number>(300);
|
|
|
|
| 41 |
const [isDragging, setIsDragging] = useState(false);
|
| 42 |
const [showSupportModal, setShowSupportModal] = useState(false);
|
| 43 |
const [supportConfig, setSupportConfig] = useState({
|
|
@@ -369,7 +374,7 @@ export function Sidebar({ children }: { children: React.ReactNode }) {
|
|
| 369 |
|
| 370 |
{/* Collapsible System Status & Telemetry */}
|
| 371 |
{!isCollapsed && user && (
|
| 372 |
-
<div className={`transition-all duration-300 space-y-3.5 ${isFooterCollapsed ? 'opacity-0 max-h-0 pointer-events-none mt-0' : 'opacity-100 mt-2'}`}>
|
| 373 |
<div className="flex items-center justify-between pt-2 border-t border-border/50">
|
| 374 |
<div className="text-[10px] text-foreground/40 uppercase tracking-[0.2em] font-bold">System Status</div>
|
| 375 |
<span className={`text-[9px] font-black px-2 py-0.5 rounded-full border border-current uppercase ${status?.plan === 'unlimited' ? 'text-rose-400 bg-rose-500/10' :
|
|
@@ -382,6 +387,28 @@ export function Sidebar({ children }: { children: React.ReactNode }) {
|
|
| 382 |
</span>
|
| 383 |
</div>
|
| 384 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
{status?.plan === 'free' && (
|
| 386 |
<Link href="/scraper" className="block w-full text-center py-2 bg-indigo-500/10 hover:bg-indigo-500 text-indigo-500 hover:text-white text-[10px] font-black tracking-widest rounded-lg transition-all border border-indigo-500/20 shadow-lg shadow-indigo-500/10">
|
| 387 |
UPGRADE NOW
|
|
@@ -442,6 +469,121 @@ export function Sidebar({ children }: { children: React.ReactNode }) {
|
|
| 442 |
)}
|
| 443 |
</div>
|
| 444 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
<div className="pt-2 border-t border-border/50">
|
| 446 |
<div className="text-[10px] text-foreground/30 uppercase tracking-[0.2em] font-bold">Session</div>
|
| 447 |
<div className="text-xs text-foreground/60 font-semibold truncate mt-0.5">{user.username}</div>
|
|
|
|
| 28 |
MessageCircle,
|
| 29 |
Send,
|
| 30 |
Mail,
|
| 31 |
+
ExternalLink,
|
| 32 |
+
CheckCircle2,
|
| 33 |
+
Clock,
|
| 34 |
+
Lock,
|
| 35 |
+
ShieldCheck
|
| 36 |
} from "lucide-react";
|
| 37 |
import { getToken, removeToken, apiFetch } from "@/lib/auth";
|
| 38 |
import { BroadcastBanner } from "./BroadcastBanner";
|
|
|
|
| 42 |
const [isCollapsed, setIsCollapsed] = useState(false);
|
| 43 |
const [isFooterCollapsed, setIsFooterCollapsed] = useState(false);
|
| 44 |
const [footerHeight, setFooterHeight] = useState<number>(300);
|
| 45 |
+
const [showEntitlementsFlyout, setShowEntitlementsFlyout] = useState(false);
|
| 46 |
const [isDragging, setIsDragging] = useState(false);
|
| 47 |
const [showSupportModal, setShowSupportModal] = useState(false);
|
| 48 |
const [supportConfig, setSupportConfig] = useState({
|
|
|
|
| 374 |
|
| 375 |
{/* Collapsible System Status & Telemetry */}
|
| 376 |
{!isCollapsed && user && (
|
| 377 |
+
<div className={`relative transition-all duration-300 space-y-3.5 ${isFooterCollapsed ? 'opacity-0 max-h-0 pointer-events-none mt-0' : 'opacity-100 mt-2'}`}>
|
| 378 |
<div className="flex items-center justify-between pt-2 border-t border-border/50">
|
| 379 |
<div className="text-[10px] text-foreground/40 uppercase tracking-[0.2em] font-bold">System Status</div>
|
| 380 |
<span className={`text-[9px] font-black px-2 py-0.5 rounded-full border border-current uppercase ${status?.plan === 'unlimited' ? 'text-rose-400 bg-rose-500/10' :
|
|
|
|
| 387 |
</span>
|
| 388 |
</div>
|
| 389 |
|
| 390 |
+
{/* Active Coupon Badge & Expiry (if applied) */}
|
| 391 |
+
{status?.active_coupon_code && (
|
| 392 |
+
<div className="p-2 rounded-xl bg-emerald-500/10 border border-emerald-500/25 flex items-center justify-between text-[10px]">
|
| 393 |
+
<div className="flex items-center gap-1.5 font-bold text-emerald-400">
|
| 394 |
+
<Sparkles size={11} className="text-emerald-400" />
|
| 395 |
+
<span>Coupon:</span>
|
| 396 |
+
<span className="font-mono text-white font-extrabold">{status.active_coupon_code}</span>
|
| 397 |
+
</div>
|
| 398 |
+
{status?.coupon_expires_at && (
|
| 399 |
+
<span className="text-[9px] text-emerald-300/90 font-mono font-medium">
|
| 400 |
+
{(() => {
|
| 401 |
+
const diff = new Date(status.coupon_expires_at).getTime() - Date.now();
|
| 402 |
+
if (diff <= 0) return 'Expiring';
|
| 403 |
+
const hrs = Math.floor(diff / 3600000);
|
| 404 |
+
const mins = Math.floor((diff % 3600000) / 60000);
|
| 405 |
+
return hrs > 0 ? `${hrs}h ${mins}m` : `${mins}m`;
|
| 406 |
+
})()}
|
| 407 |
+
</span>
|
| 408 |
+
)}
|
| 409 |
+
</div>
|
| 410 |
+
)}
|
| 411 |
+
|
| 412 |
{status?.plan === 'free' && (
|
| 413 |
<Link href="/scraper" className="block w-full text-center py-2 bg-indigo-500/10 hover:bg-indigo-500 text-indigo-500 hover:text-white text-[10px] font-black tracking-widest rounded-lg transition-all border border-indigo-500/20 shadow-lg shadow-indigo-500/10">
|
| 414 |
UPGRADE NOW
|
|
|
|
| 469 |
)}
|
| 470 |
</div>
|
| 471 |
|
| 472 |
+
{/* View Full Plan Entitlements Submenu Trigger */}
|
| 473 |
+
<button
|
| 474 |
+
type="button"
|
| 475 |
+
onClick={() => setShowEntitlementsFlyout(!showEntitlementsFlyout)}
|
| 476 |
+
className="w-full flex items-center justify-between p-2 rounded-xl bg-white/[0.04] hover:bg-white/[0.08] border border-white/10 hover:border-indigo-500/40 text-[11px] font-bold text-foreground transition-all cursor-pointer group shadow-xs"
|
| 477 |
+
>
|
| 478 |
+
<span className="flex items-center gap-1.5 text-indigo-400 group-hover:text-indigo-300">
|
| 479 |
+
<Sparkles size={12} />
|
| 480 |
+
<span>All Entitlements</span>
|
| 481 |
+
</span>
|
| 482 |
+
<span className="text-[10px] text-foreground/40 group-hover:text-foreground">
|
| 483 |
+
{showEntitlementsFlyout ? 'Close ✕' : 'Details →'}
|
| 484 |
+
</span>
|
| 485 |
+
</button>
|
| 486 |
+
|
| 487 |
+
{/* Floating Submenu Popover (Rendered Outside the Sidebar) */}
|
| 488 |
+
{showEntitlementsFlyout && (
|
| 489 |
+
<div className="fixed md:absolute left-4 md:left-[calc(100%+14px)] bottom-4 z-[999] w-[calc(100vw-32px)] sm:w-96 bg-[#0B0F1C]/98 backdrop-blur-2xl border border-indigo-500/40 rounded-2xl p-4 sm:p-5 shadow-2xl text-foreground space-y-4 animate-in fade-in zoom-in-95 duration-150">
|
| 490 |
+
<div className="flex items-center justify-between pb-3 border-b border-white/10">
|
| 491 |
+
<div className="flex items-center gap-2">
|
| 492 |
+
<div className="p-1.5 rounded-lg bg-indigo-500/10 text-indigo-400">
|
| 493 |
+
<ShieldCheck size={16} />
|
| 494 |
+
</div>
|
| 495 |
+
<div>
|
| 496 |
+
<div className="text-xs font-bold text-white">Full Plan Entitlements</div>
|
| 497 |
+
<div className="text-[10px] text-foreground/50">Active Tier: <span className="text-indigo-400 font-bold uppercase">{status?.plan || 'Free'}</span></div>
|
| 498 |
+
</div>
|
| 499 |
+
</div>
|
| 500 |
+
<button
|
| 501 |
+
type="button"
|
| 502 |
+
onClick={() => setShowEntitlementsFlyout(false)}
|
| 503 |
+
className="text-foreground/40 hover:text-white p-1 rounded-lg hover:bg-white/5 transition-colors cursor-pointer"
|
| 504 |
+
>
|
| 505 |
+
<X size={15} />
|
| 506 |
+
</button>
|
| 507 |
+
</div>
|
| 508 |
+
|
| 509 |
+
{/* 10 Package Features Matrix */}
|
| 510 |
+
<div className="space-y-2 text-xs max-h-[55vh] overflow-y-auto custom-scrollbar pr-1">
|
| 511 |
+
<div className="p-2.5 rounded-xl bg-white/[0.03] border border-white/5 flex items-center justify-between">
|
| 512 |
+
<span className="text-foreground/60 text-[11px]">1. Telegram Accounts</span>
|
| 513 |
+
<span className="font-bold text-white text-[11px] font-mono">{status?.max_accounts || 1} Allowed</span>
|
| 514 |
+
</div>
|
| 515 |
+
|
| 516 |
+
<div className="p-2.5 rounded-xl bg-white/[0.03] border border-white/5 flex items-center justify-between">
|
| 517 |
+
<span className="text-foreground/60 text-[11px]">2. Daily Campaigns</span>
|
| 518 |
+
<span className="font-bold text-white text-[11px] font-mono">{status?.daily_campaign_count || 0} / {status?.max_daily_campaigns || 20}</span>
|
| 519 |
+
</div>
|
| 520 |
+
|
| 521 |
+
<div className="p-2.5 rounded-xl bg-white/[0.03] border border-white/5 flex items-center justify-between">
|
| 522 |
+
<span className="text-foreground/60 text-[11px]">3. Scraper Power</span>
|
| 523 |
+
<span className="font-bold text-white text-[11px] font-mono">{status?.scrape_limit || 50} groups / search</span>
|
| 524 |
+
</div>
|
| 525 |
+
|
| 526 |
+
<div className="p-2.5 rounded-xl bg-white/[0.03] border border-white/5 flex items-center justify-between">
|
| 527 |
+
<span className="text-foreground/60 text-[11px]">4. AI Keyword Suggestions</span>
|
| 528 |
+
<span className="font-bold text-white text-[11px] font-mono">{status?.ai_keyword_cap || 5} per prompt</span>
|
| 529 |
+
</div>
|
| 530 |
+
|
| 531 |
+
<div className="p-2.5 rounded-xl bg-white/[0.03] border border-white/5 flex items-center justify-between">
|
| 532 |
+
<span className="text-foreground/60 text-[11px]">5. Saved Templates</span>
|
| 533 |
+
<span className="font-bold text-white text-[11px] font-mono">{status?.template_count || 0} / {status?.max_templates || 1}</span>
|
| 534 |
+
</div>
|
| 535 |
+
|
| 536 |
+
<div className="p-2.5 rounded-xl bg-white/[0.03] border border-white/5 flex items-center justify-between">
|
| 537 |
+
<span className="text-foreground/60 text-[11px]">6. Fleet Compare & Audit</span>
|
| 538 |
+
<span className={`font-bold text-[11px] ${status?.has_fleet_compare ? 'text-emerald-400' : 'text-foreground/30'}`}>
|
| 539 |
+
{status?.has_fleet_compare ? '✓ Unlocked' : '🔒 Locked (Basic+)'}
|
| 540 |
+
</span>
|
| 541 |
+
</div>
|
| 542 |
+
|
| 543 |
+
<div className="p-2.5 rounded-xl bg-white/[0.03] border border-white/5 flex items-center justify-between">
|
| 544 |
+
<span className="text-foreground/60 text-[11px]">7. Delivery Speed Modes</span>
|
| 545 |
+
<span className="font-bold text-indigo-300 text-[11px] capitalize truncate max-w-[170px] text-right">
|
| 546 |
+
{status?.allowed_speeds?.join(', ') || 'Balanced'}
|
| 547 |
+
</span>
|
| 548 |
+
</div>
|
| 549 |
+
|
| 550 |
+
<div className="p-2.5 rounded-xl bg-white/[0.03] border border-white/5 flex items-center justify-between">
|
| 551 |
+
<span className="text-foreground/60 text-[11px]">8. Spintax Generator</span>
|
| 552 |
+
<span className={`font-bold text-[11px] ${status?.has_spintax ? 'text-emerald-400' : 'text-foreground/30'}`}>
|
| 553 |
+
{status?.has_spintax ? '✓ Unlocked' : '🔒 Locked (Basic+)'}
|
| 554 |
+
</span>
|
| 555 |
+
</div>
|
| 556 |
+
|
| 557 |
+
<div className="p-2.5 rounded-xl bg-white/[0.03] border border-white/5 flex items-center justify-between">
|
| 558 |
+
<span className="text-foreground/60 text-[11px]">9. Bulk Join Minimizer</span>
|
| 559 |
+
<span className={`font-bold text-[11px] ${status?.has_fleet_compare ? 'text-emerald-400' : 'text-foreground/30'}`}>
|
| 560 |
+
{status?.has_fleet_compare ? '✓ Unlocked' : '🔒 Locked (Basic+)'}
|
| 561 |
+
</span>
|
| 562 |
+
</div>
|
| 563 |
+
|
| 564 |
+
<div className="p-2.5 rounded-xl bg-white/[0.03] border border-white/5 flex items-center justify-between">
|
| 565 |
+
<span className="text-foreground/60 text-[11px]">10. Leads CSV Export</span>
|
| 566 |
+
<span className="font-bold text-emerald-400 text-[11px]">✓ Full Export</span>
|
| 567 |
+
</div>
|
| 568 |
+
</div>
|
| 569 |
+
|
| 570 |
+
{/* Upgrade CTA if not on highest plan */}
|
| 571 |
+
{status?.plan !== 'unlimited' && (
|
| 572 |
+
<button
|
| 573 |
+
type="button"
|
| 574 |
+
onClick={() => {
|
| 575 |
+
setShowEntitlementsFlyout(false);
|
| 576 |
+
window.dispatchEvent(new Event('open-monetization-modal'));
|
| 577 |
+
}}
|
| 578 |
+
className="w-full py-2.5 rounded-xl bg-indigo-500 hover:bg-indigo-600 text-white font-bold text-xs transition-colors shadow-md flex items-center justify-center gap-1.5 cursor-pointer"
|
| 579 |
+
>
|
| 580 |
+
<Sparkles size={13} />
|
| 581 |
+
<span>Upgrade Plan / Extend Limits</span>
|
| 582 |
+
</button>
|
| 583 |
+
)}
|
| 584 |
+
</div>
|
| 585 |
+
)}
|
| 586 |
+
|
| 587 |
<div className="pt-2 border-t border-border/50">
|
| 588 |
<div className="text-[10px] text-foreground/30 uppercase tracking-[0.2em] font-bold">Session</div>
|
| 589 |
<div className="text-xs text-foreground/60 font-semibold truncate mt-0.5">{user.username}</div>
|
frontend/src/components/SpintaxModal.tsx
CHANGED
|
@@ -327,11 +327,18 @@ export function SpintaxModal({ isOpen, onClose, initialText, onApply }: SpintaxM
|
|
| 327 |
const [isAiLoading, setIsAiLoading] = useState(false);
|
| 328 |
const [aiNote, setAiNote] = useState('');
|
| 329 |
const [configuredModel, setConfiguredModel] = useState('');
|
|
|
|
| 330 |
|
| 331 |
useEffect(() => {
|
| 332 |
if (isOpen) {
|
| 333 |
setText(initialText || '');
|
| 334 |
setAiNote('');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
try {
|
| 336 |
const m = localStorage.getItem('arkitel_ai_model');
|
| 337 |
if (m) {
|
|
@@ -364,6 +371,11 @@ export function SpintaxModal({ isOpen, onClose, initialText, onApply }: SpintaxM
|
|
| 364 |
|
| 365 |
const handleAutoSpintax = async () => {
|
| 366 |
if (!text.trim()) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
|
| 368 |
let storedKey = '';
|
| 369 |
let storedModel = 'meta-llama/llama-3.3-70b-instruct';
|
|
@@ -401,24 +413,20 @@ export function SpintaxModal({ isOpen, onClose, initialText, onApply }: SpintaxM
|
|
| 401 |
setAiNote(`Spun with AI (${shortModel.replace(/-instruct|-chat/g, '')}) • Paragraphs & spacing formatted`);
|
| 402 |
setTimeout(() => setAiNote(''), 4000);
|
| 403 |
} else {
|
| 404 |
-
|
| 405 |
-
const formatted = formatMessageParagraphsAndSpacing(spun);
|
| 406 |
-
setText(formatted);
|
| 407 |
-
setAiNote(data.detail || 'Used local Spintax dictionary.');
|
| 408 |
-
setTimeout(() => setAiNote(''), 4000);
|
| 409 |
}
|
| 410 |
} catch (e: any) {
|
| 411 |
-
|
| 412 |
-
const formatted = formatMessageParagraphsAndSpacing(spun);
|
| 413 |
-
setText(formatted);
|
| 414 |
-
setAiNote('Used local Spintax dictionary.');
|
| 415 |
-
setTimeout(() => setAiNote(''), 3000);
|
| 416 |
} finally {
|
| 417 |
setIsAiLoading(false);
|
| 418 |
}
|
| 419 |
};
|
| 420 |
|
| 421 |
const handleInstantSpin = () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
const spun = generateSmartSpintax(text);
|
| 423 |
const formatted = formatMessageParagraphsAndSpacing(spun);
|
| 424 |
setText(formatted);
|
|
@@ -444,6 +452,12 @@ export function SpintaxModal({ isOpen, onClose, initialText, onApply }: SpintaxM
|
|
| 444 |
alert("Please fix unbalanced braces before applying.");
|
| 445 |
return;
|
| 446 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
onApply(text);
|
| 448 |
onClose();
|
| 449 |
};
|
|
@@ -533,9 +547,23 @@ export function SpintaxModal({ isOpen, onClose, initialText, onApply }: SpintaxM
|
|
| 533 |
</button>
|
| 534 |
|
| 535 |
{aiNote ? (
|
| 536 |
-
<
|
| 537 |
-
{aiNote}
|
| 538 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 539 |
) : null}
|
| 540 |
</div>
|
| 541 |
|
|
|
|
| 327 |
const [isAiLoading, setIsAiLoading] = useState(false);
|
| 328 |
const [aiNote, setAiNote] = useState('');
|
| 329 |
const [configuredModel, setConfiguredModel] = useState('');
|
| 330 |
+
const [userPlan, setUserPlan] = useState<string>('free');
|
| 331 |
|
| 332 |
useEffect(() => {
|
| 333 |
if (isOpen) {
|
| 334 |
setText(initialText || '');
|
| 335 |
setAiNote('');
|
| 336 |
+
apiFetch('/api/monetization/status')
|
| 337 |
+
.then(r => r.ok ? r.json() : null)
|
| 338 |
+
.then(d => {
|
| 339 |
+
if (d?.plan) setUserPlan(d.plan.toLowerCase());
|
| 340 |
+
})
|
| 341 |
+
.catch(() => {});
|
| 342 |
try {
|
| 343 |
const m = localStorage.getItem('arkitel_ai_model');
|
| 344 |
if (m) {
|
|
|
|
| 371 |
|
| 372 |
const handleAutoSpintax = async () => {
|
| 373 |
if (!text.trim()) return;
|
| 374 |
+
|
| 375 |
+
if (userPlan === 'free') {
|
| 376 |
+
setAiNote('Dynamic AI Spintax is exclusive to upgraded accounts (Growth Basic and higher). Upgrade your plan to use Spintax.');
|
| 377 |
+
return;
|
| 378 |
+
}
|
| 379 |
|
| 380 |
let storedKey = '';
|
| 381 |
let storedModel = 'meta-llama/llama-3.3-70b-instruct';
|
|
|
|
| 413 |
setAiNote(`Spun with AI (${shortModel.replace(/-instruct|-chat/g, '')}) • Paragraphs & spacing formatted`);
|
| 414 |
setTimeout(() => setAiNote(''), 4000);
|
| 415 |
} else {
|
| 416 |
+
setAiNote(data.detail || 'Spintax is exclusive to upgraded accounts.');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
}
|
| 418 |
} catch (e: any) {
|
| 419 |
+
setAiNote(e.message || 'Spintax generation failed.');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
} finally {
|
| 421 |
setIsAiLoading(false);
|
| 422 |
}
|
| 423 |
};
|
| 424 |
|
| 425 |
const handleInstantSpin = () => {
|
| 426 |
+
if (userPlan === 'free') {
|
| 427 |
+
setAiNote('Spintax rotation is exclusive to upgraded accounts (Growth Basic and higher). Upgrade your plan to use Spintax.');
|
| 428 |
+
return;
|
| 429 |
+
}
|
| 430 |
const spun = generateSmartSpintax(text);
|
| 431 |
const formatted = formatMessageParagraphsAndSpacing(spun);
|
| 432 |
setText(formatted);
|
|
|
|
| 452 |
alert("Please fix unbalanced braces before applying.");
|
| 453 |
return;
|
| 454 |
}
|
| 455 |
+
const hasSpintax = text.includes('{') && text.includes('|') && text.includes('}');
|
| 456 |
+
if (userPlan === 'free' && hasSpintax) {
|
| 457 |
+
setAiNote("Spintax rotation requires a Basic plan or higher. Upgrade to Growth Basic or remove Spintax braces before inserting.");
|
| 458 |
+
alert("Dynamic Spintax rotation is exclusive to upgraded accounts (Growth Basic and higher). Please upgrade your plan or remove Spintax braces before inserting.");
|
| 459 |
+
return;
|
| 460 |
+
}
|
| 461 |
onApply(text);
|
| 462 |
onClose();
|
| 463 |
};
|
|
|
|
| 547 |
</button>
|
| 548 |
|
| 549 |
{aiNote ? (
|
| 550 |
+
<div className="flex flex-wrap items-center gap-2">
|
| 551 |
+
<span className={`text-[11px] font-semibold px-2 animate-in fade-in ${aiNote.toLowerCase().includes('upgrade') || aiNote.toLowerCase().includes('locked') ? 'text-amber-400' : 'text-emerald-400'}`}>
|
| 552 |
+
{aiNote}
|
| 553 |
+
</span>
|
| 554 |
+
{aiNote.toLowerCase().includes('upgrade') && (
|
| 555 |
+
<button
|
| 556 |
+
type="button"
|
| 557 |
+
onClick={() => {
|
| 558 |
+
onClose();
|
| 559 |
+
window.dispatchEvent(new CustomEvent('open_upgrade_modal'));
|
| 560 |
+
}}
|
| 561 |
+
className="px-2.5 py-1 rounded-lg bg-indigo-500 hover:bg-indigo-400 text-white font-bold text-[10px] shadow-sm transition-all cursor-pointer"
|
| 562 |
+
>
|
| 563 |
+
Upgrade Plan
|
| 564 |
+
</button>
|
| 565 |
+
)}
|
| 566 |
+
</div>
|
| 567 |
) : null}
|
| 568 |
</div>
|
| 569 |
|