feat: dynamic warehouse management and fix admin header

This commit is contained in:
2026-06-12 11:09:07 +03:30
parent aabcea3aeb
commit 73b87193e1
7 changed files with 109 additions and 13 deletions
+20 -5
View File
@@ -5,11 +5,27 @@ import { AlertTriangle, CheckCircle, PackageSearch, RefreshCw, Send, ListTree, A
export default function DiscrepancyDashboard() {
const [warehouse, setWarehouse] = useState('11');
const [warehouses, setWarehouses] = useState([]);
const [data, setData] = useState({ discrepancies: [], accurate: [] });
const [loading, setLoading] = useState(true);
useEffect(() => {
fetchData();
fetch('/api/settings')
.then(res => res.json())
.then(data => {
if (data.warehouses) {
setWarehouses(data.warehouses);
if (data.warehouses.length > 0) {
setWarehouse(data.warehouses[0].id);
}
}
});
}, []);
useEffect(() => {
if (warehouse) {
fetchData();
}
}, [warehouse]);
const fetchData = async () => {
@@ -55,10 +71,9 @@ export default function DiscrepancyDashboard() {
onChange={(e) => setWarehouse(e.target.value)}
className="bg-gray-50 border border-gray-200 rounded-xl px-4 py-2.5 text-sm font-bold focus:outline-none focus:border-indigo-500 flex-1 sm:w-48"
>
<option value="11">انبار مرکزی (11)</option>
<option value="13">انبار فروشگاه (13)</option>
<option value="14">انبار کارگاه شارژ (14)</option>
<option value="15">انبار کارگاه تعمیرات (15)</option>
{warehouses.map(wh => (
<option key={wh.id} value={wh.id}>{wh.name} ({wh.id})</option>
))}
</select>
<button onClick={fetchData} className="bg-gray-900 text-white p-3 rounded-xl hover:bg-gray-800 transition-colors">
<RefreshCw size={18} className={loading ? 'animate-spin' : ''} />
+62
View File
@@ -133,6 +133,68 @@ export default function SettingsPage() {
</div>
</div>
{/* Warehouses Setting */}
<div className="border-t border-gray-50 pt-8">
<div className="flex items-center gap-2 mb-2">
<div className="w-8 h-8 rounded-xl bg-orange-50 text-orange-600 flex items-center justify-center">
<span className="font-black text-sm">WH</span>
</div>
<h2 className="text-base font-bold text-gray-800">مدیریت انبارهای حسابفا</h2>
</div>
<p className="text-xs text-gray-500 leading-relaxed mb-4">
لیست انبارهایی که انبارداران مجاز به انبارگردانی آنها هستند. کد انبار باید دقیقاً با کد حسابفا مطابقت داشته باشد.
</p>
<div className="flex flex-col gap-3">
{settings.warehouses?.map((wh) => (
<div key={wh.id} className="flex items-center justify-between p-3 rounded-[16px] border border-gray-200 bg-gray-50">
<div className="flex items-center gap-3">
<div className="bg-gray-200 text-gray-600 px-3 py-1 rounded-lg text-xs font-black">کد: {wh.id}</div>
<span className="text-sm font-bold text-gray-800">{wh.name}</span>
</div>
<button
onClick={() => setSettings(s => ({ ...s, warehouses: s.warehouses.filter(w => w.id !== wh.id) }))}
className="text-red-500 hover:bg-red-50 p-2 rounded-xl transition-colors"
>
حذف
</button>
</div>
))}
<div className="flex gap-2 mt-2">
<input
type="number"
placeholder="کد انبار..."
id="wh_id"
className="w-24 bg-white border border-gray-200 rounded-[16px] px-3 py-2 text-sm focus:outline-none focus:border-indigo-500"
/>
<input
type="text"
placeholder="نام انبار..."
id="wh_name"
className="flex-1 bg-white border border-gray-200 rounded-[16px] px-3 py-2 text-sm focus:outline-none focus:border-indigo-500"
/>
<button
onClick={() => {
const id = document.getElementById('wh_id').value;
const name = document.getElementById('wh_name').value;
if (id && name) {
setSettings(s => ({
...s,
warehouses: [...(s.warehouses || []), { id, name }]
}));
document.getElementById('wh_id').value = '';
document.getElementById('wh_name').value = '';
}
}}
className="bg-indigo-50 text-indigo-600 px-4 py-2 rounded-[16px] text-xs font-bold hover:bg-indigo-100 transition-colors"
>
افزودن
</button>
</div>
</div>
</div>
</div>
<div className="flex justify-end">