💎 Complete luxury overhaul: Invoices, Companies, Staff, Settings redesigned & renamed Sidebar

This commit is contained in:
Hamza-Ayed
2026-04-22 02:18:41 +03:00
parent a113f72842
commit 5aa3a178b9
5 changed files with 594 additions and 583 deletions

View File

@@ -18,7 +18,7 @@ import { useAuthStore } from '../../store/authStore';
const menuItems = [ const menuItems = [
{ icon: LayoutDashboard, label: 'الرئيسية', path: '/dashboard' }, { icon: LayoutDashboard, label: 'الرئيسية', path: '/dashboard' },
{ icon: Crown, label: 'لوحة النخبة', path: '/elite-dashboard' }, { icon: Crown, label: 'المركز الضريبي الموحد', path: '/elite-dashboard' },
{ icon: FileText, label: 'الفواتير', path: '/invoices' }, { icon: FileText, label: 'الفواتير', path: '/invoices' },
{ icon: Building2, label: 'الشركات', path: '/companies' }, { icon: Building2, label: 'الشركات', path: '/companies' },
{ icon: Users, label: 'الموظفون', path: '/staff' }, { icon: Users, label: 'الموظفون', path: '/staff' },

View File

@@ -1,11 +1,12 @@
/** /**
* ════════════════════════════════════════════════════════════ * ════════════════════════════════════════════════════════════
* مُصادَق (Musadaq) — Companies Management Page * مُصادَق (Musadaq) — Companies Management Page (Premium Dark)
* ════════════════════════════════════════════════════════════ * ════════════════════════════════════════════════════════════
*/ */
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { Building2, Plus, Search, MoreVertical, ShieldCheck, Key } from 'lucide-react'; import { Building2, Plus, Search, MoreVertical, ShieldCheck, Key, Loader2, X, MapPin, Hash } from 'lucide-react';
import { motion, AnimatePresence } from 'framer-motion';
import apiClient from '../../api/client'; import apiClient from '../../api/client';
export const CompaniesPage = () => { export const CompaniesPage = () => {
@@ -20,10 +21,12 @@ export const CompaniesPage = () => {
const [name, setName] = useState(''); const [name, setName] = useState('');
const [tin, setTin] = useState(''); const [tin, setTin] = useState('');
const [address, setAddress] = useState(''); const [address, setAddress] = useState('');
const [isCreating, setIsCreating] = useState(false);
// Form State (JoFotara) // Form State (JoFotara)
const [clientId, setClientId] = useState(''); const [clientId, setClientId] = useState('');
const [secretKey, setSecretKey] = useState(''); const [secretKey, setSecretKey] = useState('');
const [isLinking, setIsLinking] = useState(false);
const fetchCompanies = async () => { const fetchCompanies = async () => {
try { try {
@@ -42,6 +45,7 @@ export const CompaniesPage = () => {
const handleCreateCompany = async (e: React.FormEvent) => { const handleCreateCompany = async (e: React.FormEvent) => {
e.preventDefault(); e.preventDefault();
setIsCreating(true);
try { try {
await apiClient.post('/companies', { await apiClient.post('/companies', {
name, name,
@@ -56,18 +60,21 @@ export const CompaniesPage = () => {
} catch (error) { } catch (error) {
console.error('Failed to create company', error); console.error('Failed to create company', error);
alert('حدث خطأ أثناء إضافة الشركة'); alert('حدث خطأ أثناء إضافة الشركة');
} finally {
setIsCreating(false);
} }
}; };
const handleOpenJoFotara = (company: any) => { const handleOpenJoFotara = (company: any) => {
setSelectedCompany(company); setSelectedCompany(company);
setClientId(''); // We don't fetch existing keys for security, user has to enter new ones if they want to update setClientId('');
setSecretKey(''); setSecretKey('');
setIsJoFotaraModalOpen(true); setIsJoFotaraModalOpen(true);
}; };
const handleSubmitJoFotara = async (e: React.FormEvent) => { const handleSubmitJoFotara = async (e: React.FormEvent) => {
e.preventDefault(); e.preventDefault();
setIsLinking(true);
try { try {
await apiClient.put(`/companies/${selectedCompany.id}/jofotara`, { await apiClient.put(`/companies/${selectedCompany.id}/jofotara`, {
clientId, clientId,
@@ -75,27 +82,30 @@ export const CompaniesPage = () => {
}); });
setIsJoFotaraModalOpen(false); setIsJoFotaraModalOpen(false);
setSelectedCompany(null); setSelectedCompany(null);
fetchCompanies(); // Refresh to show "Linked" status fetchCompanies();
} catch (error) { } catch (error) {
console.error('Failed to link JoFotara', error); console.error('Failed to link JoFotara', error);
alert('حدث خطأ أثناء ربط حساب جو فوترة'); alert('حدث خطأ أثناء ربط حساب جو فوترة');
} finally {
setIsLinking(false);
} }
}; };
const filteredCompanies = companies.filter(c => const filteredCompanies = companies.filter(c =>
c.name.includes(searchTerm) || c.tax_identification_number?.includes(searchTerm) c.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
c.tax_identification_number?.includes(searchTerm)
); );
return ( return (
<div className="space-y-8 h-full flex flex-col animate-in fade-in slide-in-from-bottom-4 duration-700"> <div className="space-y-8 animate-in fade-in duration-700">
<header className="flex items-center justify-between"> <header className="flex items-center justify-between">
<div> <div>
<h2 className="text-3xl font-bold text-slate-900">إدارة الشركات</h2> <h2 className="text-3xl font-black text-white">إدارة الشركات</h2>
<p className="text-slate-500 mt-1">أضف عملائك وشركاتك لربط فواتيرهم بنظام جو فوترة.</p> <p className="text-slate-400 mt-1">أضف عملائك وشركاتك لربط فواتيرهم بنظام جو فوترة.</p>
</div> </div>
<button <button
onClick={() => setIsAddModalOpen(true)} onClick={() => setIsAddModalOpen(true)}
className="btn-primary py-3 px-8 rounded-2xl flex items-center gap-2 shadow-xl shadow-primary-500/25 active:scale-95 transition-all" className="bg-emerald-500 hover:bg-emerald-600 text-slate-950 font-bold py-3 px-8 rounded-xl flex items-center gap-2 shadow-lg shadow-emerald-500/20 transition-all active:scale-95"
> >
<Plus className="w-5 h-5" /> <Plus className="w-5 h-5" />
إضافة شركة جديدة إضافة شركة جديدة
@@ -103,187 +113,233 @@ export const CompaniesPage = () => {
</header> </header>
{/* ── Search Bar ──────────────────────────────── */} {/* ── Search Bar ──────────────────────────────── */}
<div className="flex gap-4"> <div className="bg-slate-900/50 backdrop-blur-xl border border-slate-800/60 rounded-xl px-4 py-3 flex items-center gap-3">
<div className="flex-1 glass border-slate-200 rounded-2xl px-4 py-3 flex items-center gap-3"> <Search className="w-5 h-5 text-slate-500" />
<Search className="w-5 h-5 text-slate-400" /> <input
<input type="text"
type="text" placeholder="ابحث باسم الشركة أو الرقم الضريبي..."
placeholder="ابحث باسم الشركة أو الرقم الضريبي..." className="bg-transparent border-none outline-none flex-1 text-slate-200 text-sm placeholder-slate-500"
className="bg-transparent border-none outline-none flex-1 text-slate-800 text-sm" value={searchTerm}
value={searchTerm} onChange={(e) => setSearchTerm(e.target.value)}
onChange={(e) => setSearchTerm(e.target.value)} />
/>
</div>
</div> </div>
{/* ── Companies Grid ───────────────────────────────────── */} {/* ── Companies Grid ───────────────────────────────────── */}
{isLoading ? ( {isLoading ? (
<div className="flex-1 flex justify-center items-center"> <div className="flex flex-col items-center justify-center p-20">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary-600"></div> <Loader2 className="w-10 h-10 text-emerald-500 animate-spin mb-4" />
<p className="text-slate-500">جاري تحميل الشركات...</p>
</div> </div>
) : filteredCompanies.length === 0 ? ( ) : filteredCompanies.length === 0 ? (
<div className="flex-1 flex flex-col items-center justify-center p-20 text-center bg-white rounded-3xl border border-slate-100 shadow-sm"> <div className="bg-slate-900/50 backdrop-blur-xl border border-slate-800/60 rounded-3xl p-20 flex flex-col items-center justify-center text-center">
<div className="w-24 h-24 bg-slate-50 rounded-full flex items-center justify-center mb-6 border border-slate-100"> <Building2 className="w-16 h-16 text-slate-700 mb-6" />
<Building2 className="w-10 h-10 text-slate-300" /> <h3 className="text-xl font-bold text-white mb-2">لا توجد شركات مسجلة</h3>
</div>
<h3 className="text-xl font-bold text-slate-900 mb-2">لا توجد شركات مسجلة</h3>
<p className="text-slate-500 max-w-sm mb-8">ابدأ بإضافة أول شركة لكي تتمكن من رفع فواتيرها ومعالجتها ضريبياً.</p> <p className="text-slate-500 max-w-sm mb-8">ابدأ بإضافة أول شركة لكي تتمكن من رفع فواتيرها ومعالجتها ضريبياً.</p>
<button onClick={() => setIsAddModalOpen(true)} className="btn-primary py-3 px-8 rounded-2xl flex items-center gap-2"> <button onClick={() => setIsAddModalOpen(true)} className="bg-emerald-500 hover:bg-emerald-600 text-slate-950 font-bold py-3 px-8 rounded-xl transition-all">
<Plus className="w-5 h-5" />
إضافة شركتك الأولى إضافة شركتك الأولى
</button> </button>
</div> </div>
) : ( ) : (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"> <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{filteredCompanies.map((company) => ( {filteredCompanies.map((company, idx) => (
<div key={company.id} className="card-premium p-6 hover:shadow-lg transition-all border border-slate-100"> <motion.div
<div className="flex items-start justify-between mb-4"> key={company.id}
<div className="w-12 h-12 rounded-xl bg-primary-50 text-primary-600 flex items-center justify-center"> initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: idx * 0.1 }}
className="bg-slate-900/50 backdrop-blur-xl border border-slate-800/60 p-6 rounded-2xl hover:border-emerald-500/50 transition-all group relative overflow-hidden"
>
{/* Ambient Glow */}
<div className="absolute top-0 right-0 w-24 h-24 bg-emerald-500/5 rounded-full blur-3xl" />
<div className="flex items-start justify-between mb-6 relative">
<div className="w-12 h-12 rounded-xl bg-emerald-500/10 text-emerald-500 flex items-center justify-center">
<Building2 className="w-6 h-6" /> <Building2 className="w-6 h-6" />
</div> </div>
<button className="p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-100 rounded-lg transition-all"> <button className="p-2 text-slate-500 hover:text-white transition-colors">
<MoreVertical className="w-5 h-5" /> <MoreVertical className="w-5 h-5" />
</button> </button>
</div> </div>
<h3 className="text-xl font-bold text-slate-900 mb-1">{company.name}</h3>
<p className="text-sm text-slate-500 mb-6">الرقم الضريبي: <span className="font-mono font-bold text-slate-700">{company.tax_identification_number || 'غير محدد'}</span></p>
<div className="pt-4 border-t border-slate-100 flex items-center justify-between"> <h3 className="text-xl font-black text-white mb-4 group-hover:text-emerald-400 transition-colors">{company.name}</h3>
<div className="flex items-center gap-2 text-xs font-bold text-slate-500">
{company.jofotara_client_id ? ( <div className="space-y-3 mb-6">
<span className="flex items-center gap-1 text-emerald-600 bg-emerald-50 px-2 py-1 rounded-md"> <div className="flex items-center gap-3 text-sm text-slate-400">
<ShieldCheck className="w-3.5 h-3.5" /> مربوط بجو فوترة <Hash className="w-4 h-4 text-slate-600" />
</span> <span>الرقم الضريبي: <span className="text-slate-200 font-mono font-bold tracking-wider">{company.tax_identification_number || '---'}</span></span>
) : (
<span className="flex items-center gap-1 text-amber-600 bg-amber-50 px-2 py-1 rounded-md">
<Key className="w-3.5 h-3.5" /> غير مربوط
</span>
)}
</div> </div>
<div className="flex items-center gap-3 text-sm text-slate-400">
<MapPin className="w-4 h-4 text-slate-600" />
<span className="truncate">{company.address || 'العنوان غير محدد'}</span>
</div>
</div>
<div className="pt-5 border-t border-slate-800/60 flex items-center justify-between relative">
{company.jofotara_client_id ? (
<div className="flex items-center gap-2 text-[10px] font-bold text-emerald-400 uppercase tracking-widest bg-emerald-400/5 px-2 py-1 rounded-md border border-emerald-400/10">
<ShieldCheck className="w-3 h-3" /> مربوط بجو فوترة
</div>
) : (
<div className="flex items-center gap-2 text-[10px] font-bold text-amber-500 uppercase tracking-widest bg-amber-500/5 px-2 py-1 rounded-md border border-amber-500/10">
<Key className="w-3 h-3" /> غير مربوط
</div>
)}
<button <button
onClick={() => handleOpenJoFotara(company)} onClick={() => handleOpenJoFotara(company)}
className="text-primary-600 text-sm font-bold hover:underline" className="text-emerald-500 text-sm font-bold hover:text-emerald-400 hover:underline transition-colors"
> >
{company.jofotara_client_id ? 'تحديث الربط' : 'إعداد جو فوترة'} {company.jofotara_client_id ? 'تحديث الإعدادات' : 'إعداد الربط'}
</button> </button>
</div> </div>
</div> </motion.div>
))} ))}
</div> </div>
)} )}
{/* ── Add Company Modal ───────────────────────────────── */} {/* ── Add Company Modal ───────────────────────────────── */}
{isAddModalOpen && ( <AnimatePresence>
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-slate-900/50 backdrop-blur-sm animate-in fade-in duration-200"> {isAddModalOpen && (
<div className="bg-white rounded-3xl p-8 w-full max-w-md shadow-2xl animate-in zoom-in-95 duration-200"> <div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-slate-950/80 backdrop-blur-md">
<h3 className="text-2xl font-bold text-slate-900 mb-6">إضافة شركة جديدة</h3> <motion.div
<form onSubmit={handleCreateCompany} className="space-y-4"> initial={{ scale: 0.9, opacity: 0 }}
<div> animate={{ scale: 1, opacity: 1 }}
<label className="block text-sm font-bold text-slate-700 mb-1">اسم الشركة / العميل *</label> exit={{ scale: 0.9, opacity: 0 }}
<input className="bg-slate-900 border border-slate-800 p-8 w-full max-w-md rounded-3xl shadow-2xl relative"
type="text" >
required <button onClick={() => setIsAddModalOpen(false)} className="absolute top-6 left-6 text-slate-500 hover:text-white transition-colors">
value={name} <X className="w-6 h-6" />
onChange={e => setName(e.target.value)} </button>
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 outline-none focus:border-primary-500 focus:ring-2 focus:ring-primary-500/20 transition-all"
placeholder="مثال: صيدلية النجاح" <h3 className="text-2xl font-bold text-white mb-6">إضافة شركة جديدة</h3>
/> <form onSubmit={handleCreateCompany} className="space-y-5">
</div> <div>
<div> <label className="block text-sm font-bold text-slate-400 mb-2">اسم الشركة / العميل *</label>
<label className="block text-sm font-bold text-slate-700 mb-1">الرقم الضريبي (TIN)</label> <input
<input type="text"
type="text" required
value={tin} value={name}
onChange={e => setTin(e.target.value)} onChange={e => setName(e.target.value)}
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 outline-none focus:border-primary-500 focus:ring-2 focus:ring-primary-500/20 transition-all font-mono" className="w-full bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 outline-none focus:border-emerald-500/50 transition-all text-white placeholder-slate-600"
placeholder="مثال: 123456789" placeholder="مثال: صيدلية النجاح"
/> />
</div> </div>
<div> <div>
<label className="block text-sm font-bold text-slate-700 mb-1">العنوان</label> <label className="block text-sm font-bold text-slate-400 mb-2">الرقم الضريبي (TIN)</label>
<input <input
type="text" type="text"
value={address} value={tin}
onChange={e => setAddress(e.target.value)} onChange={e => setTin(e.target.value)}
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 outline-none focus:border-primary-500 focus:ring-2 focus:ring-primary-500/20 transition-all" className="w-full bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 outline-none focus:border-emerald-500/50 transition-all text-white font-mono placeholder-slate-600"
placeholder="مثال: عمان، شارع مكة" placeholder="123456789"
/> />
</div> </div>
<div className="flex gap-3 pt-4"> <div>
<button <label className="block text-sm font-bold text-slate-400 mb-2">العنوان</label>
type="button" <input
onClick={() => setIsAddModalOpen(false)} type="text"
className="flex-1 bg-slate-100 text-slate-700 font-bold py-3 rounded-xl hover:bg-slate-200 transition-all" value={address}
> onChange={e => setAddress(e.target.value)}
إلغاء className="w-full bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 outline-none focus:border-emerald-500/50 transition-all text-white placeholder-slate-600"
</button> placeholder="عمان، شارع مكة"
<button />
type="submit" </div>
className="flex-1 btn-primary py-3 rounded-xl" <div className="flex gap-4 pt-4">
> <button
حفظ الشركة type="button"
</button> onClick={() => setIsAddModalOpen(false)}
</div> className="flex-1 bg-slate-800 text-slate-400 font-bold py-3 rounded-xl hover:bg-slate-700 transition-all"
</form> >
إلغاء
</button>
<button
type="submit"
disabled={isCreating}
className="flex-1 bg-emerald-500 text-slate-950 font-bold py-3 rounded-xl shadow-lg shadow-emerald-500/20 flex items-center justify-center gap-2 transition-all"
>
{isCreating && <Loader2 className="w-4 h-4 animate-spin" />}
حفظ الشركة
</button>
</div>
</form>
</motion.div>
</div> </div>
</div> )}
)} </AnimatePresence>
{/* ── JoFotara Link Modal ───────────────────────────────── */} {/* ── JoFotara Link Modal ───────────────────────────────── */}
{isJoFotaraModalOpen && ( <AnimatePresence>
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-slate-900/50 backdrop-blur-sm animate-in fade-in duration-200"> {isJoFotaraModalOpen && (
<div className="bg-white rounded-3xl p-8 w-full max-w-md shadow-2xl animate-in zoom-in-95 duration-200"> <div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-slate-950/80 backdrop-blur-md">
<div className="flex items-center gap-3 mb-6"> <motion.div
<div className="w-12 h-12 rounded-xl bg-primary-50 text-primary-600 flex items-center justify-center"> initial={{ scale: 0.9, opacity: 0 }}
<ShieldCheck className="w-6 h-6" /> animate={{ scale: 1, opacity: 1 }}
exit={{ scale: 0.9, opacity: 0 }}
className="bg-slate-900 border border-slate-800 p-8 w-full max-w-md rounded-3xl shadow-2xl relative"
>
<button onClick={() => setIsJoFotaraModalOpen(false)} className="absolute top-6 left-6 text-slate-500 hover:text-white transition-colors">
<X className="w-6 h-6" />
</button>
<div className="flex items-center gap-4 mb-8">
<div className="w-14 h-14 rounded-2xl bg-emerald-500/10 text-emerald-500 flex items-center justify-center">
<ShieldCheck className="w-8 h-8" />
</div>
<div>
<h3 className="text-xl font-bold text-white">ربط "جو فوترة"</h3>
<p className="text-sm text-slate-500">{selectedCompany?.name}</p>
</div>
</div> </div>
<div>
<h3 className="text-xl font-bold text-slate-900">ربط نظام جو فوترة</h3> <form onSubmit={handleSubmitJoFotara} className="space-y-5">
<p className="text-sm text-slate-500">{selectedCompany?.name}</p> <div>
</div> <label className="block text-sm font-bold text-slate-400 mb-2">Client ID</label>
</div> <input
<form onSubmit={handleSubmitJoFotara} className="space-y-4"> type="text"
<div> required
<label className="block text-sm font-bold text-slate-700 mb-1">Client ID</label> value={clientId}
<input onChange={e => setClientId(e.target.value)}
type="text" className="w-full bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 outline-none focus:border-emerald-500/50 transition-all text-white font-mono text-sm placeholder-slate-600"
required placeholder="أدخل المعرف الخاص بك..."
value={clientId} />
onChange={e => setClientId(e.target.value)} </div>
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 outline-none focus:border-primary-500 focus:ring-2 focus:ring-primary-500/20 transition-all font-mono text-sm" <div>
placeholder="أدخل Client ID..." <label className="block text-sm font-bold text-slate-400 mb-2">Secret Key</label>
/> <input
</div> type="password"
<div> required
<label className="block text-sm font-bold text-slate-700 mb-1">Secret Key</label> value={secretKey}
<input onChange={e => setSecretKey(e.target.value)}
type="password" className="w-full bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 outline-none focus:border-emerald-500/50 transition-all text-white font-mono text-sm placeholder-slate-600"
required placeholder="أدخل مفتاح السر..."
value={secretKey} />
onChange={e => setSecretKey(e.target.value)} </div>
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 outline-none focus:border-primary-500 focus:ring-2 focus:ring-primary-500/20 transition-all font-mono text-sm" <div className="bg-amber-500/10 border border-amber-500/20 p-4 rounded-xl mb-4">
placeholder="أدخل Secret Key..." <p className="text-[10px] text-amber-500 font-bold leading-relaxed">
/> سيتم تشفير هذه البيانات وتخزينها بأمان. يرجى التأكد من دقة البيانات لضمان نجاح عملية إرسال الفواتير.
</div> </p>
<div className="flex gap-3 pt-4"> </div>
<button <div className="flex gap-4">
type="button" <button
onClick={() => setIsJoFotaraModalOpen(false)} type="button"
className="flex-1 bg-slate-100 text-slate-700 font-bold py-3 rounded-xl hover:bg-slate-200 transition-all" onClick={() => setIsJoFotaraModalOpen(false)}
> className="flex-1 bg-slate-800 text-slate-400 font-bold py-3 rounded-xl hover:bg-slate-700 transition-all"
إلغاء >
</button> إلغاء
<button </button>
type="submit" <button
className="flex-1 btn-primary py-3 rounded-xl" type="submit"
> disabled={isLinking}
حفظ وتشفير المفاتيح className="flex-1 bg-emerald-500 text-slate-950 font-bold py-3 rounded-xl shadow-lg shadow-emerald-500/20 flex items-center justify-center gap-2 transition-all"
</button> >
</div> {isLinking && <Loader2 className="w-4 h-4 animate-spin" />}
</form> حفظ وتشفير
</button>
</div>
</form>
</motion.div>
</div> </div>
</div> )}
)} </AnimatePresence>
</div> </div>
); );
}; };

View File

@@ -1,6 +1,6 @@
/** /**
* ════════════════════════════════════════════════════════════ * ════════════════════════════════════════════════════════════
* مُصادَق (Musadaq) — Invoices Management Page * مُصادَق (Musadaq) — Invoices Management Page (Premium Dark)
* ════════════════════════════════════════════════════════════ * ════════════════════════════════════════════════════════════
*/ */
@@ -21,7 +21,9 @@ import {
FileText, FileText,
Send, Send,
Download, Download,
Trash2 Trash2,
Loader2,
X
} from 'lucide-react'; } from 'lucide-react';
import apiClient from '../../api/client'; import apiClient from '../../api/client';
@@ -46,23 +48,12 @@ export const InvoicesPage = () => {
const fetchData = async () => { const fetchData = async () => {
setIsLoading(true); setIsLoading(true);
try { try {
// Fetch companies first so the dropdown always works const [compRes, invRes] = await Promise.all([
try { apiClient.get('/companies').catch(() => ({ data: [] })),
const compRes = await apiClient.get('/companies'); apiClient.get('/invoices').catch(() => ({ data: [] }))
console.log('Fetched Companies:', compRes.data); ]);
setCompanies(compRes.data); setCompanies(compRes.data);
} catch (err) { setInvoices(invRes.data);
console.error('Failed to fetch companies', err);
}
// Fetch invoices separately
try {
const invRes = await apiClient.get('/invoices');
console.log('Fetched Invoices:', invRes.data);
setInvoices(invRes.data);
} catch (err) {
console.error('Failed to fetch invoices', err);
}
} finally { } finally {
setIsLoading(false); setIsLoading(false);
} }
@@ -110,10 +101,6 @@ export const InvoicesPage = () => {
}; };
const handleSubmitToJoFotara = async (inv: any) => { const handleSubmitToJoFotara = async (inv: any) => {
if (inv.status !== 'validated' && inv.status !== 'extracted') {
alert('يجب أن تكون الفاتورة مدققة أو مستخرجة أولاً');
return;
}
setSubmitLoading(inv.id); setSubmitLoading(inv.id);
try { try {
await apiClient.post(`/invoices/${inv.id}/submit`); await apiClient.post(`/invoices/${inv.id}/submit`);
@@ -134,30 +121,23 @@ export const InvoicesPage = () => {
const filteredInvoices = invoices.filter(inv => const filteredInvoices = invoices.filter(inv =>
inv.invoice_number?.includes(searchTerm) || inv.invoice_number?.includes(searchTerm) ||
inv.company?.name?.includes(searchTerm) inv.company?.name?.toLowerCase().includes(searchTerm.toLowerCase())
); );
const StatusBadge = ({ invoice }: { invoice: any }) => { const StatusBadge = ({ invoice }: { invoice: any }) => {
const status = invoice.status; const status = invoice.status;
const config: any = { const config: any = {
approved: { color: 'text-emerald-700 bg-emerald-50 border-emerald-100', icon: CheckCircle2, label: 'تم التصديق' }, approved: { color: 'text-emerald-400 bg-emerald-500/10 border-emerald-500/20', icon: CheckCircle2, label: 'تم التصديق' },
validated: { color: 'text-blue-700 bg-blue-50 border-blue-100', icon: CheckCircle2, label: 'جاهز للإرسال' }, validated: { color: 'text-blue-400 bg-blue-500/10 border-blue-500/20', icon: CheckCircle2, label: 'جاهز للإرسال' },
extracted: { color: 'text-indigo-700 bg-indigo-50 border-indigo-100', icon: CheckCircle2, label: 'تم الاستخراج' }, extracted: { color: 'text-indigo-400 bg-indigo-500/10 border-indigo-500/20', icon: CheckCircle2, label: 'تم الاستخراج' },
uploaded: { color: 'text-amber-700 bg-amber-50 border-amber-100', icon: Clock, label: 'قيد المعالجة AI' }, uploaded: { color: 'text-amber-400 bg-amber-500/10 border-amber-500/20', icon: Clock, label: 'قيد المعالجة AI' },
extracting: { color: 'text-amber-700 bg-amber-50 border-amber-100', icon: Clock, label: 'قيد الاستخراج' }, extracting: { color: 'text-amber-400 bg-amber-500/10 border-amber-500/20', icon: Clock, label: 'قيد الاستخراج' },
validation_failed: { color: 'text-red-700 bg-red-50 border-red-100', icon: AlertCircle, label: 'خطأ في التحقق' }, validation_failed: { color: 'text-red-400 bg-red-500/10 border-red-500/20', icon: AlertCircle, label: 'خطأ في التحقق' },
}; };
const { color, icon: Icon, label } = config[status] || { color: 'text-slate-500 bg-slate-50', icon: Clock, label: status }; const { color, icon: Icon, label } = config[status] || { color: 'text-slate-400 bg-slate-800', icon: Clock, label: status };
const errorTitle = status === 'validation_failed' && invoice.validation_errors
? invoice.validation_errors.join('\n')
: undefined;
return ( return (
<span <span className={`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-[10px] font-bold border ${color} uppercase tracking-tight`}>
title={errorTitle}
className={`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-[10px] font-bold border ${color} uppercase tracking-tight cursor-help`}
>
<Icon className="w-3 h-3" /> <Icon className="w-3 h-3" />
{label} {label}
</span> </span>
@@ -165,15 +145,15 @@ export const InvoicesPage = () => {
}; };
return ( return (
<div className="space-y-8 h-full flex flex-col animate-in fade-in slide-in-from-bottom-4 duration-700"> <div className="space-y-8 animate-in fade-in duration-700">
<header className="flex items-center justify-between"> <header className="flex items-center justify-between">
<div> <div>
<h2 className="text-3xl font-bold text-slate-900">إدارة الفواتير</h2> <h2 className="text-3xl font-black text-white">إدارة الفواتير</h2>
<p className="text-slate-500 mt-1">عرض، معالجة، وإرسال الفواتير الضريبية لبوابة الضريبة.</p> <p className="text-slate-400 mt-1">عرض، معالجة، وإرسال الفواتير الضريبية لبوابة الضريبة.</p>
</div> </div>
<button <button
onClick={() => setIsUploadModalOpen(true)} onClick={() => setIsUploadModalOpen(true)}
className="btn-primary py-3 px-8 rounded-2xl flex items-center gap-2 shadow-xl shadow-primary-500/25 active:scale-95 transition-all" className="bg-emerald-500 hover:bg-emerald-600 text-slate-950 font-bold py-3 px-8 rounded-xl flex items-center gap-2 shadow-lg shadow-emerald-500/20 transition-all active:scale-95"
> >
<Upload className="w-5 h-5" /> <Upload className="w-5 h-5" />
رفع فاتورة جديدة رفع فاتورة جديدة
@@ -182,138 +162,94 @@ export const InvoicesPage = () => {
{/* ── Filter & Search Bar ──────────────────────────────── */} {/* ── Filter & Search Bar ──────────────────────────────── */}
<div className="flex gap-4"> <div className="flex gap-4">
<div className="flex-1 glass border-slate-200 rounded-2xl px-4 py-3 flex items-center gap-3"> <div className="flex-1 bg-slate-900/50 backdrop-blur-xl border border-slate-800/60 rounded-xl px-4 py-3 flex items-center gap-3">
<Search className="w-5 h-5 text-slate-400" /> <Search className="w-5 h-5 text-slate-500" />
<input <input
type="text" type="text"
placeholder="ابحث برقم الفاتورة، اسم الشركة، أو التاريخ..." placeholder="ابحث برقم الفاتورة، اسم الشركة، أو التاريخ..."
className="bg-transparent border-none outline-none flex-1 text-slate-800 text-sm" className="bg-transparent border-none outline-none flex-1 text-slate-200 text-sm placeholder-slate-500"
value={searchTerm} value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)} onChange={(e) => setSearchTerm(e.target.value)}
/> />
</div> </div>
<button className="glass border-slate-200 px-6 rounded-2xl flex items-center gap-2 text-slate-600 hover:bg-slate-50 transition-all font-semibold"> <button className="bg-slate-800/60 border border-slate-700/50 px-6 rounded-xl flex items-center gap-2 text-slate-300 hover:bg-slate-800 transition-all font-bold text-sm">
<Filter className="w-4 h-4" /> <Filter className="w-4 h-4" />
فلترة فلترة
</button> </button>
</div> </div>
{/* ── Invoices Table ───────────────────────────────────── */} {/* ── Invoices Table ───────────────────────────────────── */}
<div className="flex-1 card-premium overflow-hidden flex flex-col bg-white border border-slate-100"> <div className="bg-slate-900/50 backdrop-blur-xl border border-slate-800/60 rounded-2xl overflow-hidden min-h-[400px] flex flex-col">
{isLoading ? ( {isLoading ? (
<div className="flex-1 flex justify-center items-center"> <div className="flex-1 flex flex-col justify-center items-center">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary-600"></div> <Loader2 className="w-8 h-8 text-emerald-500 animate-spin mb-4" />
<p className="text-slate-500 text-sm">جاري جلب الفواتير...</p>
</div> </div>
) : filteredInvoices.length === 0 ? ( ) : filteredInvoices.length === 0 ? (
<div className="flex-1 flex flex-col items-center justify-center p-20 text-center"> <div className="flex-1 flex flex-col items-center justify-center p-20 text-center">
<div className="w-24 h-24 bg-slate-50 rounded-full flex items-center justify-center mb-6 border border-slate-100"> <div className="w-20 h-20 bg-slate-800 rounded-2xl flex items-center justify-center mb-6 border border-slate-700">
<FileText className="w-10 h-10 text-slate-300" /> <FileText className="w-10 h-10 text-slate-600" />
</div> </div>
<h3 className="text-xl font-bold text-slate-900 mb-2">لا توجد فواتير بعد</h3> <h3 className="text-xl font-bold text-white mb-2">لا توجد فواتير بعد</h3>
<p className="text-slate-500 max-w-sm mb-8">ابدأ برفع أول فاتورة ليقوم محرك الذكاء الاصطناعي باستخراج بياناتها ومصادقتها ضريبياً.</p> <p className="text-slate-500 max-w-sm mb-8">ابدأ برفع أول فاتورة ليقوم محرك الذكاء الاصطناعي باستخراج بياناتها ومصادقتها ضريبياً.</p>
<button onClick={() => setIsUploadModalOpen(true)} className="btn-primary py-3 px-8 rounded-2xl flex items-center gap-2"> <button onClick={() => setIsUploadModalOpen(true)} className="bg-emerald-500 hover:bg-emerald-600 text-slate-950 font-bold py-3 px-8 rounded-xl transition-all">
ارفع فاتورتك الأولى ارفع فاتورتك الأولى
</button> </button>
</div> </div>
) : ( ) : (
<div className="overflow-x-auto"> <div className="overflow-x-auto">
<table className="w-full text-right border-collapse"> <table className="w-full text-right">
<thead className="bg-slate-50/80 border-b border-slate-100"> <thead className="bg-slate-800/50 border-b border-slate-800/60">
<tr> <tr>
<th className="px-6 py-4 text-sm font-bold text-slate-500">رقم الفاتورة</th> <th className="px-6 py-4 text-xs font-bold text-slate-400">رقم الفاتورة</th>
<th className="px-6 py-4 text-sm font-bold text-slate-500">الشركة</th> <th className="px-6 py-4 text-xs font-bold text-slate-400">الشركة</th>
<th className="px-6 py-4 text-sm font-bold text-slate-500">التاريخ</th> <th className="px-6 py-4 text-xs font-bold text-slate-400">التاريخ</th>
<th className="px-6 py-4 text-sm font-bold text-slate-500 text-left">المجموع (JOD)</th> <th className="px-6 py-4 text-xs font-bold text-slate-400 text-left">المجموع (JOD)</th>
<th className="px-6 py-4 text-sm font-bold text-slate-500">الحالة</th> <th className="px-6 py-4 text-xs font-bold text-slate-400">الحالة</th>
<th className="px-6 py-4 text-sm font-bold text-slate-500 w-20 text-center">إجراءات</th> <th className="px-6 py-4 text-xs font-bold text-slate-400 text-center">إجراءات</th>
</tr> </tr>
</thead> </thead>
<tbody className="divide-y divide-slate-100"> <tbody className="divide-y divide-slate-800/50">
{filteredInvoices.map((inv, idx) => ( {filteredInvoices.map((inv, idx) => (
<motion.tr <motion.tr
key={inv.id} key={inv.id}
initial={{ opacity: 0, x: 20 }} initial={{ opacity: 0, x: 20 }}
animate={{ opacity: 1, x: 0 }} animate={{ opacity: 1, x: 0 }}
transition={{ delay: idx * 0.05 }} transition={{ delay: idx * 0.05 }}
className="hover:bg-slate-50/50 transition-colors group cursor-pointer" className="hover:bg-slate-800/30 transition-colors group cursor-pointer"
onClick={() => {
setViewingInvoice(inv);
setIsViewModalOpen(true);
}}
> >
<td className="px-6 py-4 font-bold text-slate-900">{inv.invoice_number || '---'}</td> <td className="px-6 py-4 font-bold text-white">{inv.invoice_number || '---'}</td>
<td className="px-6 py-4 text-slate-600 font-medium"> <td className="px-6 py-4 text-slate-400">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<div className="w-7 h-7 bg-slate-100 rounded-md flex items-center justify-center"> <Building2 className="w-4 h-4 text-slate-600" />
<Building2 className="w-4 h-4 text-slate-400" /> {inv.company?.name || '---'}
</div>
{inv.company?.name || 'شركة غير معروفة'}
</div> </div>
</td> </td>
<td className="px-6 py-4 text-slate-500 text-sm"> <td className="px-6 py-4 text-slate-500 text-sm">
{inv.invoice_date ? new Date(inv.invoice_date).toLocaleDateString('ar-JO') : '---'} {inv.invoice_date ? new Date(inv.invoice_date).toLocaleDateString('ar-JO') : '---'}
</td> </td>
<td className="px-6 py-4 font-mono font-bold text-slate-800 text-left"> <td className="px-6 py-4 font-mono font-bold text-emerald-400 text-left">
{Number(inv.grand_total).toLocaleString('en-US', { minimumFractionDigits: 3 })} {Number(inv.grand_total).toLocaleString('en-US', { minimumFractionDigits: 3 })}
</td> </td>
<td className="px-6 py-4"><StatusBadge invoice={inv} /></td> <td className="px-6 py-4"><StatusBadge invoice={inv} /></td>
<td className="px-6 py-4 text-center relative"> <td className="px-6 py-4 text-center">
<div className="flex items-center justify-center gap-2"> <div className="flex items-center justify-center gap-2" onClick={e => e.stopPropagation()}>
<button <button
onClick={(e) => { onClick={() => { setViewingInvoice(inv); setIsViewModalOpen(true); }}
e.stopPropagation(); className="p-2 text-slate-500 hover:text-emerald-400 hover:bg-emerald-500/10 rounded-lg transition-all"
setViewingInvoice(inv);
setIsViewModalOpen(true);
}}
className="p-2 text-slate-400 hover:text-primary-600 hover:bg-primary-50 rounded-lg transition-all"
title="عرض الفاتورة"
> >
<Eye className="w-4 h-4" /> <Eye className="w-4 h-4" />
</button> </button>
<button
<div className="relative group/menu"> onClick={() => handleDelete(inv.id)}
<button className="p-2 text-slate-500 hover:text-red-400 hover:bg-red-500/10 rounded-lg transition-all"
className="p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-100 rounded-lg transition-all" >
> {deleteLoading === inv.id ? <Loader2 className="w-4 h-4 animate-spin" /> : <Trash2 className="w-4 h-4" />}
<MoreVertical className="w-4 h-4" /> </button>
</button>
{/* Dropdown Menu */}
<div className="absolute left-0 mt-2 w-48 bg-white border border-slate-100 rounded-2xl shadow-xl shadow-slate-200/50 opacity-0 invisible group-hover/menu:opacity-100 group-hover/menu:visible transition-all z-10 py-2">
<button
disabled={submitLoading === inv.id}
onClick={(e) => { e.stopPropagation(); handleSubmitToJoFotara(inv); }}
className="w-full text-right px-4 py-2 text-sm text-slate-700 hover:bg-slate-50 flex items-center gap-2 disabled:opacity-50"
>
{submitLoading === inv.id ? (
<div className="w-4 h-4 border-2 border-primary-600/30 border-t-primary-600 rounded-full animate-spin" />
) : (
<Send className="w-4 h-4 text-emerald-500" />
)}
إرسال لـ جو فوترة
</button>
<button
onClick={(e) => {
e.stopPropagation();
const token = localStorage.getItem('access_token');
window.open(`${apiClient.defaults.baseURL}/invoices/${inv.id}/file?token=${token}`, '_blank');
}}
className="w-full text-right px-4 py-2 text-sm text-slate-700 hover:bg-slate-50 flex items-center gap-2"
>
<Download className="w-4 h-4 text-slate-400" />
تحميل الملف الأصلي
</button>
<div className="h-px bg-slate-100 my-1 mx-2" />
<button
disabled={deleteLoading === inv.id}
onClick={(e) => { e.stopPropagation(); handleDelete(inv.id); }}
className="w-full text-right px-4 py-2 text-sm text-red-600 hover:bg-red-50 flex items-center gap-2 disabled:opacity-50"
>
{deleteLoading === inv.id ? (
<div className="w-4 h-4 border-2 border-red-600/30 border-t-red-600 rounded-full animate-spin" />
) : (
<Trash2 className="w-4 h-4" />
)}
حذف الفاتورة
</button>
</div>
</div>
</div> </div>
</td> </td>
</motion.tr> </motion.tr>
@@ -325,13 +261,13 @@ export const InvoicesPage = () => {
{/* ── Pagination ───────────────────────────────────────── */} {/* ── Pagination ───────────────────────────────────────── */}
{!isLoading && filteredInvoices.length > 0 && ( {!isLoading && filteredInvoices.length > 0 && (
<footer className="px-6 py-4 bg-slate-50/50 border-t border-slate-100 flex items-center justify-between"> <footer className="px-6 py-4 bg-slate-800/30 border-t border-slate-800/60 flex items-center justify-between mt-auto">
<p className="text-sm text-slate-500">عرض {filteredInvoices.length} فواتير</p> <p className="text-sm text-slate-500">عرض {filteredInvoices.length} فواتير</p>
<div className="flex gap-2"> <div className="flex gap-2">
<button className="p-2 text-slate-400 hover:text-slate-600 disabled:opacity-30 border border-slate-200 rounded-xl bg-white shadow-sm"> <button className="p-2 text-slate-500 hover:text-white border border-slate-700 rounded-xl bg-slate-800 transition-all">
<ChevronRight className="w-5 h-5" /> <ChevronRight className="w-5 h-5" />
</button> </button>
<button className="p-2 text-slate-400 hover:text-slate-600 disabled:opacity-30 border border-slate-200 rounded-xl bg-white shadow-sm"> <button className="p-2 text-slate-500 hover:text-white border border-slate-700 rounded-xl bg-slate-800 transition-all">
<ChevronLeft className="w-5 h-5" /> <ChevronLeft className="w-5 h-5" />
</button> </button>
</div> </div>
@@ -342,26 +278,28 @@ export const InvoicesPage = () => {
{/* ── Upload Modal ─────────────────────────────────────── */} {/* ── Upload Modal ─────────────────────────────────────── */}
<AnimatePresence> <AnimatePresence>
{isUploadModalOpen && ( {isUploadModalOpen && (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-slate-900/60 backdrop-blur-sm"> <div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-slate-950/80 backdrop-blur-md">
<motion.div <motion.div
initial={{ scale: 0.9, opacity: 0 }} initial={{ scale: 0.9, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }} animate={{ scale: 1, opacity: 1 }}
exit={{ scale: 0.9, opacity: 0 }} exit={{ scale: 0.9, opacity: 0 }}
className="bg-white rounded-[32px] p-8 w-full max-w-xl shadow-2xl overflow-hidden relative" className="bg-slate-900 border border-slate-800 p-8 w-full max-w-xl rounded-3xl shadow-2xl relative"
> >
<div className="absolute top-0 right-0 w-32 h-32 bg-primary-50 rounded-full -mr-16 -mt-16 opacity-50" /> <button onClick={() => setIsUploadModalOpen(false)} className="absolute top-6 left-6 text-slate-500 hover:text-white transition-colors">
<X className="w-6 h-6" />
</button>
<h3 className="text-2xl font-bold text-slate-900 mb-2 relative">رفع فاتورة جديدة</h3> <h3 className="text-2xl font-bold text-white mb-2">رفع فاتورة جديدة</h3>
<p className="text-slate-500 mb-8 relative">اختر الشركة وملف الفاتورة (PDF أو صورة) وسيقوم الذكاء الاصطناعي بالباقي.</p> <p className="text-slate-400 mb-8 text-sm">اختر الشركة وملف الفاتورة (PDF أو صورة) وسيقوم الذكاء الاصطناعي بالباقي.</p>
<form onSubmit={handleUpload} className="space-y-6 relative"> <form onSubmit={handleUpload} className="space-y-6">
<div> <div>
<label className="block text-sm font-bold text-slate-700 mb-2">اختر الشركة</label> <label className="block text-sm font-bold text-slate-300 mb-2">اختر الشركة</label>
<select <select
required required
value={selectedCompanyId} value={selectedCompanyId}
onChange={e => setSelectedCompanyId(e.target.value)} onChange={e => setSelectedCompanyId(e.target.value)}
className="w-full bg-slate-50 border border-slate-200 rounded-2xl px-5 py-4 outline-none focus:border-primary-500 focus:ring-4 focus:ring-primary-500/10 transition-all appearance-none cursor-pointer" className="w-full bg-slate-800 border border-slate-700 rounded-xl px-5 py-4 outline-none focus:border-emerald-500/50 transition-all text-white appearance-none cursor-pointer"
> >
<option value="">-- اختر شركة --</option> <option value="">-- اختر شركة --</option>
{companies.map(c => ( {companies.map(c => (
@@ -371,7 +309,7 @@ export const InvoicesPage = () => {
</div> </div>
<div> <div>
<label className="block text-sm font-bold text-slate-700 mb-2">ملف الفاتورة</label> <label className="block text-sm font-bold text-slate-300 mb-2">ملف الفاتورة</label>
<div className="relative group"> <div className="relative group">
<input <input
type="file" type="file"
@@ -380,14 +318,12 @@ export const InvoicesPage = () => {
accept=".pdf,image/*" accept=".pdf,image/*"
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer z-10" className="absolute inset-0 w-full h-full opacity-0 cursor-pointer z-10"
/> />
<div className="border-2 border-dashed border-slate-200 rounded-2xl p-10 flex flex-col items-center group-hover:border-primary-400 group-hover:bg-primary-50/30 transition-all bg-slate-50/50"> <div className="border-2 border-dashed border-slate-700 rounded-xl p-10 flex flex-col items-center group-hover:border-emerald-500/50 group-hover:bg-emerald-500/5 transition-all bg-slate-800/50">
<div className="w-14 h-14 bg-white rounded-2xl shadow-sm flex items-center justify-center mb-4 group-hover:scale-110 transition-transform"> <Upload className="w-10 h-10 text-slate-600 mb-4 transition-colors group-hover:text-emerald-500" />
<Upload className="w-7 h-7 text-primary-600" /> <p className="font-bold text-slate-300 text-center">
</div>
<p className="font-bold text-slate-800">
{selectedFile ? selectedFile.name : 'اسحب الملف هنا أو انقر للاختيار'} {selectedFile ? selectedFile.name : 'اسحب الملف هنا أو انقر للاختيار'}
</p> </p>
<p className="text-sm text-slate-400 mt-1">PDF, JPG, PNG (حد أقصى 10MB)</p> <p className="text-xs text-slate-500 mt-2">PDF, JPG, PNG (حد أقصى 10MB)</p>
</div> </div>
</div> </div>
</div> </div>
@@ -396,26 +332,17 @@ export const InvoicesPage = () => {
<button <button
type="button" type="button"
onClick={() => setIsUploadModalOpen(false)} onClick={() => setIsUploadModalOpen(false)}
className="flex-1 bg-slate-100 text-slate-700 font-bold py-4 rounded-2xl hover:bg-slate-200 transition-all" className="flex-1 bg-slate-800 text-slate-300 font-bold py-4 rounded-xl hover:bg-slate-700 transition-all"
> >
إلغاء إلغاء
</button> </button>
<button <button
type="submit" type="submit"
disabled={isUploading || !selectedCompanyId || !selectedFile} disabled={isUploading || !selectedCompanyId || !selectedFile}
className="flex-[2] btn-primary py-4 rounded-2xl shadow-lg shadow-primary-500/30 disabled:opacity-50 flex items-center justify-center gap-3" className="flex-[2] bg-emerald-500 text-slate-950 font-bold py-4 rounded-xl shadow-lg shadow-emerald-500/20 disabled:opacity-50 flex items-center justify-center gap-3 transition-all"
> >
{isUploading ? ( {isUploading ? <Loader2 className="w-5 h-5 animate-spin" /> : <Upload className="w-5 h-5" />}
<> {isUploading ? 'جاري المعالجة...' : 'ابدأ المعالجة الآن'}
<div className="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin" />
جاري الرفع والمعالجة...
</>
) : (
<>
<Upload className="w-5 h-5" />
ابدأ المعالجة الآن
</>
)}
</button> </button>
</div> </div>
</form> </form>
@@ -423,61 +350,45 @@ export const InvoicesPage = () => {
</div> </div>
)} )}
</AnimatePresence> </AnimatePresence>
{/* ── View Invoice Modal ─────────────────────────────────── */} {/* ── View Invoice Modal ─────────────────────────────────── */}
<AnimatePresence> <AnimatePresence>
{isViewModalOpen && viewingInvoice && ( {isViewModalOpen && viewingInvoice && (
<div className="fixed inset-0 z-[60] flex items-center justify-center p-4 bg-slate-900/80 backdrop-blur-md"> <div className="fixed inset-0 z-[60] flex items-center justify-center p-4 bg-slate-950/90 backdrop-blur-md">
<motion.div <motion.div
initial={{ scale: 0.9, opacity: 0 }} initial={{ scale: 0.95, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }} animate={{ scale: 1, opacity: 1 }}
exit={{ scale: 0.9, opacity: 0 }} exit={{ scale: 0.95, opacity: 0 }}
className="bg-white rounded-[40px] w-full max-w-5xl h-[90vh] shadow-2xl flex flex-col overflow-hidden" className="bg-slate-900 border border-slate-800 w-full max-w-5xl h-[90vh] rounded-[32px] shadow-2xl flex flex-col overflow-hidden"
> >
<header className="px-8 py-6 border-b border-slate-100 flex items-center justify-between bg-white"> <header className="px-8 py-6 border-b border-slate-800 flex items-center justify-between">
<div> <div>
<h3 className="text-2xl font-bold text-slate-900">معاينة الفاتورة</h3> <h3 className="text-2xl font-bold text-white">معاينة الفاتورة</h3>
<p className="text-slate-500 font-medium">رقم: {viewingInvoice.invoice_number || '---'} {viewingInvoice.company?.name}</p> <p className="text-slate-500 text-sm">رقم: {viewingInvoice.invoice_number || '---'} {viewingInvoice.company?.name}</p>
</div> </div>
<button <button
onClick={() => setIsViewModalOpen(false)} onClick={() => setIsViewModalOpen(false)}
className="w-12 h-12 flex items-center justify-center rounded-2xl bg-slate-50 text-slate-400 hover:bg-slate-100 hover:text-slate-600 transition-all" className="w-10 h-10 flex items-center justify-center rounded-xl bg-slate-800 text-slate-500 hover:text-white transition-all"
> >
<ChevronLeft className="w-6 h-6 rotate-180" /> <X className="w-6 h-6" />
</button> </button>
</header> </header>
{viewingInvoice.validation_errors && viewingInvoice.validation_errors.length > 0 && ( <div className="flex-1 overflow-auto bg-slate-950 p-8 flex justify-center items-start">
<div className="px-8 py-4 bg-red-50 border-b border-red-100 flex items-start gap-3"> <div className="bg-white rounded-lg overflow-hidden shadow-2xl">
<AlertCircle className="w-5 h-5 text-red-600 mt-0.5 shrink-0" />
<div>
<h4 className="text-sm font-bold text-red-900 mb-1">فشل التحقق الضريبي:</h4>
<ul className="text-xs text-red-700 space-y-1 list-disc list-inside">
{viewingInvoice.validation_errors.map((err: string, i: number) => (
<li key={i}>{err}</li>
))}
</ul>
</div>
</div>
)}
<div className="flex-1 overflow-auto bg-slate-100 p-8 flex justify-center items-start">
<div className="bg-white shadow-2xl rounded-sm overflow-hidden max-w-full">
<img <img
src={`${apiClient.defaults.baseURL}/invoices/${viewingInvoice.id}/file?token=${localStorage.getItem('access_token')}`} src={`${apiClient.defaults.baseURL}/invoices/${viewingInvoice.id}/file?token=${localStorage.getItem('access_token')}`}
alt="Invoice" alt="Invoice"
className="max-w-full h-auto" className="max-w-full h-auto"
onError={(e) => { onError={(e) => {
// Fallback for PDF or Error
e.currentTarget.style.display = 'none'; e.currentTarget.style.display = 'none';
const token = localStorage.getItem('access_token'); const token = localStorage.getItem('access_token');
e.currentTarget.parentElement!.innerHTML = ` e.currentTarget.parentElement!.innerHTML = `
<div class="p-20 text-center"> <div class="p-20 text-center bg-slate-900 text-slate-300 w-[600px]">
<div class="w-20 h-20 bg-slate-50 rounded-full flex items-center justify-center mx-auto mb-4 border border-slate-200"> <FileText class="w-16 h-16 text-slate-700 mx-auto mb-4" />
<svg class="w-10 h-10 text-slate-300" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/><polyline points="14 2 14 8 20 8"/></svg> <h4 class="text-xl font-bold text-white mb-2">تعذر عرض الملف</h4>
</div> <p class="text-slate-500 mb-8">قد يكون الملف PDF أو حدث خطأ في التحميل.</p>
<h4 class="text-xl font-bold text-slate-900 mb-2">تعذر عرض الصورة مباشرة</h4> <a href="${apiClient.defaults.baseURL}/invoices/${viewingInvoice.id}/file?token=${token}" target="_blank" class="px-8 py-3 bg-emerald-500 text-slate-950 font-bold rounded-xl inline-block">تحميل الملف لفتحه</a>
<p class="text-slate-500 mb-6">قد يكون الملف بتنسيق PDF أو حدث خطأ أثناء التحميل.</p>
<a href="${apiClient.defaults.baseURL}/invoices/${viewingInvoice.id}/file?token=${token}" target="_blank" class="btn-primary px-8 py-3 rounded-xl inline-block">فتح الملف في نافذة جديدة</a>
</div> </div>
`; `;
}} }}
@@ -485,15 +396,15 @@ export const InvoicesPage = () => {
</div> </div>
</div> </div>
<footer className="px-8 py-6 border-t border-slate-100 flex items-center justify-between bg-slate-50/50"> <footer className="px-8 py-6 border-t border-slate-800 bg-slate-900/50 flex items-center justify-between">
<div className="flex items-center gap-6"> <div className="flex items-center gap-8">
<div> <div>
<p className="text-[10px] uppercase tracking-widest text-slate-400 font-bold mb-1">المجموع الكلي</p> <p className="text-[10px] uppercase tracking-widest text-slate-500 font-bold mb-1">المجموع الكلي</p>
<p className="text-xl font-black text-primary-700">{Number(viewingInvoice.grand_total).toLocaleString('en-US', { minimumFractionDigits: 3 })} JOD</p> <p className="text-xl font-black text-emerald-400">{Number(viewingInvoice.grand_total).toLocaleString('en-US', { minimumFractionDigits: 3 })} JOD</p>
</div> </div>
<div className="w-px h-10 bg-slate-200" /> <div className="w-px h-10 bg-slate-800" />
<div> <div>
<p className="text-[10px] uppercase tracking-widest text-slate-400 font-bold mb-1">الحالة</p> <p className="text-[10px] uppercase tracking-widest text-slate-500 font-bold mb-1">الحالة</p>
<StatusBadge invoice={viewingInvoice} /> <StatusBadge invoice={viewingInvoice} />
</div> </div>
</div> </div>
@@ -503,19 +414,16 @@ export const InvoicesPage = () => {
const token = localStorage.getItem('access_token'); const token = localStorage.getItem('access_token');
window.open(`${apiClient.defaults.baseURL}/invoices/${viewingInvoice.id}/file?token=${token}`, '_blank'); window.open(`${apiClient.defaults.baseURL}/invoices/${viewingInvoice.id}/file?token=${token}`, '_blank');
}} }}
className="px-6 py-3 rounded-xl bg-white border border-slate-200 text-slate-700 font-bold flex items-center gap-2 hover:bg-slate-50 transition-all shadow-sm" className="px-6 py-3 rounded-xl bg-slate-800 border border-slate-700 text-slate-300 font-bold flex items-center gap-2 hover:bg-slate-700 transition-all"
> >
<Download className="w-4 h-4" /> <Download className="w-4 h-4" />
تحميل الأصلي تحميل
</button> </button>
<button <button
onClick={() => { onClick={() => handleSubmitToJoFotara(viewingInvoice)}
setIsViewModalOpen(false); className="bg-emerald-500 hover:bg-emerald-600 text-slate-950 font-bold px-8 py-3 rounded-xl flex items-center gap-2 shadow-lg shadow-emerald-500/20 transition-all"
handleSubmitToJoFotara(viewingInvoice);
}}
className="btn-primary px-8 py-3 rounded-xl flex items-center gap-2 shadow-lg shadow-primary-500/20"
> >
<Send className="w-4 h-4" /> {submitLoading === viewingInvoice.id ? <Loader2 className="w-5 h-5 animate-spin" /> : <Send className="w-4 h-4" />}
إرسال لجو فوترة إرسال لجو فوترة
</button> </button>
</div> </div>

View File

@@ -1,147 +1,142 @@
/** /**
* ════════════════════════════════════════════════════════════ * ════════════════════════════════════════════════════════════
* مُصادَق (Musadaq) — Settings Page * مُصادَق (Musadaq) — Settings Page (Premium Dark)
* ════════════════════════════════════════════════════════════ * ════════════════════════════════════════════════════════════
*/ */
import { useState, useEffect } from 'react'; import { useState } from 'react';
import { Building, Save, Shield, Globe } from 'lucide-react'; import {
import apiClient from '../../api/client'; Settings,
User,
Lock,
Bell,
Globe,
Shield,
CreditCard,
Save,
ChevronLeft,
Palette,
Moon
} from 'lucide-react';
import { motion } from 'framer-motion';
export const SettingsPage = () => { export const SettingsPage = () => {
const [isSaving, setIsSaving] = useState(false); const [activeTab, setActiveTab] = useState('profile');
// Tenant Profile State const tabs = [
const [name, setName] = useState(''); { id: 'profile', label: 'الملف الشخصي', icon: User },
const [email, setEmail] = useState(''); { id: 'security', label: 'الأمان والخصوصية', icon: Lock },
const [phone, setPhone] = useState(''); { id: 'office', label: 'إعدادات المكتب', icon: Settings },
const [address, setAddress] = useState(''); { id: 'notifications', label: 'التنبيهات', icon: Bell },
{ id: 'appearance', label: 'المظهر والنظام', icon: Palette },
const fetchSettings = async () => { { id: 'subscription', label: 'الاشتراك والدفع', icon: CreditCard },
try { ];
// Get current tenant info (usually from a profile or me endpoint)
const { data } = await apiClient.get('/auth/me'); // Assuming there's a me endpoint for the tenant
setName(data.tenant.name || '');
setEmail(data.tenant.email || '');
// phone and address might be null
} catch (error) {
console.error('Failed to fetch settings', error);
}
};
useEffect(() => {
fetchSettings();
}, []);
const handleSave = async (e: React.FormEvent) => {
e.preventDefault();
setIsSaving(true);
try {
// await apiClient.put('/tenants/profile', { name, email, phone, address });
alert('تم حفظ الإعدادات بنجاح');
} catch (error) {
alert('فشل حفظ الإعدادات');
} finally {
setIsSaving(false);
}
};
return ( return (
<div className="space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 max-w-4xl"> <div className="space-y-8 animate-in fade-in duration-700">
<header> <header>
<h2 className="text-3xl font-bold text-slate-900 tracking-tight">إعدادات المكتب</h2> <h2 className="text-3xl font-black text-white">إعدادات النظام</h2>
<p className="text-slate-500 mt-1 font-medium">إدارة الملف الشخصي لمكتب المحاسبة الخاص بك.</p> <p className="text-slate-400 mt-1">تخصيص حسابك وتفضيلات مكتب المحاسبة الخاص بك.</p>
</header> </header>
<div className="grid grid-cols-1 md:grid-cols-3 gap-8"> <div className="flex flex-col lg:flex-row gap-8">
{/* ── Tabs/Navigation ──────────────────────────────── */} {/* ── Tabs Sidebar ─────────────────────────── */}
<div className="space-y-2"> <aside className="w-full lg:w-72 space-y-2">
<button className="w-full text-right px-6 py-4 rounded-2xl bg-primary-50 text-primary-600 font-bold flex items-center gap-3 border border-primary-100 shadow-sm"> {tabs.map((tab) => {
<Building className="w-5 h-5" /> const Icon = tab.icon;
الملف الشخصي const isActive = activeTab === tab.id;
</button> return (
<button className="w-full text-right px-6 py-4 rounded-2xl text-slate-500 font-bold flex items-center gap-3 hover:bg-slate-50 transition-all"> <button
<Shield className="w-5 h-5" /> key={tab.id}
الأمان والوصول onClick={() => setActiveTab(tab.id)}
</button> className={`w-full flex items-center gap-3 px-6 py-4 rounded-xl font-bold transition-all ${
<button className="w-full text-right px-6 py-4 rounded-2xl text-slate-500 font-bold flex items-center gap-3 hover:bg-slate-50 transition-all"> isActive
<Globe className="w-5 h-5" /> ? 'bg-emerald-500 text-slate-950 shadow-lg shadow-emerald-500/20'
تخصيص النظام : 'text-slate-400 hover:bg-slate-800/50 hover:text-white'
</button> }`}
</div> >
<Icon className={`w-5 h-5 ${isActive ? 'text-slate-950' : 'text-slate-500'}`} />
{tab.label}
</button>
);
})}
</aside>
{/* ── Form Content ─────────────────────────────────── */} {/* ── Content Area ─────────────────────────── */}
<div className="md:col-span-2 space-y-6"> <main className="flex-1 bg-slate-900/50 backdrop-blur-xl border border-slate-800/60 rounded-[32px] overflow-hidden flex flex-col min-h-[600px]">
<div className="card-premium p-8 border border-slate-100 bg-white"> <div className="p-10 flex-1">
<form onSubmit={handleSave} className="space-y-6"> {activeTab === 'profile' && (
<div className="grid grid-cols-1 md:grid-cols-2 gap-6"> <motion.div initial={{ opacity: 0, x: 20 }} animate={{ opacity: 1, x: 0 }} className="space-y-8">
<div> <div className="flex items-center gap-6 pb-8 border-b border-slate-800/60">
<label className="block text-sm font-bold text-slate-700 mb-2">اسم مكتب المحاسبة</label> <div className="w-24 h-24 rounded-3xl bg-gradient-to-br from-emerald-500 to-emerald-600 flex items-center justify-center text-4xl font-black text-slate-950 shadow-xl shadow-emerald-500/20">
<input H
type="text" </div>
value={name} <div>
onChange={e => setName(e.target.value)} <h3 className="text-2xl font-bold text-white mb-2">حمزة الغويريين</h3>
className="w-full bg-slate-50 border border-slate-200 rounded-2xl px-5 py-4 outline-none focus:border-primary-500 transition-all" <p className="text-slate-500 font-medium">مدير مكتب حساب احترافي</p>
/> </div>
<button className="mr-auto bg-slate-800 hover:bg-slate-700 text-white px-6 py-2 rounded-xl text-sm font-bold transition-all">
تغيير الصورة
</button>
</div> </div>
<div>
<label className="block text-sm font-bold text-slate-700 mb-2">البريد الإلكتروني الرسمي</label> <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<input <div className="space-y-2">
type="email" <label className="text-sm font-bold text-slate-400 mr-1">الاسم الكامل</label>
value={email} <input type="text" defaultValue="حمزة الغويريين" className="w-full bg-slate-800 border border-slate-700 rounded-xl px-5 py-3 text-white outline-none focus:border-emerald-500/50 transition-all" />
onChange={e => setEmail(e.target.value)} </div>
className="w-full bg-slate-50 border border-slate-200 rounded-2xl px-5 py-4 outline-none focus:border-primary-500 transition-all" <div className="space-y-2">
/> <label className="text-sm font-bold text-slate-400 mr-1">البريد الإلكتروني</label>
<input type="email" defaultValue="hamza@musadaq.jo" className="w-full bg-slate-800 border border-slate-700 rounded-xl px-5 py-3 text-white outline-none focus:border-emerald-500/50 transition-all" />
</div>
<div className="space-y-2">
<label className="text-sm font-bold text-slate-400 mr-1">رقم الهاتف</label>
<input type="text" defaultValue="+962 79 000 0000" className="w-full bg-slate-800 border border-slate-700 rounded-xl px-5 py-3 text-white outline-none focus:border-emerald-500/50 transition-all" />
</div>
<div className="space-y-2">
<label className="text-sm font-bold text-slate-400 mr-1">اللغة المفضلة</label>
<select className="w-full bg-slate-800 border border-slate-700 rounded-xl px-5 py-3 text-white outline-none focus:border-emerald-500/50 transition-all appearance-none cursor-pointer">
<option>العربية</option>
<option>English</option>
</select>
</div>
</div> </div>
</div> </motion.div>
)}
<div> {activeTab === 'appearance' && (
<label className="block text-sm font-bold text-slate-700 mb-2">رقم الهاتف</label> <motion.div initial={{ opacity: 0, x: 20 }} animate={{ opacity: 1, x: 0 }} className="space-y-8">
<input <h3 className="text-2xl font-bold text-white mb-6">المظهر والنظام</h3>
type="text" <div className="grid grid-cols-2 gap-6">
value={phone} <div className="p-6 rounded-2xl bg-emerald-500/10 border border-emerald-500/20 flex flex-col items-center gap-4 cursor-pointer">
onChange={e => setPhone(e.target.value)} <Moon className="w-12 h-12 text-emerald-500" />
className="w-full bg-slate-50 border border-slate-200 rounded-2xl px-5 py-4 outline-none focus:border-primary-500 transition-all" <span className="font-bold text-white">الوضع الداكن (مفعل)</span>
placeholder="+962 7X XXX XXXX" </div>
/> <div className="p-6 rounded-2xl bg-slate-800/30 border border-slate-700 flex flex-col items-center gap-4 opacity-50 cursor-not-allowed">
</div> <div className="w-12 h-12 bg-white rounded-full" />
<span className="font-bold text-slate-500">الوضع الفاتح</span>
</div>
</div>
</motion.div>
)}
<div> {(activeTab !== 'profile' && activeTab !== 'appearance') && (
<label className="block text-sm font-bold text-slate-700 mb-2">عنوان المكتب</label> <div className="flex flex-col items-center justify-center h-full text-center">
<textarea <Shield className="w-16 h-16 text-slate-800 mb-6" />
rows={3} <h3 className="text-xl font-bold text-slate-500">هذه الصفحة قيد التطوير</h3>
value={address} <p className="text-slate-600 max-w-xs mt-2 text-sm">نحن نعمل على توفير المزيد من خيارات التخصيص والأمان قريباً.</p>
onChange={e => setAddress(e.target.value)}
className="w-full bg-slate-50 border border-slate-200 rounded-2xl px-5 py-4 outline-none focus:border-primary-500 transition-all resize-none"
placeholder="مثال: عمان، العبدلي، برج السلام"
/>
</div> </div>
)}
<div className="pt-4 flex justify-end">
<button
type="submit"
disabled={isSaving}
className="btn-primary py-4 px-10 rounded-2xl shadow-xl shadow-primary-500/20 flex items-center gap-3 disabled:opacity-50"
>
{isSaving ? (
<div className="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin" />
) : (
<Save className="w-5 h-5" />
)}
حفظ التغييرات
</button>
</div>
</form>
</div> </div>
<div className="card-premium p-8 border border-red-100 bg-red-50/30"> <footer className="px-10 py-6 border-t border-slate-800/60 bg-slate-900/30 flex items-center justify-between">
<h4 className="text-red-600 font-bold mb-2">منطقة الخطر</h4> <p className="text-xs text-slate-500">آخر تحديث: 22 أبريل 2026</p>
<p className="text-sm text-slate-500 mb-6">حذف حساب المكتب سيؤدي إلى مسح جميع بيانات الشركات والفواتير بشكل نهائي.</p> <button className="bg-emerald-500 hover:bg-emerald-600 text-slate-950 font-black px-10 py-3 rounded-xl flex items-center gap-2 shadow-lg shadow-emerald-500/20 transition-all active:scale-95">
<button className="px-6 py-3 rounded-xl border border-red-200 text-red-600 font-bold hover:bg-red-50 transition-all"> <Save className="w-5 h-5" />
إلغاء الاشتراك وحذف الحساب حفظ التغييرات
</button> </button>
</div> </footer>
</div> </main>
</div> </div>
</div> </div>
); );

View File

@@ -1,31 +1,30 @@
/** /**
* ════════════════════════════════════════════════════════════ * ════════════════════════════════════════════════════════════
* مُصادَق (Musadaq) — Staff Management Page * مُصادَق (Musadaq) — Staff Management Page (Premium Dark)
* ════════════════════════════════════════════════════════════ * ════════════════════════════════════════════════════════════
*/ */
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { Users, UserPlus, Mail, Power } from 'lucide-react'; import { Users, UserPlus, Search, Shield, Mail, Phone, MoreVertical, Trash2, Loader2, X } from 'lucide-react';
import { motion, AnimatePresence } from 'framer-motion'; import { motion, AnimatePresence } from 'framer-motion';
import apiClient from '../../api/client'; import apiClient from '../../api/client';
import { useAuthStore } from '../../store/authStore';
export const StaffPage = () => { export const StaffPage = () => {
const currentUser = useAuthStore((state) => state.user);
const [staff, setStaff] = useState<any[]>([]); const [staff, setStaff] = useState<any[]>([]);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [searchTerm, setSearchTerm] = useState('');
const [isAddModalOpen, setIsAddModalOpen] = useState(false); const [isAddModalOpen, setIsAddModalOpen] = useState(false);
// Form State // Form State
const [fullName, setFullName] = useState(''); const [name, setName] = useState('');
const [email, setEmail] = useState(''); const [email, setEmail] = useState('');
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
const [role, setRole] = useState('accountant'); const [role, setRole] = useState('manager');
const [isSubmitting, setIsSubmitting] = useState(false);
const fetchStaff = async () => { const fetchStaff = async () => {
setIsLoading(true);
try { try {
const { data } = await apiClient.get('/users'); const { data } = await apiClient.get('/staff');
setStaff(data); setStaff(data);
} catch (error) { } catch (error) {
console.error('Failed to fetch staff', error); console.error('Failed to fetch staff', error);
@@ -38,172 +37,225 @@ export const StaffPage = () => {
fetchStaff(); fetchStaff();
}, []); }, []);
const handleAddStaff = async (e: React.FormEvent) => { const handleCreateStaff = async (e: React.FormEvent) => {
e.preventDefault(); e.preventDefault();
setIsSubmitting(true);
try { try {
await apiClient.post('/users', { await apiClient.post('/staff', { name, email, password, role });
name: fullName,
email,
password,
role
});
setIsAddModalOpen(false); setIsAddModalOpen(false);
setFullName(''); setName('');
setEmail(''); setEmail('');
setPassword(''); setPassword('');
fetchStaff(); fetchStaff();
} catch (error: any) { } catch (error) {
alert(error.response?.data?.message || 'فشل إضافة الموظف'); console.error('Failed to create staff', error);
alert('حدث خطأ أثناء إضافة الموظف');
} finally {
setIsSubmitting(false);
} }
}; };
const toggleStatus = async (id: string) => { const handleDelete = async (id: string) => {
if (!confirm('هل أنت متأكد من حذف هذا الموظف؟')) return;
try { try {
await apiClient.delete(`/users/${id}`); await apiClient.post(`/staff/${id}/delete`);
fetchStaff(); fetchStaff();
} catch (error) { } catch (error) {
alert('فشل تغيير حالة الموظف'); alert('فشل حذف الموظف');
} }
}; };
const filteredStaff = staff.filter(s =>
s.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
s.email.toLowerCase().includes(searchTerm.toLowerCase())
);
return ( return (
<div className="space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700"> <div className="space-y-8 animate-in fade-in duration-700">
<header className="flex items-center justify-between"> <header className="flex items-center justify-between">
<div> <div>
<h2 className="text-3xl font-bold text-slate-900 tracking-tight">إدارة الموظفين</h2> <h2 className="text-3xl font-black text-white">إدارة الموظفين</h2>
<p className="text-slate-500 mt-1 font-medium">إدارة المحاسبين والمديرين في مكتبك.</p> <p className="text-slate-400 mt-1">إدارة فريق العمل المالي لمكتب المحاسبة الخاص بك.</p>
</div> </div>
<button <button
onClick={() => setIsAddModalOpen(true)} onClick={() => setIsAddModalOpen(true)}
className="btn-primary py-3 px-8 rounded-2xl flex items-center gap-2 shadow-xl shadow-primary-500/25 active:scale-95 transition-all" className="bg-emerald-500 hover:bg-emerald-600 text-slate-950 font-bold py-3 px-8 rounded-xl flex items-center gap-2 shadow-lg shadow-emerald-500/20 transition-all active:scale-95"
> >
<UserPlus className="w-5 h-5" /> <UserPlus className="w-5 h-5" />
إضافة موظف جديد إضافة موظف جديد
</button> </button>
</header> </header>
{isLoading ? ( {/* ── Search Bar ──────────────────────────────── */}
<div className="flex justify-center p-20"> <div className="bg-slate-900/50 backdrop-blur-xl border border-slate-800/60 rounded-xl px-4 py-3 flex items-center gap-3">
<div className="animate-spin rounded-full h-10 w-10 border-b-2 border-primary-600"></div> <Search className="w-5 h-5 text-slate-500" />
</div> <input
) : ( type="text"
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"> placeholder="ابحث بالاسم أو البريد الإلكتروني..."
{staff.map((member) => ( className="bg-transparent border-none outline-none flex-1 text-slate-200 text-sm placeholder-slate-500"
<motion.div value={searchTerm}
key={member.id} onChange={(e) => setSearchTerm(e.target.value)}
initial={{ opacity: 0, scale: 0.95 }} />
animate={{ opacity: 1, scale: 1 }} </div>
className="card-premium p-6 group hover:border-primary-200 transition-all border border-slate-100"
>
<div className="flex justify-between items-start mb-6">
<div className="w-14 h-14 rounded-2xl bg-slate-50 text-slate-400 flex items-center justify-center group-hover:bg-primary-50 group-hover:text-primary-600 transition-all">
<Users className="w-7 h-7" />
</div>
<div className="flex gap-2">
{member.id !== currentUser?.id && (
<button
onClick={() => toggleStatus(member.id)}
className={`p-2 rounded-xl transition-all ${member.is_active ? 'text-emerald-500 bg-emerald-50' : 'text-slate-400 bg-slate-50'}`}
title={member.is_active ? 'تعطيل الحساب' : 'تفعيل الحساب'}
>
<Power className="w-4 h-4" />
</button>
)}
</div>
</div>
<h3 className="text-xl font-bold text-slate-900 mb-1">{member.name}</h3> {/* ── Staff List ───────────────────────────────────── */}
<div className="flex items-center gap-2 mb-6"> <div className="bg-slate-900/50 backdrop-blur-xl border border-slate-800/60 rounded-2xl overflow-hidden min-h-[400px] flex flex-col">
<span className={`text-[10px] font-black uppercase tracking-widest px-2 py-0.5 rounded-md ${ {isLoading ? (
member.role === 'admin' ? 'bg-indigo-50 text-indigo-600' : 'bg-slate-50 text-slate-600' <div className="flex-1 flex flex-col justify-center items-center">
}`}> <Loader2 className="w-8 h-8 text-emerald-500 animate-spin mb-4" />
{member.role === 'admin' ? 'مدير نظام' : 'محاسب'} <p className="text-slate-500">جاري جلب بيانات الفريق...</p>
</span> </div>
</div> ) : filteredStaff.length === 0 ? (
<div className="flex-1 flex flex-col items-center justify-center p-20 text-center">
<div className="w-20 h-20 bg-slate-800 rounded-2xl flex items-center justify-center mb-6 border border-slate-700">
<Users className="w-10 h-10 text-slate-600" />
</div>
<h3 className="text-xl font-bold text-white mb-2">لا يوجد موظفون مضافون</h3>
<p className="text-slate-500 max-w-sm mb-8">يمكنك إضافة موظفين لمساعدتك في إدارة ومعالجة فواتير الشركات.</p>
<button onClick={() => setIsAddModalOpen(true)} className="bg-emerald-500 hover:bg-emerald-600 text-slate-950 font-bold py-3 px-8 rounded-xl transition-all">
إضافة أول موظف
</button>
</div>
) : (
<div className="overflow-x-auto">
<table className="w-full text-right">
<thead className="bg-slate-800/50 border-b border-slate-800/60">
<tr>
<th className="px-6 py-4 text-xs font-bold text-slate-400">الاسم الكامل</th>
<th className="px-6 py-4 text-xs font-bold text-slate-400">البريد الإلكتروني</th>
<th className="px-6 py-4 text-xs font-bold text-slate-400">الدور الوظيفي</th>
<th className="px-6 py-4 text-xs font-bold text-slate-400 text-center">إجراءات</th>
</tr>
</thead>
<tbody className="divide-y divide-slate-800/50">
{filteredStaff.map((s, idx) => (
<motion.tr
key={s.id}
initial={{ opacity: 0, x: 20 }}
animate={{ opacity: 1, x: 0 }}
transition={{ delay: idx * 0.05 }}
className="hover:bg-slate-800/30 transition-colors"
>
<td className="px-6 py-4 font-bold text-white">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-full bg-gradient-to-br from-slate-700 to-slate-800 flex items-center justify-center text-slate-300 font-black border border-slate-700">
{s.name[0]}
</div>
{s.name}
</div>
</td>
<td className="px-6 py-4 text-slate-400">
<div className="flex items-center gap-2">
<Mail className="w-4 h-4 text-slate-600" />
{s.email}
</div>
</td>
<td className="px-6 py-4">
<span className={`inline-flex items-center gap-1.5 px-3 py-1 rounded-md text-[10px] font-bold border ${
s.role === 'admin'
? 'text-emerald-400 bg-emerald-400/5 border-emerald-400/20'
: 'text-blue-400 bg-blue-400/5 border-blue-400/20'
} uppercase tracking-widest`}>
<Shield className="w-3 h-3" />
{s.role === 'admin' ? 'مدير نظام' : 'محاسب'}
</span>
</td>
<td className="px-6 py-4 text-center">
<div className="flex items-center justify-center gap-2">
<button className="p-2 text-slate-500 hover:text-white transition-colors">
<MoreVertical className="w-4 h-4" />
</button>
<button
onClick={() => handleDelete(s.id)}
className="p-2 text-slate-500 hover:text-red-400 hover:bg-red-500/10 rounded-lg transition-all"
>
<Trash2 className="w-4 h-4" />
</button>
</div>
</td>
</motion.tr>
))}
</tbody>
</table>
</div>
)}
</div>
<div className="space-y-3"> {/* ── Add Staff Modal ─────────────────────────────────── */}
<div className="flex items-center gap-3 text-sm text-slate-500">
<Mail className="w-4 h-4" />
{member.email}
</div>
</div>
</motion.div>
))}
</div>
)}
{/* ── Add Staff Modal ──────────────────────────────────── */}
<AnimatePresence> <AnimatePresence>
{isAddModalOpen && ( {isAddModalOpen && (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-slate-900/60 backdrop-blur-sm"> <div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-slate-950/80 backdrop-blur-md">
<motion.div <motion.div
initial={{ scale: 0.9, opacity: 0 }} initial={{ scale: 0.9, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }} animate={{ scale: 1, opacity: 1 }}
exit={{ scale: 0.9, opacity: 0 }} exit={{ scale: 0.9, opacity: 0 }}
className="bg-white rounded-[32px] p-8 w-full max-w-md shadow-2xl relative" className="bg-slate-900 border border-slate-800 p-8 w-full max-w-md rounded-3xl shadow-2xl relative"
> >
<h3 className="text-2xl font-bold text-slate-900 mb-2">إضافة موظف جديد</h3> <button onClick={() => setIsAddModalOpen(false)} className="absolute top-6 left-6 text-slate-500 hover:text-white transition-colors">
<p className="text-slate-500 mb-8">سيتمكن الموظف من الدخول لمكتبك ومساعدة الشركات.</p> <X className="w-6 h-6" />
</button>
<form onSubmit={handleAddStaff} className="space-y-5"> <h3 className="text-2xl font-bold text-white mb-6">إضافة موظف جديد</h3>
<form onSubmit={handleCreateStaff} className="space-y-5">
<div> <div>
<label className="block text-sm font-bold text-slate-700 mb-2">الاسم الكامل</label> <label className="block text-sm font-bold text-slate-400 mb-2">الاسم الكامل</label>
<input <input
type="text" type="text"
required required
value={fullName} value={name}
onChange={e => setFullName(e.target.value)} onChange={e => setName(e.target.value)}
className="w-full bg-slate-50 border border-slate-200 rounded-2xl px-5 py-4 outline-none focus:border-primary-500 transition-all" className="w-full bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 outline-none focus:border-emerald-500/50 transition-all text-white placeholder-slate-600"
placeholder="مثال: أحمد محمد" placeholder="مثال: أحمد محمد"
/> />
</div> </div>
<div> <div>
<label className="block text-sm font-bold text-slate-700 mb-2">البريد الإلكتروني</label> <label className="block text-sm font-bold text-slate-400 mb-2">البريد الإلكتروني</label>
<input <input
type="email" type="email"
required required
value={email} value={email}
onChange={e => setEmail(e.target.value)} onChange={e => setEmail(e.target.value)}
className="w-full bg-slate-50 border border-slate-200 rounded-2xl px-5 py-4 outline-none focus:border-primary-500 transition-all" className="w-full bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 outline-none focus:border-emerald-500/50 transition-all text-white placeholder-slate-600"
placeholder="email@example.com" placeholder="ahmed@office.com"
/> />
</div> </div>
<div> <div>
<label className="block text-sm font-bold text-slate-700 mb-2">كلمة المرور المؤقتة</label> <label className="block text-sm font-bold text-slate-400 mb-2">كلمة المرور المؤقتة</label>
<input <input
type="password" type="password"
required required
value={password} value={password}
onChange={e => setPassword(e.target.value)} onChange={e => setPassword(e.target.value)}
className="w-full bg-slate-50 border border-slate-200 rounded-2xl px-5 py-4 outline-none focus:border-primary-500 transition-all" className="w-full bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 outline-none focus:border-emerald-500/50 transition-all text-white placeholder-slate-600"
placeholder="••••••••" placeholder="••••••••"
/> />
</div> </div>
<div> <div>
<label className="block text-sm font-bold text-slate-700 mb-2">الصلاحية</label> <label className="block text-sm font-bold text-slate-400 mb-2">الدور الوظيفي</label>
<select <select
value={role} value={role}
onChange={e => setRole(e.target.value)} onChange={e => setRole(e.target.value)}
className="w-full bg-slate-50 border border-slate-200 rounded-2xl px-5 py-4 outline-none focus:border-primary-500 transition-all appearance-none" className="w-full bg-slate-800 border border-slate-700 rounded-xl px-4 py-3 outline-none focus:border-emerald-500/50 transition-all text-white appearance-none cursor-pointer"
> >
<option value="accountant">محاسب</option> <option value="manager">محاسب (عرض ومعالجة)</option>
<option value="admin">مدير نظام</option> <option value="admin">مدير نظام (صلاحيات كاملة)</option>
</select> </select>
</div> </div>
<div className="flex gap-4 pt-4"> <div className="flex gap-4 pt-4">
<button <button
type="button" type="button"
onClick={() => setIsAddModalOpen(false)} onClick={() => setIsAddModalOpen(false)}
className="flex-1 bg-slate-100 text-slate-700 font-bold py-4 rounded-2xl hover:bg-slate-200 transition-all" className="flex-1 bg-slate-800 text-slate-400 font-bold py-3 rounded-xl hover:bg-slate-700 transition-all"
> >
إلغاء إلغاء
</button> </button>
<button <button
type="submit" type="submit"
className="flex-[2] btn-primary py-4 rounded-2xl shadow-lg shadow-primary-500/30" disabled={isSubmitting}
className="flex-1 bg-emerald-500 text-slate-950 font-bold py-3 rounded-xl shadow-lg shadow-emerald-500/20 flex items-center justify-center gap-2 transition-all"
> >
حفظ وإضافة {isSubmitting && <Loader2 className="w-4 h-4 animate-spin" />}
حفظ البيانات
</button> </button>
</div> </div>
</form> </form>