87e9346d62
- NestJS backend with 11 modules: Auth, Employees, Departments, Attendance, Leaves, Payroll, Reimbursements, Announcements, Tax, Reports, Admin - JWT authentication with refresh tokens, role-based access (employee/hr_admin/super_admin) - MongoDB schemas with Mongoose for all entities - PDF payslip generation with pdfkit - OpenTelemetry tracing to SigNoz - Automatic database seeding on first startup - Next.js 14 frontend with App Router, Tailwind CSS - 25 pages covering all employee, HR admin, and super admin workflows - Multi-stage Dockerfile with nginx proxy - test-manifest.json for E2E testing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
165 lines
7.3 KiB
TypeScript
165 lines
7.3 KiB
TypeScript
'use client';
|
|
import { useEffect, useState, useRef } from 'react';
|
|
import { useAuth } from '@/lib/auth-context';
|
|
import { reimbursementsApi } from '@/lib/api';
|
|
import { formatDate, formatCurrency, getStatusColor } from '@/lib/utils';
|
|
import Topbar from '@/components/layout/Topbar';
|
|
|
|
export default function ReimbursementsPage() {
|
|
const { user } = useAuth();
|
|
const [reimbursements, setReimbursements] = useState<any[]>([]);
|
|
const [showForm, setShowForm] = useState(false);
|
|
const [loading, setLoading] = useState(true);
|
|
const [submitting, setSubmitting] = useState(false);
|
|
const [form, setForm] = useState({ category: 'travel', amount: '', description: '' });
|
|
const [receipt, setReceipt] = useState<File | null>(null);
|
|
const fileRef = useRef<HTMLInputElement>(null);
|
|
|
|
const fetchData = async () => {
|
|
if (!user) return;
|
|
try {
|
|
const res = await reimbursementsApi.getAll();
|
|
setReimbursements(res.data.data || []);
|
|
} catch {}
|
|
setLoading(false);
|
|
};
|
|
|
|
useEffect(() => { fetchData(); }, [user]);
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
setSubmitting(true);
|
|
try {
|
|
await reimbursementsApi.create(form, receipt || undefined);
|
|
setShowForm(false);
|
|
setForm({ category: 'travel', amount: '', description: '' });
|
|
setReceipt(null);
|
|
await fetchData();
|
|
} catch (err: any) {
|
|
alert(err.response?.data?.message || 'Failed to submit');
|
|
}
|
|
setSubmitting(false);
|
|
};
|
|
|
|
return (
|
|
<div className="min-h-screen bg-[#F8FAFC]">
|
|
<Topbar title="Reimbursements" />
|
|
<div className="p-6">
|
|
<div className="bg-white rounded-xl shadow-sm border border-gray-100 p-5">
|
|
<div className="flex items-center justify-between mb-4">
|
|
<h3 className="font-semibold text-gray-800">My Reimbursements</h3>
|
|
<button
|
|
onClick={() => setShowForm(!showForm)}
|
|
className="bg-indigo-600 text-white text-sm px-4 py-2 rounded-lg hover:bg-indigo-700 transition"
|
|
>
|
|
+ New Claim
|
|
</button>
|
|
</div>
|
|
|
|
{showForm && (
|
|
<form onSubmit={handleSubmit} className="bg-gray-50 rounded-xl p-5 mb-5 border border-gray-200">
|
|
<h4 className="font-semibold text-gray-700 mb-4">Submit Reimbursement Claim</h4>
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<div>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">Category</label>
|
|
<select
|
|
value={form.category}
|
|
onChange={(e) => setForm({ ...form, category: e.target.value })}
|
|
className="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm"
|
|
>
|
|
<option value="travel">Travel</option>
|
|
<option value="food">Food</option>
|
|
<option value="medical">Medical</option>
|
|
<option value="other">Other</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">Amount (₹)</label>
|
|
<input
|
|
type="number"
|
|
min="1"
|
|
value={form.amount}
|
|
onChange={(e) => setForm({ ...form, amount: e.target.value })}
|
|
required
|
|
className="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm"
|
|
placeholder="Enter amount"
|
|
/>
|
|
</div>
|
|
<div className="md:col-span-2">
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">Description</label>
|
|
<textarea
|
|
value={form.description}
|
|
onChange={(e) => setForm({ ...form, description: e.target.value })}
|
|
required
|
|
rows={2}
|
|
className="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm"
|
|
placeholder="Describe the expense"
|
|
/>
|
|
</div>
|
|
<div className="md:col-span-2">
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">Receipt (PDF/JPG/PNG, max 5MB)</label>
|
|
<input
|
|
ref={fileRef}
|
|
type="file"
|
|
accept=".pdf,.jpg,.jpeg,.png"
|
|
onChange={(e) => setReceipt(e.target.files?.[0] || null)}
|
|
className="w-full text-sm text-gray-500"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div className="flex gap-3 mt-4">
|
|
<button type="submit" disabled={submitting} className="bg-indigo-600 text-white text-sm px-5 py-2 rounded-lg hover:bg-indigo-700 transition disabled:opacity-50">
|
|
{submitting ? 'Submitting...' : 'Submit Claim'}
|
|
</button>
|
|
<button type="button" onClick={() => setShowForm(false)} className="text-gray-600 text-sm px-5 py-2 rounded-lg border border-gray-300 hover:bg-gray-50 transition">
|
|
Cancel
|
|
</button>
|
|
</div>
|
|
</form>
|
|
)}
|
|
|
|
{loading ? (
|
|
<div className="text-center py-8"><div className="animate-spin rounded-full h-6 w-6 border-b-2 border-indigo-600 mx-auto"></div></div>
|
|
) : reimbursements.length === 0 ? (
|
|
<div className="text-center py-12 text-gray-500">
|
|
<p className="text-4xl mb-2">📄</p>
|
|
<p className="font-medium">No reimbursement claims yet</p>
|
|
</div>
|
|
) : (
|
|
<div className="overflow-x-auto">
|
|
<table className="w-full text-sm">
|
|
<thead>
|
|
<tr className="border-b border-gray-100">
|
|
<th className="text-left py-3 text-gray-500 font-medium">Category</th>
|
|
<th className="text-left py-3 text-gray-500 font-medium">Amount</th>
|
|
<th className="text-left py-3 text-gray-500 font-medium">Description</th>
|
|
<th className="text-left py-3 text-gray-500 font-medium">Date</th>
|
|
<th className="text-left py-3 text-gray-500 font-medium">Status</th>
|
|
<th className="text-left py-3 text-gray-500 font-medium">Comment</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{reimbursements.map((r: any) => (
|
|
<tr key={r._id} className="border-b border-gray-50 hover:bg-gray-50">
|
|
<td className="py-3 capitalize">{r.category}</td>
|
|
<td className="py-3 font-medium">{formatCurrency(r.amount)}</td>
|
|
<td className="py-3 max-w-xs truncate">{r.description}</td>
|
|
<td className="py-3">{formatDate(r.createdAt)}</td>
|
|
<td className="py-3">
|
|
<span className={`px-2 py-1 rounded-full text-xs font-medium ${getStatusColor(r.status)}`}>
|
|
{r.status}
|
|
</span>
|
|
</td>
|
|
<td className="py-3 text-gray-500 max-w-xs truncate">{r.reviewComment || '-'}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|