Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
573 changes: 573 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Central API utility - reads VITE_API_URL in production, falls back to localhost
const BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:5000';

async function apiFetch(path, options = {}) {
const res = await fetch(`${BASE_URL}${path}`, {
headers: { 'Content-Type': 'application/json', ...options.headers },
...options,
});
if (!res.ok) {
const err = await res.json().catch(() => ({ error: 'Request failed' }));
throw new Error(err.error || `HTTP ${res.status}`);
}
return res.json();
}

// ── Users ──────────────────────────────────────────
export const getUser = (userId) => apiFetch(`/users/${userId}`);
export const createUser = (data) => apiFetch('/users/', { method: 'POST', body: JSON.stringify(data) });

// ── Claims ─────────────────────────────────────────
export const getClaims = (userId) => apiFetch(`/claims/${userId}`);
export const fileClaim = (data) => apiFetch('/claims/file', { method: 'POST', body: JSON.stringify(data) });

// ── Premiums ───────────────────────────────────────
export const getPremiums = (userId) => apiFetch(`/premiums/${userId}`);
export const payPremium = (data) => apiFetch('/premiums/pay', { method: 'POST', body: JSON.stringify(data) });
export const getLossRatio = () => apiFetch('/premiums/stats/loss-ratio');

// ── Bonuses ────────────────────────────────────────
export const getBonuses = (userId) => apiFetch(`/bonuses/${userId}`);

// ── Payouts ────────────────────────────────────────
export const settlePayouts = () => apiFetch('/payouts/settle', { method: 'POST' });

