feat: dynamic warehouse management and fix admin header
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -5,11 +5,27 @@ import { AlertTriangle, CheckCircle, PackageSearch, RefreshCw, Send, ListTree, A
|
|||||||
|
|
||||||
export default function DiscrepancyDashboard() {
|
export default function DiscrepancyDashboard() {
|
||||||
const [warehouse, setWarehouse] = useState('11');
|
const [warehouse, setWarehouse] = useState('11');
|
||||||
|
const [warehouses, setWarehouses] = useState([]);
|
||||||
const [data, setData] = useState({ discrepancies: [], accurate: [] });
|
const [data, setData] = useState({ discrepancies: [], accurate: [] });
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
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]);
|
}, [warehouse]);
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
@@ -55,10 +71,9 @@ export default function DiscrepancyDashboard() {
|
|||||||
onChange={(e) => setWarehouse(e.target.value)}
|
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"
|
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>
|
{warehouses.map(wh => (
|
||||||
<option value="13">انبار فروشگاه (13)</option>
|
<option key={wh.id} value={wh.id}>{wh.name} ({wh.id})</option>
|
||||||
<option value="14">انبار کارگاه شارژ (14)</option>
|
))}
|
||||||
<option value="15">انبار کارگاه تعمیرات (15)</option>
|
|
||||||
</select>
|
</select>
|
||||||
<button onClick={fetchData} className="bg-gray-900 text-white p-3 rounded-xl hover:bg-gray-800 transition-colors">
|
<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' : ''} />
|
<RefreshCw size={18} className={loading ? 'animate-spin' : ''} />
|
||||||
|
|||||||
@@ -133,6 +133,68 @@ export default function SettingsPage() {
|
|||||||
</div>
|
</div>
|
||||||
</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>
|
||||||
|
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
|
|||||||
@@ -16,6 +16,14 @@ export async function GET() {
|
|||||||
if (settingsMap['correction_roles'] === undefined) {
|
if (settingsMap['correction_roles'] === undefined) {
|
||||||
settingsMap['correction_roles'] = ['ADMIN', 'SUPERVISOR'];
|
settingsMap['correction_roles'] = ['ADMIN', 'SUPERVISOR'];
|
||||||
}
|
}
|
||||||
|
if (settingsMap['warehouses'] === undefined) {
|
||||||
|
settingsMap['warehouses'] = [
|
||||||
|
{ id: '11', name: 'انبار مرکزی' },
|
||||||
|
{ id: '13', name: 'انبار فروشگاه' },
|
||||||
|
{ id: '14', name: 'انبار کارگاه شارژ' },
|
||||||
|
{ id: '15', name: 'انبار کارگاه تعمیرات' }
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return NextResponse.json(settingsMap);
|
return NextResponse.json(settingsMap);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
+18
-5
@@ -1,5 +1,5 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { useState } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import Header from '@/components/Header';
|
import Header from '@/components/Header';
|
||||||
import dynamic from 'next/dynamic';
|
import dynamic from 'next/dynamic';
|
||||||
@@ -15,7 +15,21 @@ export default function ScanPage() {
|
|||||||
const [camError, setCamError] = useState('');
|
const [camError, setCamError] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [lockError, setLockError] = useState('');
|
const [lockError, setLockError] = useState('');
|
||||||
|
const [warehouses, setWarehouses] = useState([]);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleGoToCounting = async () => {
|
const handleGoToCounting = async () => {
|
||||||
if (!code) return;
|
if (!code) return;
|
||||||
@@ -179,10 +193,9 @@ export default function ScanPage() {
|
|||||||
onChange={(e) => setWarehouse(e.target.value)}
|
onChange={(e) => setWarehouse(e.target.value)}
|
||||||
className="w-full appearance-none pl-12 pr-5 py-4 bg-white border border-gray-200 rounded-[24px] focus:outline-none focus:border-indigo-500 focus:ring-4 focus:ring-indigo-50 transition-all text-sm font-bold text-gray-700 shadow-sm"
|
className="w-full appearance-none pl-12 pr-5 py-4 bg-white border border-gray-200 rounded-[24px] focus:outline-none focus:border-indigo-500 focus:ring-4 focus:ring-indigo-50 transition-all text-sm font-bold text-gray-700 shadow-sm"
|
||||||
>
|
>
|
||||||
<option value="11">انبار مرکزی (11)</option>
|
{warehouses.map(wh => (
|
||||||
<option value="13">انبار فروشگاه (13)</option>
|
<option key={wh.id} value={wh.id}>{wh.name} ({wh.id})</option>
|
||||||
<option value="14">انبار کارگاه شارژ (14)</option>
|
))}
|
||||||
<option value="15">انبار کارگاه تعمیرات (15)</option>
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export default function Header({ title = 'داشبورد', showBack = false }) {
|
|||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<div className="flex items-center gap-2 pl-1">
|
<div className="flex items-center gap-2 pl-1">
|
||||||
{user?.role === 'ADMIN' && (
|
{user?.roles?.includes('ADMIN') && (
|
||||||
<Link
|
<Link
|
||||||
href="/admin"
|
href="/admin"
|
||||||
className="w-10 h-10 bg-gray-50 text-gray-600 rounded-[18px] hover:bg-gray-100 transition-colors flex items-center justify-center"
|
className="w-10 h-10 bg-gray-50 text-gray-600 rounded-[18px] hover:bg-gray-100 transition-colors flex items-center justify-center"
|
||||||
|
|||||||
Reference in New Issue
Block a user