Artikel DB struktur geändert von CODEX
This commit is contained in:
1 parent
0c0a678eaa
commit
9c18234efe
95 files changed
+3872
-2316
No files matched your search
@@ -1,57 +1,86 @@
|
||||
"use client";
|
||||
'use client';
|
||||
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { Article } from "../../types/catalog"
|
||||
|
||||
import { articleDelete } from "../../actions/article.actions";
|
||||
import { sites } from "../../_config/sites";
|
||||
import Link from "next/link";
|
||||
import { Eye, OctagonX } from 'lucide-react';
|
||||
|
||||
|
||||
interface Params {
|
||||
articles: Article[]
|
||||
}
|
||||
|
||||
export const ArticleList = ({ articles }: Params) => {
|
||||
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const handlerOnDelete = (id: string) => {
|
||||
articleDelete(id)
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='p-4 '>
|
||||
{articles.map((a) => (
|
||||
<div key={a._id} className="flex gap-4 border-b-1 p-4 border-gray-200">
|
||||
<div className='flex gap-4 wa'>
|
||||
<div className='w-32'>
|
||||
{a.name}
|
||||
</div>
|
||||
<div className='w-8'>
|
||||
<Link href={`${sites.article.update.url}/${a._id}`}>
|
||||
<Eye className=''></Eye>
|
||||
</Link>
|
||||
|
||||
|
||||
</div>
|
||||
<div className='w-8 '>
|
||||
<button className='flex gap-2' onClick={() => handlerOnDelete(a._id)}>
|
||||
<OctagonX className='' enableBackground={'green'} color='red'></OctagonX>
|
||||
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>))}
|
||||
|
||||
</div>
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
import { Article } from '../../types/catalog';
|
||||
import { articleDelete } from '../../actions/article.actions';
|
||||
import { sites } from '../../_config/sites';
|
||||
import Link from 'next/link';
|
||||
|
||||
export const ArticleList = ({ articles }: { articles: Article[] }) => {
|
||||
const router = useRouter();
|
||||
const [error, setError] = useState('');
|
||||
const [pendingId, setPendingId] = useState<string | null>(null);
|
||||
const archive = async (id: string) => {
|
||||
setPendingId(id);
|
||||
setError('');
|
||||
const result = await articleDelete(id);
|
||||
if (!result.success) setError(result.errors.join(' · '));
|
||||
else router.refresh();
|
||||
setPendingId(null);
|
||||
};
|
||||
return (
|
||||
<div className="overflow-auto">
|
||||
{error && (
|
||||
<p role="alert" className="text-red-700">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<table className="w-full text-left">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nummer</th>
|
||||
<th>Artikel</th>
|
||||
<th>Hersteller</th>
|
||||
<th>Einheit</th>
|
||||
<th>Bestandsführung</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{articles.map((article) => (
|
||||
<tr key={article._id} className="border-b">
|
||||
<td className="p-2">{article.articleNumber}</td>
|
||||
<td className="p-2">
|
||||
{article.name}
|
||||
{article.group && (
|
||||
<span className="block text-sm text-gray-500">
|
||||
{article.group.name}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="p-2">{article.manufacturer?.name ?? '–'}</td>
|
||||
<td className="p-2">{article.baseUnit}</td>
|
||||
<td className="p-2">
|
||||
{
|
||||
{
|
||||
quantity: 'Menge',
|
||||
batch: 'Charge',
|
||||
individual: 'Einzelstücke',
|
||||
}[article.trackingMode]
|
||||
}
|
||||
</td>
|
||||
<td className="p-2">
|
||||
<Link
|
||||
className="text-sky-700 mr-3"
|
||||
href={`${sites.article.update.url}/${article._id}`}
|
||||
>
|
||||
Bearbeiten
|
||||
</Link>
|
||||
<button
|
||||
disabled={pendingId !== null}
|
||||
onClick={() => archive(article._id)}
|
||||
>
|
||||
{pendingId === article._id ? 'Archiviert …' : 'Archivieren'}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{articles.length === 0 && (
|
||||
<p className="py-4">Noch keine Artikel vorhanden.</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user