// ── Income ─────────────────────────────────────────
export const getIncome = (userId) => apiFetch(`/income/${userId}`);
export const addIncome = (userId, data) => apiFetch(`/income/${userId}`, { method: 'POST', body: JSON.stringify(data) });
63 changes: 36 additions & 27 deletions src/pages/Bonus.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import { Card, SectionTitle, InfoRow, Divider, Badge, ProgressBar, PrimaryBtn, SecondaryBtn } from '../components/ui';
import {
Trophy,
Expand All @@ -13,22 +13,27 @@ import {
ArrowUpRight,
ChevronRight
} from 'lucide-react';
import { getBonuses } from '../api';

const bonus = {
monthsActive: 4,
weeksNoClaims: 18,
targetWeeks: 24,
bonusRate: 'Level 2 Accelerator (1.5x Multiplier)',
projectedBonus: 1240,
bonusDate: 'Jun 4, 2026',
history: [
{ id: 'BON-012', period: 'Jan–Jun 2025', status: 'PAID', amount: 1840, claims: 0 },
{ id: 'BON-008', period: 'Jul–Dec 2024', status: 'PAID', amount: 920, claims: 1 },
]
};
const TARGET_WEEKS = 24;

export default function Bonus() {
const progressPercent = (bonus.weeksNoClaims / bonus.targetWeeks) * 100;
const [bonusHistory, setBonusHistory] = useState([]);
const [loading, setLoading] = useState(true);

useEffect(() => {
const activeUser = localStorage.getItem('USER_ID') || 'u1';
getBonuses(activeUser)
.then(setBonusHistory)
.finally(() => setLoading(false));
}, []);

// Derive metrics from live data
const weeksNoClaims = bonusHistory.length ? bonusHistory[0].weeks_no_claims || 18 : 18;
const projectedBonus = bonusHistory.length ? bonusHistory[0].projected_bonus || 1240 : 1240;
const progressPercent = (weeksNoClaims / TARGET_WEEKS) * 100;

if (loading) return <div className="text-[#8892a4] p-10 text-center">Loading bonus data...</div>;

return (
<div className="space-y-10 animate-in fade-in duration-800">
Expand Down Expand Up @@ -57,15 +62,15 @@ export default function Bonus() {
<Trophy size={28} />
</div>
<h2 className="text-[24px] font-extrabold" style={{ fontFamily: "'Sora', sans-serif" }}>Accelerator Multiplier</h2>
<p className="text-[#8892a4] text-[13px] font-semibold">{bonus.bonusRate}</p>
<p className="text-[#8892a4] text-[13px] font-semibold">1.5x</p>
</div>

<div className="text-right">
<p className="text-[#8892a4] text-[10px] uppercase font-bold tracking-widest leading-none mb-1 text-center">Weeks Safe</p>
<p className="text-[42px] font-extrabold text-[#f1f5f9] leading-none mb-2" style={{ fontFamily: "'Sora', sans-serif" }}>
{bonus.weeksNoClaims}<span className="text-[#8892a4] text-[24px]"> / {bonus.targetWeeks}</span>
{weeksNoClaims}<span className="text-[#8892a4] text-[24px]"> / {TARGET_WEEKS}</span>
</p>
<Badge variant="green">STREAK: 18 WKS</Badge>
<Badge variant="green">STREAK: {weeksNoClaims} WKS</Badge>
</div>
</div>

Expand All @@ -80,18 +85,18 @@ export default function Bonus() {
<ProgressBar pct={progressPercent} color="linear-gradient(90deg,#e8602c,#f5c518)" />
<div className="flex justify-between text-[11px] text-[#8892a4] px-1 font-bold">
<span>START</span>
<span>PAID ON {bonus.bonusDate.toUpperCase()}</span>
<span>PAID UPON {TARGET_WEEKS} WEEKS</span>
</div>
</div>

<div className="grid grid-cols-2 gap-6 pt-2">
<div className="p-5 rounded-2xl border border-dashed border-[#2a3448] space-y-1">
<p className="text-[#7a8fa8] text-[11px] font-bold uppercase tracking-wider">Projected Bonus</p>
<p className="text-[22px] font-extrabold text-[#f1f5f9]">₹{bonus.projectedBonus.toLocaleString('en-IN')}</p>
<p className="text-[22px] font-extrabold text-[#f1f5f9]">₹{projectedBonus.toLocaleString('en-IN')}</p>
</div>
<div className="p-5 rounded-2xl border border-dashed border-[#2a3448] space-y-1">
<p className="text-[#7a8fa8] text-[11px] font-bold uppercase tracking-wider">Next Payout</p>
<p className="text-[22px] font-extrabold text-[#f59e0b]">{bonus.bonusDate}</p>
<p className="text-[#7a8fa8] text-[11px] font-bold uppercase tracking-wider">Next Payout Status</p>
<p className="text-[17px] font-extrabold text-[#f59e0b]">Building Streak</p>
</div>
</div>
</Card>
Expand Down Expand Up @@ -147,27 +152,31 @@ export default function Bonus() {
<SectionTitle className="px-0 pt-0">Past Bonuses Received</SectionTitle>
<Card className="p-0 overflow-hidden border-[#2a3448]">
<div className="flex flex-col">
{bonus.history.map((item, index) => (
{bonusHistory.length === 0 ? (
<div className="p-10 text-center text-[#8892a4] font-bold text-[14px]">
No bonuses received yet.
</div>
) : bonusHistory.map((item, index) => (
<div
key={item.id}
key={item.id || index}
className={`flex flex-col md:flex-row md:items-center justify-between p-6 gap-6 hover:bg-white/[0.01] transition-colors
${index < bonus.history.length - 1 ? 'border-b border-[#2a3448]' : ''}
${index < bonusHistory.length - 1 ? 'border-b border-[#2a3448]' : ''}
`}
>
<div className="flex items-center gap-6">
<div className="w-12 h-12 rounded-2xl bg-[#22c55e1a] flex items-center justify-center border border-[#22c55e22] text-[#22c55e]">
<CircleDollarSign size={24} />
</div>
<div>
<p className="text-[16px] font-bold text-[#f1f5f9] tracking-tight">Semi-Annual Bonus</p>
<p className="text-[12px] text-[#8892a4] font-medium uppercase tracking-wider">{item.period} · Claims: {item.claims}</p>
<p className="text-[16px] font-bold text-[#f1f5f9] tracking-tight">{item.type || 'Semi-Annual Bonus'}</p>
<p className="text-[12px] text-[#8892a4] font-medium uppercase tracking-wider">{item.period || 'Current'} · Claims: {item.claims || 0}</p>
</div>
</div>

<div className="text-right flex items-center justify-between md:justify-end gap-16 w-full md:w-auto">
<div className="text-right">
<p className="text-[20px] font-extrabold text-[#22c55e]" style={{ fontFamily: "'Sora', sans-serif" }}>
₹{item.amount.toLocaleString('en-IN')}
₹{(item.amount || 0).toLocaleString('en-IN')}
</p>
<p className="text-[10px] text-[#8892a4] font-bold text-right uppercase tracking-[0.1em]">PAID ON SCHEDULE</p>
</div>
Expand Down
Loading
Loading