Initial commit: NestJS NextJS pnpm monorepo

This commit is contained in:
Marco_205 committed 2026-10-12 07:20:37 +00:00
commit 610dcf202b
175 files changed
+25172

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# env files (can opt-in for committing if needed)
.env*
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
+36
View File
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
+34
View File
@@ -0,0 +1,34 @@
export const endpoints = {
apiServer: { url: 'http://192.168.50.205/api' },
test: { url: '/test' },
category: {
url: "/category",
name:"Kategorien",
new: { url: "/category/new" },
update: { url: "/category/update", param: "id" }
},
manufacturer: {
url: "/manufacturer",
new: { url: "/manufacturer/new",name:"Hersteller" },
update: { url: "/manufacturer/update", param: "id" }
},
article: {
url: "/catalog/article/",
new: { url: "/catalog/article/new" },
update: { url: "/catalog/article/", param: "id" }
},
stock: {
url: "/stock/movement/",
new: { url: "/stock/movement/new" },
update: { url: "/stock/", param: "id" }
},
location: {
url: "/locations",
name:"Lagerorte",
treeView:{
url:"/locations/childs",
name:"Get Tree View",
}
}
}
+33
View File
@@ -0,0 +1,33 @@
export const sites = {
main: { url: '/' },
test: { url: '/test' },
category: {
url: "/category",
name:"Kategorien",
new: { url: "/category/new" },
update: { url: "/category/update", param: "id" }
},
manufacturer: {
url: "/manufacturer",
new: { url: "/manufacturer/new",name:"Hersteller" },
update: { url: "/manufacturer/update", param: "id" }
},
article: {
url: "/catalog/article/",
new: { url: "/catalog/article/new" },
update: { url: "/catalog/article/", param: "id" }
},
stock: {
url: "/stock/movement/",
new: { url: "/stock/movement/new" },
update: { url: "/stock/", param: "id" }
},
location: {
url: "/location/",
name:"Lagerorte",
new: { url: "/location/new",name:"Lagerort anlegen" },
update: { url: "/location/edit", param: "id", name:"Lagerort bearbeiten" }
}
}
+9
View File
@@ -0,0 +1,9 @@
export const checkEmail = {
required: "Email ist Pflicht",
pattern: {
value: /^\S+@\S+$/i,
message: "Ungültige Email",
},
}
+94
View File
@@ -0,0 +1,94 @@
'use server'
import { revalidatePath } from 'next/cache'
import { Article, ArticleCreate, ArticleUpsert } from "@/apps/frontend/types/catalog";
import { sites } from '../_config/sites';
export async function articleCreate(data: ArticleCreate) {
console.log(data);
const result = await fetch('http://192.168.50.205/api/articles', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
};
}
revalidatePath(sites.article.new.url)
}
export async function articleUpdate(id: string, data: ArticleUpsert): Promise<ActionResult> {
const result = await fetch(`http://192.168.50.205/api/articles/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
};
}
revalidatePath(sites.article.update.url + '/' + id);
return { success: true };
}
export async function articleFindAll(): Promise<Article[]> {
const result = await fetch(`http://192.168.50.205/api/articles`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json() as Article[];
return data;
}
export async function articleFindById(id: string): Promise<any> {
const result = await fetch(`http://192.168.50.205/api/articles/${id}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json() as Article
console.log('getArticle', data)
return data;
}
export async function articleDelete(id: string,revalidateUrl?:string): Promise<ActionResult> {
const result = await fetch(`http://192.168.50.205/api/articles/${id}`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' }
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
};
}
if(revalidateUrl) revalidatePath(revalidateUrl);
return { success: true };
}
+49
View File
@@ -0,0 +1,49 @@
'use server'
import { revalidatePath } from 'next/cache'
import { Category, CategoryCreate } from "@/apps/frontend/types/catalog";
export async function categoryCreate(data: CategoryCreate) {
console.log(data);
const result = await fetch('http://192.168.50.205/api/categories', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
console.log(result);
revalidatePath('/test')
}
export async function categoryUpdate( id: string, data: Partial<CategoryCreate>) {
console.log(data,id);
const result = await fetch(`http://192.168.50.205/api/categories/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
console.log(result);
revalidatePath('/test')
}
export async function categoryFindAll():Promise<Category[]> {
const result = await fetch(`http://192.168.50.205/api/categories`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json();
return data;
}
export async function categoryFindById(id:string):Promise<Category> {
const result = await fetch(`http://192.168.50.205/api/categories/${id}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json();
return data;
}
+69
View File
@@ -0,0 +1,69 @@
'use server'
import { Location, LocationCreate, LocationTreeNode, LocationUpdate } from "../types/inventory";
import { endpoints } from '../_config/endpoints';
import { revalidateTag, revalidatePath } from "next/cache"
export async function locationCreate(data: LocationCreate) {
console.log(`${endpoints.apiServer}${endpoints.location}`);
const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.url}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const respData = await result.json();
revalidateTag("location", "default");
return respData;
console.log(data)
}
export async function locationUpdate(id: string, data: LocationUpdate) {
const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.url}/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const respData = await result.json();
revalidateTag("location", "default");
return respData;
}
export async function locationFindAll(): Promise<Location[]> {
const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.url}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json();
return data;
}
export async function locationTree(): Promise<LocationTreeNode[]> {
const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.treeView.url}`, {
next: { tags: ["location"] },
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json();
return data;
}
export async function locationFindById(id: string): Promise<Location> {
const result = await fetch(`${endpoints.apiServer.url}${endpoints.location.url}/${id}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const respData = await result.json();
return respData;
}
@@ -0,0 +1,74 @@
'use server'
import { revalidatePath } from 'next/cache'
import { Manufacturer, ManufacturerCreate } from "@/apps/frontend/types/catalog";
import { sites } from '../_config/sites';
export async function manufacturerCreate(data: ManufacturerCreate): Promise<ActionResult> {
const result = await fetch('http://192.168.50.205/api/manufacturer', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message,
};
}
// revalidatePath(sites.manufacturer.new.url);
return { success: true, data:resultData };
}
export async function manufacturerUpdate(id: string, data: Partial<ManufacturerCreate>): Promise<ActionResult> {
console.log(data, id);
const result = await fetch(`http://192.168.50.205/api/manufacturer/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message,
};
}
revalidatePath(sites.manufacturer.update.url + '/' + id);
revalidatePath(sites.manufacturer.url );
return { success: true, data:resultData.data };
}
export async function manufacturerFindAll(): Promise<Manufacturer[]> {
const result = await fetch(`http://192.168.50.205/api/manufacturer`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json();
return data;
}
export async function manufacturerFindById(id: string): Promise<Manufacturer> {
const result = await fetch(`http://192.168.50.205/api/manufacturer/${id}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json();
return data;
}
+94
View File
@@ -0,0 +1,94 @@
'use server'
import { revalidatePath } from 'next/cache'
import { sites } from '../_config/sites';
import { Stock, StockCreate, StockUpdate } from '../types/inventory/stockContent.types';
export async function stockCreate(data: StockCreate) {
const result = await fetch('http://192.168.50.205/api/stock', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
};
}
revalidatePath(sites.stock.new.url)
}
export async function stockUpdate(id: string, data: StockUpdate): Promise<ActionResult> {
const result = await fetch(`http://192.168.50.205/api/stocks/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
};
}
revalidatePath(sites.stock.update.url + '/' + id);
return { success: true };
}
export async function stockFindAll(): Promise<Stock[]> {
const result = await fetch(`http://192.168.50.205/api/stocks`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json() as Stock[];
return data;
}
export async function stockFindById(id: string): Promise<any> {
const result = await fetch(`http://192.168.50.205/api/stocks/${id}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
const data = await result.json() as Stock
console.log('getArticle', data)
return data;
}
export async function stockDelete(id: string,revalidateUrl?:string): Promise<ActionResult> {
const result = await fetch(`http://192.168.50.205/api/stocks/${id}`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' }
})
const resultData = await result.json();
if (!result.ok) {
return {
success: false,
errors: resultData.message, // kommt aus NestJS
};
}
if(revalidateUrl) revalidatePath(revalidateUrl);
return { success: true };
}
@@ -0,0 +1,37 @@
import Link from "next/link";
import { sites } from "../../../../_config/sites";
import { articleFindById } from "../../../../actions/article.actions";
import { ArticleMainForm } from "../../../../components/article/articleMain.form";
import { categoryFindAll } from "../../../../actions/category.actions";
import { manufacturerFindAll } from "../../../../actions/manufacturer.actions";
interface PageProps {
params: Promise<{ id: string }>
}
export default async function CatergoryUpdate({ params }: PageProps) {
const { id } = await params
const article = await articleFindById(id);
const cats = await categoryFindAll();
const manufacturer = await manufacturerFindAll();
if(!article._id) {
return (<div>
<div>Artikel nicht gefunden</div>
<div>
<Link className="cursor-pointer p-2 border-1 border-sky-500 bg-sky-500 text-white rounded-full m-1 hover:bg-sky-700 " href={sites.article.url}>zurück1</Link>
</div>
</div>)
}
const {name,category,variants} = article;
console.log('Varianten:',article.variants)
return (
<div className="h-screen">
<ArticleMainForm initData={article} categories={cats} manufacturer={manufacturer}></ArticleMainForm>
<Link className="cursor-pointer p-2 border-1 border-sky-500 bg-sky-500 text-white rounded-full m-1 hover:bg-sky-700 " href={sites.article.url}>zurück</Link>
</div>
);
}
@@ -0,0 +1,27 @@
import { manufacturerFindAll } from "../../../../actions/manufacturer.actions";
import { categoryFindAll } from "../../../../actions/category.actions";
import { ArticleMainForm } from "../../../../components/article/articleMain.form";
import { articleCreate, articleFindAll } from "../../../../actions/article.actions";
import Link from "next/link";
import { sites } from "../../../../../../apps/frontend/_config/sites";
//import { sites } from "@/";
interface Props {
}
export default async function ArticlePage({ }: Props) {
const cats = await categoryFindAll();
const manufacturer = await manufacturerFindAll();
const artikel = await articleFindAll();
if(!manufacturer) return <div>Keine Hersteller gefunden</div>
return <>
<ArticleMainForm categories={cats} manufacturer={manufacturer}></ArticleMainForm>
<Link href={`${sites.article.url}`} className="text-sky-300">zurück</Link>
</>
}
@@ -0,0 +1,26 @@
import { manufacturerFindAll } from "../../../actions/manufacturer.actions";
import { articleFindAll } from "../../../actions/article.actions";
import Link from "next/link";
import { sites } from "../../../../../apps/frontend/_config/sites";
import { ArticleList } from "../../../components/article/articleList";
import { Icon, CirclePlus } from "lucide-react";
interface Props { }
export default async function ArticlePage({ }: Props) {
const manufacturer = await manufacturerFindAll();
const artikel = await articleFindAll();
if (!manufacturer) return <div>Keine Hersteller gefunden</div>
return <div className="p-4 mb-4">
<div className="">
<Link href={`${sites.article.new.url}`} className="text-sky-300 text-black"><CirclePlus color="green" />neu </Link>
</div>
<ArticleList articles={artikel}></ArticleList>
<Link href={`${sites.main.url}`} className="text-sky-300">zurück</Link>
</div>
}
+21
View File
@@ -0,0 +1,21 @@
import Link from "next/link";
import { sites } from "../../../_config/sites";
import { CategoryForm } from "../../../components/category/categroy.form";
interface PageProps {
}
export default async function CatergoryUpdate({ }: PageProps) {
return (
<div className="h-screen">
<CategoryForm></CategoryForm>
<Link className="cursor-pointer p-2 border-1 border-sky-500 bg-sky-500 text-white rounded-full m-1 hover:bg-sky-700 " href={sites.category.url}>zurück</Link>
</div>
);
}
+41
View File
@@ -0,0 +1,41 @@
import Link from "next/link";
import { sites } from "../../_config/sites";
import { categoryFindAll } from "../../actions/category.actions";
export default async function CatergoryPage() {
const cats = await categoryFindAll();
return (
<div className="h-screen">
<div className="flex flex-col gap-8 mt-4 ms-4">
<div className="border-1 max-w-200 p-4">
<div className="mb-4 cursor-pointer text-sky-500 hover:bg-sky-700">
<Link href={`/category/new`}>Neu</Link>
</div>
{cats.map((cat) => (
<div key={cat._id} className="flex gap-4 p-0">
<div className="min-w-30">
{cat.name}
</div>
<div className="cursor-pointer text-sky-500 ps-1 pe-1 hover:bg-sky-700">
<Link href={`/category/update/${cat._id}`}>Update</Link>
</div>
</div>
))}
</div>
<div>
<Link className="cursor-pointer p-2 border-1 border-sky-500 bg-sky-500 text-white rounded-full m-1 hover:bg-sky-700 " href={sites.main.url}>Home</Link>
</div>
</div>
</div>
);
}
@@ -0,0 +1,33 @@
import Link from "next/link";
import { sites } from "../../../../_config/sites";
import { CategoryForm } from "../../../../components/category/categroy.form";
import { categoryFindById } from "../../../../actions/category.actions";
interface PageProps {
params: Promise<{ id: string }>
}
export default async function CatergoryUpdate({ params }: PageProps) {
const { id } = await params
const cat = await categoryFindById(id);
if(!cat._id) {
return (<div>
<div>Kategorie nicht gefunden</div>
<div>
<Link className="cursor-pointer p-2 border-1 border-sky-500 bg-sky-500 text-white rounded-full m-1 hover:bg-sky-700 " href={sites.category.url}>zurück</Link>
</div>
</div>)
}
return (
<div className="h-screen">
<CategoryForm initData={cat} ></CategoryForm>
<Link className="cursor-pointer p-2 border-1 border-sky-500 bg-sky-500 text-white rounded-full m-1 hover:bg-sky-700 " href={sites.category.url}>zurück</Link>
</div>
);
}
+38
View File
@@ -0,0 +1,38 @@
'use client';
import { useEffect, useState } from 'react';
import { io } from 'socket.io-client';
const socket = io('http://localhost:3000');
export default function Home() {
const [msg, setMsg] = useState('');
const [messages, setMessages] = useState<string[]>([]);
useEffect(() => {
socket.on('message', (data) => {
console.log(data);
setMessages((prev) => [...prev, data]);
});
return () => {
socket.off('message');
};
}, []);
const sendMessage = () => {
socket.emit('message', msg);
setMsg('');
};
return (
<div>
<input value={msg} onChange={(e) => setMsg(e.target.value)} />
<button onClick={sendMessage}>Send</button>
<ul>
{messages.map((m, i) => <li key={i}>{m}</li>)}
</ul>
</div>
);
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

+26
View File
@@ -0,0 +1,26 @@
@import "tailwindcss";
:root {
--background: #ffffff;
--foreground: #171717;
}
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--font-sans: var(--font-geist-sans);
--font-mono: var(--font-geist-mono);
}
@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}
body {
background: var(--background);
color: var(--foreground);
font-family: Arial, Helvetica, sans-serif;
}
+34
View File
@@ -0,0 +1,34 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
);
}
+22
View File
@@ -0,0 +1,22 @@
import Link from "next/link";
import { sites } from "../../../_config/sites";
import { LocationForm } from "../../../components/location/location.form";
export default async function LocationNewPage() {
return (
<div className="h-screen flex flex-col gap-4">
<div>
{sites.location.new.name}
<LocationForm debug={true}></LocationForm>
</div>
<Link href={sites.location.url}>zurück zu {sites.location.name}</Link>
</div>
);
}
+30
View File
@@ -0,0 +1,30 @@
import Link from "next/link";
import { sites } from "../../_config/sites";
import { locationTree } from "../../actions/location.actions";
import { LocationView } from "../../components/location/location.view";
export default async function LocationPage() {
const treeNodes = await locationTree();
return (
<div className="h-screen">
<div>
<Link href={sites.location.new.url}>{sites.location.new.name}</Link>
</div>
<div>
<LocationView data={treeNodes}></LocationView>
</div>
<Link href={sites.main.url}>Home</Link>
</div>
);
}
@@ -0,0 +1,21 @@
import Link from "next/link";
import { sites } from "../../../_config/sites";
import { ManufactuererForm } from "../../../components/manufacturer/manufacturer.form";
interface PageProps {
}
export default async function ManufacturerUpdate({ }: PageProps) {
return (
<div className="h-screen">
<ManufactuererForm></ManufactuererForm>
<Link className="cursor-pointer p-2 border-1 border-sky-500 bg-sky-500 text-white rounded-full m-1 hover:bg-sky-700 " href={sites.manufacturer.url}>zurück</Link>
</div>
);
}
+41
View File
@@ -0,0 +1,41 @@
import Link from "next/link";
import { sites } from "../../_config/sites";
import { manufacturerFindAll } from "../../actions/manufacturer.actions";
export default async function ManufacturerPage() {
const manufacturer = await manufacturerFindAll();
return (
<div className="h-screen">
<div className="flex flex-col gap-8 mt-4 ms-4">
<div className="border-1 max-w-200 p-4">
<div className="mb-4 cursor-pointer text-sky-500 hover:bg-sky-700">
<Link href={sites.manufacturer.new.url}>Neu</Link>
</div>
{manufacturer.map((man) => (
<div key={man._id} className="flex gap-4 p-0">
<div className="min-w-30">
{man.name}
</div>
<div className="cursor-pointer text-sky-500 ps-1 pe-1 hover:bg-sky-700">
<Link href={`${sites.manufacturer.update.url}/${man._id}`}>Update</Link>
</div>
</div>
))}
</div>
<div>
<Link className="cursor-pointer p-2 border-1 border-sky-500 bg-sky-500 text-white rounded-full m-1 hover:bg-sky-700 " href={sites.main.url}>Home</Link>
</div>
</div>
</div>
);
}
@@ -0,0 +1,32 @@
import Link from "next/link";
import { manufacturerFindById } from "../../../../actions/manufacturer.actions";
import { ManufactuererForm } from "../../../../components/manufacturer/manufacturer.form";
import { sites } from "../../../../_config/sites";
interface PageProps {
params: Promise<{ id: string }>
}
export default async function CatergoryUpdate({ params }: PageProps) {
const { id } = await params
const hersteller = await manufacturerFindById(id);
if(!hersteller._id) {
return (<div>
<div>Hersteller nicht gefunden</div>
<div>
<Link className="cursor-pointer p-2 border-1 border-sky-500 bg-sky-500 text-white rounded-full m-1 hover:bg-sky-700 " href={sites.manufacturer.url}>zurück</Link>
</div>
</div>)
}
return (
<div className="h-screen">
<ManufactuererForm initData={hersteller} ></ManufactuererForm>
<Link className="cursor-pointer p-2 border-1 border-sky-500 bg-sky-500 text-white rounded-full m-1 hover:bg-sky-700 " href={sites.manufacturer.url}>zurück</Link>
</div>
);
}
+21
View File
@@ -0,0 +1,21 @@
import Link from "next/link";
import { sites } from "../_config/sites";
export default function Home() {
return (
<div className="h-dvh bg-gray-100">
<div className="min-h-[60] md:max-h-[60] bg-gray-300 ps-12 pt-4">Home Manager</div>
<main className="flex flex-col border-1 border-gray-200 ">
<div className="m-4 flex flex-col gap-2">
<Link href={sites.article.url}>Artikel</Link>
<Link href={sites.category.url}>Kategorien</Link>
<Link href={sites.manufacturer.url}>Hersteller</Link>
<Link href={sites.location.url}>{sites.location.name}</Link>
<Link href={sites.stock.new.url}>{sites.stock.new.url}</Link>
<Link href={sites.test.url}>Test</Link>
</div>
</main>
</div>
);
}
@@ -0,0 +1,27 @@
import Link from "next/link";
import { sites } from "../../../../_config/sites";
import { LocationForm } from "../../../../components/location/location.form";
import { articleFindAll } from "../../../../actions/article.actions";
import { locationFindAll, locationTree } from "../../../../actions/location.actions";
import { StockForm } from "../../../../components/stock/stock.form";
import { categoryFindAll } from "../../../../actions/category.actions";
export default async function StockMovmentNewPage() {
const artikel = await articleFindAll();
const orte = await locationTree();
const kategorien = await categoryFindAll();
return (
<div className="h-screen flex flex-col gap-4">
<div>
{sites.location.new.name}
<StockForm article={artikel} orte={orte} categories={kategorien}></StockForm>
</div>
<Link href={sites.location.url}>zurück zu {sites.location.name}</Link>
</div>
);
}
+23
View File
@@ -0,0 +1,23 @@
import Image from "next/image";
import { sharedFunction } from '@male/shared';
import Link from "next/link";
import { sites } from "../../_config/sites";
import { TestForm } from "../../components/test/testForm";
import { CategoryForm } from "../../components/category/categroy.form";
import { categoryFindAll } from "../../actions/category.actions";
console.log(sharedFunction)
export default async function Home() {
const cats = await categoryFindAll();
return (
<div className="h-screen">
{cats.map((cat)=>(<div key={cat._id}>{cat.name}</div>))}
<CategoryForm></CategoryForm>
<Link className="cursor-pointer p-2 border-1 border-sky-500 bg-sky-500 text-white rounded-full m-1 hover:bg-sky-700 " href={sites.main.url}>Home</Link>
</div>
);
}
@@ -0,0 +1,26 @@
"use client";
import { ArticleCreate, ArticleUpsert, Category } from "../../types/catalog"
import { useFormContext } from "react-hook-form"
import { InputTextR } from "../ui/inputTextR";
import ComboBoxR from "../ui/ComboBoxR";
interface Params {
categories: Category[]
}
export const ArticleBaseForm = ({ categories }: Params) => {
const { register, control } = useFormContext<ArticleUpsert>();
const values = categories.map((i) => ({ id: i._id, value: i.name }))
return (
<>
<InputTextR label="Artikename" {...register("name", { required: "Pflichtfeld" })} />
<ComboBoxR name="categoryId" control={control} options={values} placeholder="wählen..." />
</>
)
}
@@ -0,0 +1,57 @@
"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>
)
}
@@ -0,0 +1,106 @@
"use client";
import { emptyArticleDto, Article, ArticleCreate, Category, Manufacturer, ArticleUpsert } from "../../types/catalog"
import { FormProvider, useForm } from "react-hook-form"
import { ArticleBaseForm } from "./articleBase.form";
import { ArticleVariantForm } from "./articleVariants.form";
import { articleCreate, articleUpdate } from "../../actions/article.actions";
import { useEffect, useState } from "react";
import Modal from "../ui/modal";
import { ManufactuererForm } from "../manufacturer/manufacturer.form";
interface Params {
categories: Category[]
manufacturer: Manufacturer[]
initData?: ArticleUpsert
debug?: boolean
}
export const ArticleMainForm = ({ categories, manufacturer, initData, debug }: Params) => {
const methods = useForm<ArticleUpsert>({ defaultValues: emptyArticleDto });
const [errMsg, setErrorMsg] = useState<string[]>([])
const [error, setError] = useState(false)
const [creatManufacturer, setCreatManufacturer] = useState(-1);
const [hersteller,setHersteller] = useState<Manufacturer[]>([])
useEffect(() => {
setHersteller(manufacturer);
if (initData && initData._id) {
methods.reset(initData);
}
}, [initData])
const handlerCreatManufacturer = (data: Manufacturer) => {
console.log('Create')
setHersteller((cur)=>([...cur,data]));
methods.setValue(
`variants.${creatManufacturer}.manufacturerId`,
data._id,
{ shouldDirty: true, shouldValidate: true }
);
setCreatManufacturer(-1)
}
const onSubmit = async (data: ArticleUpsert) => {
if (initData?._id) {
const result = await articleUpdate(initData._id, data)
if (!result.success) {
setError(true)
setErrorMsg(() => result.errors)
console.log(result)
} else {
setError(false)
}
} else {
console.log('create')
const { name, categoryId, variants, attributes } = data;
if (categoryId) {
const create = {
name,
categoryId,
variants,
attributes
}
articleCreate(create);
}
}
};
return (
<div className="me-30 flex flex-col p-4 pt-10 ps-10" >
<FormProvider {...methods}>
{initData?._id && <div>{initData._id}</div>}
<form onSubmit={methods.handleSubmit(onSubmit)}>
<ArticleBaseForm categories={categories}></ArticleBaseForm>
<ArticleVariantForm manufacturer={hersteller} onOpenManufacturer={(index) => setCreatManufacturer(index)}></ArticleVariantForm>
<div>{methods.watch("name")}</div>
<pre>{JSON.stringify(methods.watch(), null, 2)}</pre>
<button type="submit">Absenden</button>
</form>
</FormProvider>
<Modal open={creatManufacturer >= 0} onClose={() => setCreatManufacturer(-1)}>
<ManufactuererForm onChangeData={(d) => handlerCreatManufacturer(d)}></ManufactuererForm>
<button onClick={() => setCreatManufacturer(-1)}>Abbruch</button>
</Modal>
{error && <div className="border-1 border-red-400 bg-red-200">
Error
{errMsg.map((msg, id) => (<div key={id}>{msg}</div>))}
</div>}
</div>
)
}
@@ -0,0 +1,85 @@
"use client";
import { ArticleCreate, ArticleUpsert, Manufacturer } from "../../types/catalog"
import { useFieldArray, useFormContext } from "react-hook-form"
import { InputTextR } from "../ui/inputTextR";
import ComboBoxRHF from "../ui/ComboBoxR";
import { useState } from "react";
import Modal from "../ui/modal";
import { ManufactuererForm } from "../manufacturer/manufacturer.form";
import SelectAndSearch2 from "../ui/SelectAndSearch2";
interface Params {
manufacturer: Manufacturer[]
onOpenManufacturer: (index: number) => void
}
export const ArticleVariantForm = ({ manufacturer, onOpenManufacturer }: Params) => {
const { control, register, getValues, setValue } = useFormContext<ArticleUpsert>();
const { fields, append, remove } = useFieldArray({ control, name: "variants", });
const [creatManufacturer, setCreatManufacturer] = useState(false);
const handleRemove = (index: number) => {
const id = getValues(`variants.${index}._id`);
if (!id) {
remove(index);
return;
}
const x = getValues(`variants.${index}.deleted`) ? true : false;
setValue(`variants.${index}.deleted`, !x, { shouldDirty: true })
}
const hersteller = manufacturer.map((i) => ({ id: i._id, value: i.name }))
return (
<div className="mt-4 border-1 rounded border-gray-200 p-2">
<div>
<button type="button" onClick={() => append({ manufacturerId: "", packagingUnit: "1" })} className="bg-sky-400 rounded-md p-1 mt-2 mb-2 ps-2 pe-2">
+ Neue Variante
</button>
</div>
<div className="flex flex-col gap-2 mb-2">
<div className="grid grid-cols-12 gap-4 ">
<div className="col-span-4" >
Hersteller
</div>
<div className="col-span-3" >
Packungseinheit
</div>
<div className="col-span-3" >
Aktion
</div>
</div>
<div className="border-1"></div>
{fields.map((field, index) => (
<div key={field.id} className="grid grid-cols-12 gap-4 ">
<div className="col-span-4" >
<ComboBoxRHF name={`variants.${index}.manufacturerId`} control={control} options={hersteller} placeholder="wählen..." />
<button onClick={() => onOpenManufacturer(index)}>+</button>
</div>
<div className="col-span-3" >
<InputTextR {...register(`variants.${index}.packagingUnit`)} />
</div>
<div className="col-span-3" >
<button type="button" onClick={() => handleRemove(index)} className={`bg-gray-200 rounded-md ps-2 pe-2 `}>
löschen
</button>
</div>
</div>
))}
</div>
</div>
)
}
@@ -0,0 +1,76 @@
"use client";
import { useEffect, useState } from "react"
import { Category, CategoryCreate, emptyCategory } from "../../types/catalog/category.types"
import { useForm } from "react-hook-form"
import { InputTextR } from "../ui/inputTextR";
import { InputCheckboxR } from "../ui/inputCheckboxR";
import { categoryCreate, categoryUpdate } from '../../actions/category.actions'
interface Params {
initData?: Category
debug?: boolean
}
export const CategoryForm = ({ initData, debug }: Params) => {
const { register, handleSubmit, formState: { errors }, watch, getFieldState, reset } = useForm<CategoryCreate>({ defaultValues: emptyCategory, })
const [modeUpdate, setModeUpdate] = useState(false);
const [id, setId] = useState<string | undefined>();
const [error, setError] = useState<string | undefined>();
useEffect(() => {
if (initData) {
const { _id, name, description, isConsumable } = initData;
setId(_id);
setModeUpdate(true);
reset({ name, description, isConsumable })
}
}, []);
const onSubmit = async (data: CategoryCreate) => {
setError(undefined);
//const { name, isConsumable, description } = data;
if (modeUpdate) {
if(id){
categoryUpdate(id,data);
}else{
setError('Etwas ist falsch, keine ID');
}
} else {
categoryCreate(data);
}
}
return (
<div className="w-120 flex flex-col p-4 pt-10 ps-10" >
<div className="border-1 p-4">
<form onSubmit={handleSubmit(onSubmit)} className="max-w-md mx-auto">
<InputTextR label="Kategorie Name" {...register("name", { required: "Pflichtfeld" })} error={errors.name?.message} />
<InputTextR label="Beschreibung" {...register("description")} error={errors.description?.message} />
<div className="mt-4 mb-4 p-2 border-1 border-gray-200 relative ">
<div className="absolute -top-2 left-2 bg-white ps-1 pe-1 text-xs">Optionen</div>
<InputCheckboxR label="Konsumierbar" {...register("isConsumable")} error={errors.isConsumable?.message} />
</div>
<div>
{error && <div>{error}</div>}
{errors.name && <div>{errors.name.message}</div>}
</div>
<button type="submit" className="bg-blue-500 text-white p-2 rounded mt-2 hover:bg-blue-600">Speichern</button>
</form>
</div>
{debug &&
<div>
<div>{watch("name")}</div>
<pre>touched:{getFieldState("name").isTouched ? 'true' : 'false'}</pre>
<pre>{JSON.stringify(watch(), null, 2)}</pre>
</div>
}
</div>
)
}
@@ -0,0 +1,35 @@
import { useEffect, useState } from "react"
interface ChangeValue {
[key: string]: boolean
}
interface Props {
label?:string
name: string
valueInit?: boolean,
onChange: (value: boolean) => void
}
export const InputCheckbox = ({ label, valueInit, onChange, name }: Props) => {
const [checked, setChecked] = useState(false);
useEffect(() => {
if (valueInit) {
setChecked(valueInit);
}
}, [])
useEffect(() => {
const obj = { [name]: checked };
onChange(checked);
}, [checked])
return (
<div className="border-1 border-gray-100 p-2 mb-1 mt-1 bg-green-100 flex items-center">
<input type="checkbox" className=" p-1 me-2 w-8 h-8 " name={name} value={label} checked={checked} onChange={(e) => setChecked((pre)=>!pre)} />
{label && <div className="text-sm font-bold text-black font-mono ps-1">{label}</div>}
</div>
)
}
@@ -0,0 +1,35 @@
import { useEffect, useState } from "react"
interface ChangeValue {
[key: string]: string
}
interface Props {
label?:string
name: string
valueInit?: string,
onTxtChange: (txt: ChangeValue) => void
}
export const InputText = ({ label, valueInit, onTxtChange, name }: Props) => {
const [txt, setTxt] = useState('');
useEffect(() => {
if (valueInit) {
setTxt(valueInit);
}
}, [])
useEffect(() => {
const obj = { [name]: txt };
onTxtChange(obj);
}, [txt])
return (
<div className="border-1 border-gray-100 p-2 mb-1 mt-1 bg-green-100">
{label && <div className="text-sm font-bold text-black font-mono ps-1">{label}</div>}
<input className="bg-white border-1 rounded p-1 w-full" name={name} value={txt} onChange={(e) => setTxt(e.target.value)} />
</div>
)
}
@@ -0,0 +1,66 @@
"use client"
import { useState } from "react";
import { LocationTreeNode } from "../../types/inventory";
type Props = {
node: LocationTreeNode;
selectedId: string | null;
focusedId: string | null;
openMap: Record<string, boolean>;
setOpenMap: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
setFocusedId: (id: string) => void;
onSelect: (id: string ) => void;
};
export function LocationTreeNodeItem({ node, selectedId, focusedId, openMap, setOpenMap, setFocusedId, onSelect }: Props) {
const hasChildren = node.children.length > 0;
const isOpen = openMap[node._id];
return (
<div className="ml-4" >
<div className="flex items-center gap-2">
{hasChildren && (
<button
type="button"
onClick={() => setOpenMap(m => ({ ...m, [node._id]: !isOpen }))}
className="w-6"
>
{isOpen ? "▼" : "▶"}
</button>
)}
{!hasChildren && <span className="w-6" />}
<button
type="button"
onClick={() => onSelect(node._id)}
onFocus={() => setFocusedId(node._id)}
className={`text-left px-1 rounded ${selectedId === node._id ? "font-bold text-blue-600" : ""
} ${focusedId === node._id ? "bg-blue-100" : ""
}`}
>
{node.name}
</button>
</div>
{isOpen && hasChildren && (
<ul className="ml-6 mt-1 border-l pl-2">
{node.children.map(child => (
<LocationTreeNodeItem
key={child._id}
node={child}
selectedId={selectedId}
focusedId={focusedId}
openMap={openMap}
setOpenMap={setOpenMap}
setFocusedId={setFocusedId}
onSelect={onSelect}
/>
))}
</ul>
)}
</div>
);
}
@@ -0,0 +1,135 @@
"use client";
import { useEffect, useState } from "react"
import { Controller, useForm } from "react-hook-form"
import { InputTextR } from "../ui/inputTextR";
import { emptyLocation, Location, LocationCreate, LocationMutaion, LocationTreeNode, LocationUpdate } from "../../types/inventory";
import { locationCreate, locationTree, locationUpdate } from "../../actions/location.actions";
import { useRouter } from "next/navigation"
import { sites } from "../../_config/sites";
import { LocationTreeView } from "./location.treeView";
interface Params {
initData?: Location
debug?: boolean
}
export const LocationForm = ({ initData, debug }: Params) => {
const [locationTreeData, setLocationTree] = useState<LocationTreeNode[]>()
useEffect(() => {
const load = async () => {
let d = await locationTree();
setLocationTree(d);
}
load();
if (initData) {
const { _id, name, description, parentLocationId } = initData;
setId(_id);
setModeUpdate(true);
reset({ name, description, parentLocationId })
}
}, [initData])
const router = useRouter();
const {
register,
handleSubmit,
formState: { errors },
watch,
control,
getFieldState,
reset }
= useForm<LocationMutaion>({ defaultValues: emptyLocation })
const [modeUpdate, setModeUpdate] = useState(false);
const [id, setId] = useState<string | undefined>();
const [error, setError] = useState<string | undefined>();
const onSubmit = async (data: LocationMutaion) => {
setError(undefined);
if (modeUpdate) {
if (id) {
locationUpdate(id, data);
} else {
setError('Etwas ist falsch, keine ID');
}
} else {
const res = await locationCreate(data);
/* if (!res.ok) {
setError("_id")
return
}
*/
router.push(sites.location.url)
}
}
return (
<div className="w-120 flex flex-col p-4 pt-10 ps-10" >
{modeUpdate ? <div>Update</div> : <div>Anlegen</div>}
<div className="border-1 p-4">
<form onSubmit={handleSubmit(onSubmit)} className="max-w-md mx-auto">
<InputTextR
label="Lagerort Bezeichnung"
{...register("name", { required: "Pflichtfeld" })}
error={errors.name?.message}
/>
<InputTextR
label="Beschreibung"
{...register("description")}
error={errors.description?.message}
/>
{locationTreeData &&
<Controller
name="parentLocationId"
control={control}
rules={{ required: false }}
render={({ field }) => (
<LocationTreeView data={locationTreeData}
onSelect={(id) => field.onChange(id)}
/>
)}
/>
}
<div>
{error && <div>{error}</div>}
{errors.name && <div>{errors.name.message}</div>}
</div>
<button
className="bg-blue-500 text-white p-2 rounded mt-2 hover:bg-blue-600"
type="submit">
Speichern
</button>
</form>
</div>
{debug &&
<div>
<div>{watch("name")}</div>
<pre>touched:{getFieldState("name").isTouched ? 'true' : 'false'}</pre>
<pre>{JSON.stringify(watch(), null, 2)}</pre>
</div>
}
</div>
)
}
@@ -0,0 +1,115 @@
"use client"
import { useEffect, useMemo, useState } from "react";
import { LocationTreeNode } from "../../types/inventory";
import { LocationTreeNodeItem } from "./LocationTreeNodeItem";
type Props = {
data: LocationTreeNode[];
onSelect: (node: LocationTreeNode) => void;
};
export function LocationTreeView({ data, onSelect }: Props) {
const [selectedId, setSelectedId] = useState<string | null>(null);
const [focusedId, setFocusedId] = useState<string | null>(null);
const [openMap, setOpenMap] = useState<Record<string, boolean>>({});
// sichtbare Nodes flach machen
const visibleNodes = useMemo(() => {
const result: LocationTreeNode[] = [];
function walk(nodes: LocationTreeNode[]) {
for (const n of nodes) {
result.push(n);
if (openMap[n._id]) {
walk(n.children);
}
}
}
walk(data);
return result;
}, [data, openMap]);
const handleSelect = (id:string)=>{
let node = visibleNodes.find((node)=> node._id === id)
console.log('nodex')
if(node) onSelect(node);
}
// initial focus
useEffect(() => {
if (!focusedId && visibleNodes.length > 0) {
setFocusedId(visibleNodes[0]._id);
}
console.log(visibleNodes)
}, [visibleNodes, focusedId]);
function handleKeyDown(e: React.KeyboardEvent) {
if (!focusedId) return;
const index = visibleNodes.findIndex(n => n._id === focusedId);
if (e.key === "ArrowDown") {
console.log('down')
e.preventDefault();
const next = visibleNodes[index + 1];
if (next) setFocusedId(next._id);
}
if (e.key === "ArrowUp") {
console.log('up')
e.preventDefault();
const prev = visibleNodes[index - 1];
if (prev) setFocusedId(prev._id);
}
if (e.key === "ArrowRight") {
console.log('right')
e.preventDefault();
setOpenMap(m => ({ ...m, [focusedId]: true }));
}
if (e.key === "ArrowLeft") {
console.log('left')
e.preventDefault();
setOpenMap(m => ({ ...m, [focusedId]: false }));
}
if (e.key === "Enter") {
e.preventDefault();
setSelectedId(focusedId);
handleSelect(focusedId);
}
if (e.key === "Space") {
e.preventDefault();
setSelectedId(focusedId);
handleSelect(focusedId);
}
console.log(e.key)
}
return (
<div
tabIndex={0}
onKeyDown={handleKeyDown}
className="border p-2 rounded outline-none focus:ring"
>
{data.map(node => (
<LocationTreeNodeItem
key={node._id}
node={node}
selectedId={selectedId}
focusedId={focusedId}
openMap={openMap}
setOpenMap={setOpenMap}
setFocusedId={setFocusedId}
onSelect={(id) => { setSelectedId(id); setFocusedId(id); handleSelect(id); }} />
))}
</div>
);
}
@@ -0,0 +1,33 @@
"use client";
import { useState } from "react";
import { LocationTreeNode, Location } from "../../types/inventory";
import { LocationTreeView } from "./location.treeView";
import { locationFindById } from "../../actions/location.actions";
import { LocationForm } from "./location.form";
interface Params {
data: LocationTreeNode[]
}
export function LocationView({ data }: Params) {
const [selectedLocation, setSelectedLocation] = useState<Location | undefined>();
const handleSelect = async (node: LocationTreeNode) => {
console.log('node',node);
// const node = await locationFindById(value);
setSelectedLocation(() => node);
}
return (
<div className="w-120 flex flex-col p-4 pt-10 ps-10">
<div>xxx</div>
<LocationTreeView data={data} onSelect={(item) => handleSelect(item)}></LocationTreeView>
{selectedLocation &&
<LocationForm initData={selectedLocation}></LocationForm>
}
</div>
);
}
@@ -0,0 +1,90 @@
"use client";
import { useEffect, useState } from "react"
import { Manufacturer, ManufacturerCreate, emptyManufacturer } from "../../types/catalog/manufacturer.types"
import { useForm } from "react-hook-form"
import { InputTextR } from "../ui/inputTextR";
import { manufacturerCreate, manufacturerUpdate } from '../../actions/manufacturer.actions'
interface Params {
initData?: Manufacturer
debug?: boolean,
onChangeData?:(data:Manufacturer)=>void
}
export const ManufactuererForm = ({ onChangeData, initData, debug }: Params) => {
const { register, handleSubmit, formState: { errors }, watch, getFieldState, reset } = useForm<ManufacturerCreate>({ defaultValues: emptyManufacturer, })
const [modeUpdate, setModeUpdate] = useState(false);
const [id, setId] = useState<string | undefined>();
const [error, setError] = useState(false);
const [errMsg, setErrMsg] = useState<string[]>([])
useEffect(() => {
if (initData) {
const { _id, name } = initData;
setId(_id);
setModeUpdate(true);
reset({ name })
}
}, []);
const onSubmit = async (data: ManufacturerCreate) => {
setError(false);
let result: ActionResult = { success: false, errors: [] };
if (modeUpdate) {
if (!id) {
setError(true);
setErrMsg(['Etwas ist falsch, keine ID']);
return;
}
result = await manufacturerUpdate(id, data);
} else {
result = await manufacturerCreate(data);
}
if (!result.success) {
setError(true)
setErrMsg(() => result.errors)
} else {
console.log(result)
onChangeData && onChangeData({_id:result.data._id,name:result.data.name})
setError(false)
}
}
return (
<div className="w-120 flex flex-col p-4 pt-10 ps-10" >
<div className="border-1 p-4">
<form onSubmit={handleSubmit(onSubmit)} className="max-w-md mx-auto">
<InputTextR label="Name" {...register("name", { required: "Pflichtfeld" })} error={errors.name?.message} />
<div>
{error && <div>{error}</div>}
{errors.name && <div>{errors.name.message}</div>}
</div>
<button type="submit" className="bg-blue-500 text-white p-2 rounded mt-2 hover:bg-blue-600">Speichern</button>
</form>
</div>
{debug &&
<div>
<div>{watch("name")}</div>
<pre>touched:{getFieldState("name").isTouched ? 'true' : 'false'}</pre>
<pre>{JSON.stringify(watch(), null, 2)}</pre>
</div>
}
{error && <div className="border-1 border-red-400 bg-red-200">
Error
{errMsg.map((msg,id)=>(<div key={id}>{msg}</div>))}
</div>}
</div>
)
}
@@ -0,0 +1,109 @@
"use client";
import { emptyArticleDto, Article, ArticleCreate, Category, Manufacturer, ArticleVariant } from "../../types/catalog"
import { FormProvider, useForm } from "react-hook-form"
import { articleCreate, articleUpdate } from "../../actions/article.actions";
import { useEffect, useState } from "react";
import Modal from "../ui/modal";
import { ManufactuererForm } from "../manufacturer/manufacturer.form";
import { Location, LocationTreeNode } from "../../types/inventory";
import { emptyStock, Stock, StockCreate } from "../../types/inventory/stockContent.types";
import { stockCreate, stockUpdate } from "../../actions/stock.actions";
import { InputTextR } from "../ui/inputTextR";
import { LocationView } from "../location/location.view";
import { LocationTreeView } from "../location/location.treeView";
interface Params {
categories: Category[]
article: Article[],
orte: LocationTreeNode[]
initData?: Stock
debug?: boolean
}
export const StockForm = ({ article, categories, initData, orte, debug }: Params) => {
const { register, reset, formState: { errors }, handleSubmit } = useForm<StockCreate>({ defaultValues: emptyStock });
const [errMsg, setErrorMsg] = useState<string[]>([])
const [selectetCategory, setSelectedCategory] = useState<Category>()
const [selectetArticle, setSelectedArticle] = useState<Article>()
const [selectetArticleVariant, setSelectedArticleVariant] = useState<ArticleVariant>()
const [selectetOrt, setSelectedOrt] = useState<Location>()
const [error, setError] = useState(false)
useEffect(() => {
if (initData && initData.id) {
reset(initData);
}
}, [initData])
const onSubmit = async (data: StockCreate) => {
if (initData?.id) {
const result = await stockUpdate(initData.id, data)
if (!result.success) {
setError(true)
setErrorMsg(() => result.errors)
console.log(result)
} else {
setError(false)
}
} else {
console.log('create')
const { articleVariantId, locationId, quantity, expiryDate, batchNumber } = data;
if (true) {
const create = {
articleVariantId,
locationId,
quantity,
expiryDate,
batchNumber
}
stockCreate(create);
}
}
};
const handleLocationSelect = (ort: LocationTreeNode) => {
setSelectedOrt(ort);
}
return (
<div className="me-30 flex flex-col p-4 pt-10 ps-10" >
{initData?.id && <div>{initData.id}</div>}
<form onSubmit={handleSubmit(onSubmit)}>
<InputTextR
label="Menge"
{...register("quantity", { required: "Pflichtfeld" })}
error={errors.quantity?.message}
/>
<button type="submit">Absenden</button>
</form>
<LocationTreeView data={orte} onSelect={(item) => handleLocationSelect(item)}></LocationTreeView>
{error && <div className="border-1 border-red-400 bg-red-200">
Error
{errMsg.map((msg, id) => (<div key={id}>{msg}</div>))}
</div>}
{selectetOrt && <div>{selectetOrt.name}</div>}
</div>
)
}
@@ -0,0 +1,25 @@
"use client";
import { useState } from "react"
import { InputText } from "../form/inputText"
interface Values{
name:string,
sonstiges:string
}
export const TestForm = ()=>{
const [values,setValues] = useState<Values>({name:"",sonstiges:""})
return (
<div>
<InputText label="Name" name="name" valueInit="wert" onTxtChange={(v)=>setValues((pre)=>({...pre,...v}))} />
<div>
<div>name:{values.name}</div>
<div>sonstiges:{values.sonstiges}</div>
</div>
</div>
)
}
@@ -0,0 +1,133 @@
"use client";
import { useState, useRef, useEffect } from "react";
import { Control, useController } from "react-hook-form";
export type Option = {
id: string;
value: string;
};
type ComboBoxRHFProps = {
name: string;
control: Control<any>;
options: Option[];
placeholder?: string;
};
export default function ComboBoxR({
name,
control,
options,
placeholder = "Option wählen...",
}: ComboBoxRHFProps) {
const { field: { value: formValue, onChange, onBlur }, } = useController({ name, control });
const [open, setOpen] = useState(false);
const [highlight, setHighlight] = useState(0);
const [inputValue, setInputValue] = useState("");
const wrapperRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
console.log('Change Value' + formValue)
}, [formValue])
// Sync Input mit RHF-Wert (wenn z.B. defaultValue gesetzt ist)
useEffect(() => {
console.log(`FromValue(${formValue})`)
const selected = options.find((o) => o.id === formValue);
if (selected) {
setInputValue(selected.value);
}
}, [formValue, options]);
// Klick außerhalb schließen
useEffect(() => {
function handleClickOutside(e: MouseEvent) {
if (
wrapperRef.current &&
!wrapperRef.current.contains(e.target as Node)
) {
setOpen(false);
onBlur();
}
}
document.addEventListener("mousedown", handleClickOutside);
return () =>
document.removeEventListener("mousedown", handleClickOutside);
}, [onBlur]);
const filtered = options.filter((opt) =>
opt.value.toLowerCase().includes(inputValue.toLowerCase())
);
function selectOption(opt: Option) {
setInputValue(opt.value); // Text anzeigen
onChange(opt.id); // ID ins Form-State
setOpen(false);
}
function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {
if (!open) setOpen(true);
if (e.key === "ArrowDown") {
e.preventDefault();
setHighlight((h) => Math.min(h + 1, filtered.length - 1));
}
if (e.key === "ArrowUp") {
e.preventDefault();
setHighlight((h) => Math.max(h - 1, 0));
}
if (e.key === "Enter") {
e.preventDefault();
selectOption(filtered[highlight]);
}
if (e.key === "Escape") {
setOpen(false);
}
if (e.key === "Tab") {
setOpen(false);
onBlur();
}
}
return (
<div ref={wrapperRef} className="relative w-64">
<input
value={inputValue}
placeholder={placeholder}
onChange={(e) => {
setInputValue(e.target.value); // ✅ frei tippen
setOpen(true);
}}
onFocus={() => setOpen(true)}
onBlur={(e) => {
if (!wrapperRef.current?.contains(e.relatedTarget as Node)) {
setOpen(false);
onBlur();
}
}}
onKeyDown={handleKeyDown}
className="w-full border border-gray-300 rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
{open && filtered.length > 0 && (
<ul className="absolute top-full left-0 w-full bg-white border border-gray-300 rounded shadow-lg max-h-40 overflow-y-auto z-50">
{filtered.map((opt, i) => (
<li
key={opt.id}
onMouseDown={() => selectOption(opt)}
onMouseEnter={() => setHighlight(i)}
className={`px-3 py-2 cursor-pointer ${i === highlight ? "bg-blue-100" : "hover:bg-gray-100"
}`}
>
{opt.value}
</li>
))}
</ul>
)}
</div>
);
}
+167
View File
@@ -0,0 +1,167 @@
"use client";
import { useState, useRef, useEffect } from "react";
import { Control, useController } from "react-hook-form";
export type Option = {
id: string;
value: string;
};
type ComboBoxRHFProps = {
name: string;
control: Control<any>;
options: Option[];
placeholder?: string;
};
export default function ComboBoxR({ name, control, options, placeholder = "Option wählen...", }: ComboBoxRHFProps) {
const { field: { value: formValue, onChange, onBlur }, } = useController({ name, control });
const [open, setOpen] = useState(false);
const [highlight, setHighlight] = useState(0);
const [inputValue, setInputValue] = useState("");
const wrapperRef = useRef<HTMLDivElement | null>(null);
const inputRef = useRef<HTMLInputElement | null>(null);
const divRef = useRef<HTMLDivElement | null>(null);
// Sync Input mit RHF-Wert (wenn z.B. defaultValue gesetzt ist)
useEffect(() => {
const selected = options.find((o) => o.id === formValue);
if (selected) setInputValue(selected.value);
}, [formValue, options]);
useEffect(() => {
if (open) {
setInputValue("");
requestAnimationFrame(() => {
inputRef.current?.focus();
});
}
}, [open]);
// Klick außerhalb schließen
useEffect(() => {
function handleClickOutside(e: MouseEvent) {
console.log('Close outside',open)
if (!open) return;
console.log('Close outside2')
if (wrapperRef.current && !wrapperRef.current.contains(e.target as Node)) {
closeOnly();
}
}
document.addEventListener("mousedown", handleClickOutside);
return () =>
document.removeEventListener("mousedown", handleClickOutside);
}, [open]);
function closeOnly() {
console.log('Aufruf close only')
setOpen(false);
onBlur();
requestAnimationFrame(() => {
divRef.current?.focus();
});
}
function closeAndFocusDiv() {
setOpen(false);
onBlur();
requestAnimationFrame(() => {
divRef.current?.focus();
});
}
const filtered = options.filter((opt) =>
opt.value.toLowerCase().includes(inputValue.toLowerCase())
);
function selectOption(opt: Option) {
setInputValue(opt.value); // Text anzeigen
onChange(opt.id); // ID ins Form-State
setOpen(false);
requestAnimationFrame(() => {
divRef.current?.focus();
});
}
function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {
if (!open) setOpen(true);
if (e.key === "ArrowDown") {
e.preventDefault();
setHighlight((h) => Math.min(h + 1, filtered.length - 1));
}
if (e.key === "ArrowUp") {
e.preventDefault();
setHighlight((h) => Math.max(h - 1, 0));
}
if (e.key === "Enter") {
e.preventDefault();
selectOption(filtered[highlight]);
}
if (e.key === "Escape") {
setOpen(false);
}
if (e.key === "Tab") {
closeAndFocusDiv();
}
}
const selectedValue = options.find((item) => item.id == formValue)
return (
<div ref={wrapperRef} className="relative w-64">
{open &&
<input
ref={inputRef}
value={inputValue}
placeholder={placeholder}
onChange={(e) => { setInputValue(e.target.value); setOpen(true); }}
onKeyDown={handleKeyDown}
className="w-full border border-gray-300 rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
}
{!open && (
<div
ref={divRef}
tabIndex={0}
onClick={() => setOpen(true)}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
setOpen(true);
}
}}
className="border px-3 py-2 rounded cursor-pointer focus:ring-2 focus:ring-blue-500"
>
{selectedValue?.value || placeholder}
</div>
)}
{open && filtered.length > 0 && (
<ul className="absolute top-full left-0 w-full bg-white border border-gray-300 rounded shadow-lg max-h-40 overflow-y-auto z-50">
{filtered.map((opt, i) => (
<li
key={opt.id}
onMouseDown={() => selectOption(opt)}
onMouseEnter={() => setHighlight(i)}
className={`px-3 py-2 cursor-pointer ${i === highlight ? "bg-blue-100" : "hover:bg-gray-100"
}`}
>
{opt.value}
</li>
))}
</ul>
)}
</div>
);
}
@@ -0,0 +1,186 @@
"use client";
import { useState, useRef, useEffect } from "react";
import { createPortal } from "react-dom";
import { ChevronDown } from "lucide-react";
type DropdownItem = { id: string, value: string };
interface Props {
placeholder?:string
items: DropdownItem[];
value?: DropdownItem | null; // id
onChange?: (item: DropdownItem) => void;
}
export default function SelectAndSearch2({ placeholder,items, value, onChange }: Props) {
const [open, setOpen] = useState(false);
const [selected, setSelected] = useState<DropdownItem>(value ?? {id:"",value:""});
const [query, setQuery] = useState("");
const [highlightIndex, setHighlightIndex] = useState(0);
const [filtered, setFiltered] = useState<DropdownItem[]>(items);
const buttonRef = useRef<HTMLButtonElement>(null);
const searchRef = useRef<HTMLInputElement>(null);
const itemRefs = useRef<HTMLButtonElement[]>([]);
const [position, setPosition] = useState({ top: 0, left: 0, width: 0 });
useEffect(() => {
setFiltered(items);
}, [items]);
// Gefilterte Liste
useEffect(() => {
const filtered = items.filter((cat) =>
cat.value.toLowerCase().includes(query.toLowerCase()))
setFiltered(() => filtered)
}, [query])
// Dropdown-Position aktualisieren
const updatePosition = () => {
if (!buttonRef.current) return;
const rect = buttonRef.current.getBoundingClientRect();
setPosition({
top: rect.bottom + window.scrollY,
left: rect.left + window.scrollX,
width: rect.width,
});
};
// Öffnen → positionieren & Fokus setzen
useEffect(() => {
if (open) {
updatePosition();
setTimeout(() => searchRef.current?.focus(), 0);
window.addEventListener("resize", updatePosition);
window.addEventListener("scroll", updatePosition);
}
return () => {
window.removeEventListener("resize", updatePosition);
window.removeEventListener("scroll", updatePosition);
};
}, [open]);
// Dropdown schließen bei Klick außerhalb
useEffect(() => {
const handleClick = (e: MouseEvent) => {
if (buttonRef.current && !buttonRef.current.contains(e.target as Node)) {
setOpen(false);
}
};
document.addEventListener("click", handleClick);
return () => document.removeEventListener("click", handleClick);
}, []);
// Tastatursteuerung
const handleKey = (e: React.KeyboardEvent) => {
if (!open) return;
switch (e.key) {
case "ArrowDown":
e.preventDefault();
setHighlightIndex((i) => Math.min(i + 1, filtered.length - 1));
break;
case "ArrowUp":
e.preventDefault();
setHighlightIndex((i) => Math.max(i - 1, 0));
break;
case "Enter":
e.preventDefault();
if (filtered[highlightIndex]) {
choose(filtered[highlightIndex]);
}
break;
case "Escape":
setOpen(false);
break;
}
};
useEffect(() => {
const el = itemRefs.current[highlightIndex];
if (el) {
el.scrollIntoView({ block: "nearest" });
}
}, [highlightIndex]);
const choose = (cat: DropdownItem) => {
console.log('Change',cat)
setSelected(cat);
setOpen(false);
if(onChange) onChange(cat);
setTimeout(() => {
buttonRef.current?.focus();
}, 0);
};
return (
<>
<button
ref={buttonRef}
onClick={() => setOpen((o) => !o)}
onKeyDown={handleKey}
className="flex justify-between items-center px-4 py-2 border border-gray-300 rounded-xl w-64 bg-white"
>
<span>{selected.value || placeholder ||"auswählen…"}</span>
<ChevronDown className="w-4 h-4" />
</button>
{open &&
createPortal(
<div
className="absolute bg-white border border-gray-200 rounded-xl shadow-lg z-50"
style={{
top: position.top,
left: position.left,
width: position.width,
}}
>
{/* Suchfeld */}
<div className="p-2 border-b border-gray-100">
<input
ref={searchRef}
value={query}
onChange={(e) => {
setQuery(e.target.value);
setHighlightIndex(0);
}}
onKeyDown={handleKey}
className="w-full px-2 py-1 border border-gray-300 rounded-md"
placeholder="Suchen..."
/>
</div>
{/* Liste */}
<div className="max-h-60 overflow-auto">
{filtered.map((cat, index) => (
<button
key={cat.id}
ref={(el) => { itemRefs.current[index] = el!; }}
onClick={() => choose(cat)}
className={`w-full text-left px-4 py-2
${index === highlightIndex
? "bg-gray-200"
: "hover:bg-gray-100"
}
`}
>
{cat.value}
</button>
))}
{filtered.length === 0 && (
<div className="px-4 py-3 text-gray-500">Keine Treffer…</div>
)}
</div>
</div>,
document.body
)}
</>
);
}
+109
View File
@@ -0,0 +1,109 @@
"use client";
import React, { useState, useRef, useEffect } from "react";
interface Option {
id: string, value: string
}
interface Props {
options: Option[]
onSelect: (value: Option) => void
}
export default function SelectTest({ options = [], onSelect }: Props) {
const [open, setOpen] = useState(false);
const [highlight, setHighlight] = useState(0);
const [value, setValue] = useState("");
const wrapperRef = useRef<HTMLDivElement>(null);
// Klick außerhalb schließen
useEffect(() => {
function handleClickOutside(e: any) {
if (wrapperRef.current && !wrapperRef.current.contains(e.target)) {
setOpen(false);
}
}
document.addEventListener("mousedown", handleClickOutside);
return () => document.removeEventListener("mousedown", handleClickOutside);
}, []);
const filtered = options.filter((opt) =>
opt.value.toLowerCase().includes(value.toLowerCase())
);
function handleKeyDown(e: React.KeyboardEvent) {
if (!open) setOpen(true);
if (e.key === "ArrowDown") {
e.preventDefault();
setHighlight((h) => Math.min(h + 1, filtered.length - 1));
}
if (e.key === "ArrowUp") {
e.preventDefault();
setHighlight((h) => Math.max(h - 1, 0));
}
if (e.key === "Enter") {
e.preventDefault();
selectOption(filtered[highlight]);
}
if (e.key === "Escape") {
setOpen(false);
}
if (e.key === "Tab") {
setOpen(false);
}
}
function selectOption(opt: Option) {
if (!opt) return;
setValue(opt.value);
setOpen(false);
onSelect?.(opt);
}
return (
<div ref={wrapperRef} className="relative w-64">
<input
value={value}
onChange={(e) => {
setValue(e.target.value);
setOpen(true);
}}
onFocus={() => setOpen(true)}
onBlur={(e) => {
if (!wrapperRef.current?.contains(e.relatedTarget)) {
setOpen(false);
}
}}
onKeyDown={handleKeyDown}
style={{
width: "100%",
padding: "8px",
border: "1px solid #ccc",
borderRadius: 4,
}}
placeholder="Wähle Option..."
/>
{open && filtered.length > 0 && (
<ul
className="absolute top-full left-0 w-full bg-white border border-gray-300 rounded shadow-lg max-h-40 overflow-y-auto z-50"
>
{filtered.map((opt, i) => (
<li
key={opt.id}
onMouseDown={() => selectOption(opt)}
className={`px-3 py-2 cursor-pointer ${
i === highlight ? "bg-blue-100" : "hover:bg-gray-100"
}`}
onMouseEnter={() => setHighlight(i)}
>
{opt.value}
</li>
))}
</ul>
)}
</div>
);
}
@@ -0,0 +1,27 @@
import { useEffect, useState } from "react"
import { forwardRef } from "react"
interface ChangeValue {
[key: string]: boolean
}
interface Props extends React.InputHTMLAttributes<HTMLInputElement> {
label?: string
error?: string | undefined
}
export const InputCheckboxR = forwardRef<HTMLInputElement, Props>(
({ label, error, ...props }, ref) => {
return (
<div className="p-2 mb-1 mt-1 bg-green-0 flex items-center">
<input ref={ref} type="checkbox" className=" me-2 w-6 h-6 " {...props} />
{label && <div className="text-md font-normal text-gray-00 font-mono ps-1">{label}</div>}
</div>
)
}
)
@@ -0,0 +1,30 @@
import { forwardRef } from "react"
interface InputTextProps
extends React.InputHTMLAttributes<HTMLInputElement> {
label?: string
error?: string | undefined
}
export const InputTextR = forwardRef<HTMLInputElement, InputTextProps>(
({ label, error, ...props }, ref) => {
return (
<div className="mb-1 bg-green-00">
{label && (
<label className="text-sm font-normal text-gray-600 font-mono ps-1">
{label}
</label>
)}
<input ref={ref}
className={`w-full ps-2 h-7 border rounded ${error ? "border-red-500" : "border-gray-300"} focus:outline-none focus:ring-1 focus:ring-blue-800`}
{...props}
/>
{false && error && <p className="text-red-500 text-sm mt-1">{error}</p>}
</div>
)
}
)
InputTextR.displayName = "InputR"
+49
View File
@@ -0,0 +1,49 @@
"use client";
import { useEffect } from "react";
interface Props {
open: boolean;
onClose: () => void;
children: React.ReactNode;
}
export default function Modal({ open, onClose, children }: Props) {
// ESC-Taste schließen
useEffect(() => {
function handleEsc(e: KeyboardEvent) {
if (e.key === "Escape") onClose();
}
if (open) {
window.addEventListener("keydown", handleEsc);
}
return () => window.removeEventListener("keydown", handleEsc);
}, [open, onClose]);
if (!open) return null;
return (
<div style={overlayStyle} onClick={onClose}>
<div style={modalStyle} onClick={(e) => e.stopPropagation()}>
{children}
</div>
</div>
);
}
const overlayStyle = {
position: "fixed" as const,
inset: 0,
backgroundColor: "rgba(0,0,0,0.5)",
display: "flex",
justifyContent: "center",
alignItems: "center",
};
const modalStyle = {
backgroundColor: "white",
padding: "20px",
borderRadius: "8px",
minWidth: "300px",
};
+39
View File
@@ -0,0 +1,39 @@
import { forwardRef, useRef, useState } from "react"
interface Props
extends React.InputHTMLAttributes<HTMLSelectElement> {
values: { id: string, value: string }[]
}
export const SelectR = forwardRef<HTMLSelectElement, Props>(
({ values, ...props }, ref) => {
const inputRef = useRef<HTMLInputElement>(null)
const [open, setOpen] = useState(false);
return (
<div className="border-4 border-black mb-1 p-1 bg-green-100 border-1 border-gray-200 " >
<div>
<input type="text" ref={inputRef} onFocus={() => setOpen(true)} className="bg-green-100"
onBlur={() => setOpen(false)} />
</div>
<div className="relative">
<select
ref={ref}
{...props}
size={open ? 5 : 1}
style={{ position: "absolute", top: "0", left: 0, width: "100%", zIndex: 1000, backgroundColor: "white", border: "1px solid #ccc", }}
className="w-10"
>
{values.map(c => (
<option key={c.id} value={c.id}>
{c.value}
</option>
))}
</select>
</div>
</div>
)
}
)
SelectR.displayName = "SelectR"
+109
View File
@@ -0,0 +1,109 @@
"use client"
import { useEffect, useMemo, useState } from "react";
import { LocationTreeNode } from "../../types/inventory";
import { LocationTreeNodeItem } from "../location/LocationTreeNodeItem";
type Props = {
data: LocationTreeNode[];
onSelect: (id: string | null) => void;
};
export function TreeViewXXXold({ data, onSelect }: Props) {
const [selectedId, setSelectedId] = useState<string | null>(null);
const [focusedId, setFocusedId] = useState<string | null>(null);
const [openMap, setOpenMap] = useState<Record<string, boolean>>({});
// sichtbare Nodes flach machen
const visibleNodes = useMemo(() => {
const result: LocationTreeNode[] = [];
function walk(nodes: LocationTreeNode[]) {
for (const n of nodes) {
result.push(n);
if (openMap[n._id]) {
walk(n.children);
}
}
}
walk(data);
return result;
}, [data, openMap]);
// initial focus
useEffect(() => {
if (!focusedId && visibleNodes.length > 0) {
setFocusedId(visibleNodes[0]._id);
}
console.log(visibleNodes)
}, [visibleNodes, focusedId]);
function handleKeyDown(e: React.KeyboardEvent) {
if (!focusedId) return;
const index = visibleNodes.findIndex(n => n._id === focusedId);
if (e.key === "ArrowDown") {
console.log('down')
e.preventDefault();
const next = visibleNodes[index + 1];
if (next) setFocusedId(next._id);
}
if (e.key === "ArrowUp") {
console.log('up')
e.preventDefault();
const prev = visibleNodes[index - 1];
if (prev) setFocusedId(prev._id);
}
if (e.key === "ArrowRight") {
console.log('right')
e.preventDefault();
setOpenMap(m => ({ ...m, [focusedId]: true }));
}
if (e.key === "ArrowLeft") {
console.log('left')
e.preventDefault();
setOpenMap(m => ({ ...m, [focusedId]: false }));
}
if (e.key === "Enter") {
e.preventDefault();
setSelectedId(focusedId);
onSelect(focusedId);
}
if (e.key === "Space") {
e.preventDefault();
setSelectedId(focusedId);
onSelect(focusedId);
}
console.log(e.key)
}
return (
<div
tabIndex={0}
onKeyDown={handleKeyDown}
className="border p-2 rounded outline-none focus:ring"
>
{data.map(node => (
<LocationTreeNodeItem
key={node._id}
node={node}
selectedId={selectedId}
focusedId={focusedId}
openMap={openMap}
setOpenMap={setOpenMap}
setFocusedId={setFocusedId}
onSelect={(id) => { setSelectedId(id); setFocusedId(id); onSelect(id); }} />
))}
</div>
);
}
+31
View File
@@ -0,0 +1,31 @@
import path from "path";
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
reactStrictMode: true,
webpack: (config) => {
// Alias für dein Shared-Package
config.resolve.alias["@male/shared"] = path.resolve(
__dirname,
"packages/shared/dist"
);
// Optional: falls du @/* für src nutzen willst
config.resolve.alias["@"] = path.resolve(__dirname, "src");
return config;
},
};
/*
export default nextConfig;
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
reactStrictMode: true,
};
export default nextConfig;
*/
+28
View File
@@ -0,0 +1,28 @@
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"dev_old": "next dev",
"dev": "next dev -H 192.168.50.205 -p 4000",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@hookform/resolvers": "^5.2.2",
"lucide-react": "^0.563.0",
"next": "16.1.4",
"react": "19.2.3",
"react-dom": "19.2.3",
"react-hook-form": "^7.71.1",
"socket.io-client": "^4.8.3"
},
"devDependencies": {
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"tailwindcss": "^4",
"typescript": "^5"
}
}
+7
View File
@@ -0,0 +1,7 @@
const config = {
plugins: {
"@tailwindcss/postcss": {},
},
};
export default config;
+1
View File
@@ -0,0 +1 @@
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 391 B

+1
View File
@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

+1
View File
@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>

After

Width:  |  Height:  |  Size: 128 B

+1
View File
@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>

After

Width:  |  Height:  |  Size: 385 B

+35
View File
@@ -0,0 +1,35 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts"
],
"exclude": ["node_modules"],
"extends": "../../tsconfig.json"
}
+9
View File
@@ -0,0 +1,9 @@
type ValidationError = {
errors: string[];
};
type ActionResult =
| { success: true,data?:any }
| { success: false; errors: string[] };
@@ -0,0 +1,93 @@
import { Category } from "./category.types";
import {Manufacturer,emptyManufacturer} from "./manufacturer.types"
export interface Article {
_id: string,
name: string,
category: Category;
attributes?: Record<string, any>;
variants: Variant[],
}
export interface ArticleCreate {
name: string;
categoryId: string;
attributes?: Record<string, any>;
variants: Variant[],
}
//--- Artikel Variante
export interface ArticleVariant {
_id: string;
article: Article;
manufacturer: Manufacturer;
supplierArticleNumber?: string;
packagingUnit?: string;
extra?: Record<string, any>;
}
export interface ArticleVariantCreate {
articleId: string;
manufacturerId: string;
supplierArticleNumber?: string;
packagingUnit?: string;
extra?: Record<string, any>;
}
export interface Variant {
_id?: string;
manufacturerId: string;
supplierArticleNumber?: string;
packagingUnit?: string;
extra?: Record<string, any>;
}
export interface VariantCreate {
manufacturerId: string;
supplierArticleNumber?: string;
packagingUnit?: string;
extra?: Record<string, any>;
}
export const emptyArticle = {
name: '',
}
export const emptyArticleVariant = {
article: emptyArticle,
manufacturer: emptyManufacturer
}
export const emptyArticleDto:ArticleCreate = {
name:'',
categoryId:'',
variants:[]
}
//Upsert
export interface ArticleUpsert {
_id:string,
name: string;
categoryId?: string;
attributes?: Record<string, any>;
variants: VariantUpsert[],
}
export interface VariantUpsert {
_id?:string
manufacturerId: string;
supplierArticleNumber?: string;
packagingUnit?: string;
extra?: Record<string, any>;
deleted?:boolean;
}
@@ -0,0 +1,26 @@
export interface CategoryCreate {
name: string;
isConsumable: boolean;
description?: string;
parentCategoryId?: string;
requiredAttributes?: Record<string, any>;
}
export interface Category {
_id:string
name: string
isConsumable: boolean
description?: string
parentCategoryId?: string
parentName?:string
requiredAttributes?: Record<string, any>
}
export const emptyCategory = {
name: '',
isConsumable: false,
// description: ''
}
+3
View File
@@ -0,0 +1,3 @@
export * from './category.types';
export * from './article.types';
export * from './manufacturer.types';
@@ -0,0 +1,19 @@
export interface ManufacturerCreate {
name: string;
}
export interface ManufacturerUpdate {
name?: string;
}
export interface Manufacturer {
_id:string
name: string
}
export const emptyManufacturer = {
name: '',
}
+1
View File
@@ -0,0 +1 @@
export * from './location.types'
@@ -0,0 +1,36 @@
export interface LocationMutaion {
name: string;
description?: string;
parentLocationId?: string;
}
export interface LocationCreate {
name: string;
description?: string;
parentLocationId?: string;
}
export interface LocationUpdate {
name?: string;
description?: string;
parentLocationId?: string;
}
export interface Location {
_id:string;
name: string;
description?: string;
parentLocationId?: string;
}
export const emptyLocation = {
name: ''
}
export interface LocationTreeNode {
_id: string;
name: string;
parentLocationId?: string;
children: LocationTreeNode[];
}
@@ -0,0 +1,20 @@
import { Location } from "./location.types";
export interface StockCreate {
name: string;
locationId: string;
areas?:string[]
}
export interface StockUpdate {
name?: string;
locationId?: string;
areas?:string[]
}
export interface Stock {
id: string
name: string;
location: Location;
areas?:string[]
}
@@ -0,0 +1,36 @@
export interface Stock {
id: string
articleVariantId: string
locationId: string
quantity: number
expiryDate?: Date
batchNumber: string
}
export interface StockCreate {
articleVariantId: string
locationId: string
quantity: number
expiryDate?: Date
batchNumber: string
}
export interface StockUpdate {
articleVariantId?: string
locationId?: string
quantity?: number
expiryDate?: Date
batchNumber?: string
}
export const emptyStock:StockCreate = {
articleVariantId: '',
locationId: '',
quantity: 0,
expiryDate: new Date(),
batchNumber: '1'
}
@@ -0,0 +1,28 @@
export interface StockMovementIn {
stockId: string;
articleVariantId: string;
quantity: number;
batchNumber?: string;
expiryDate?: Date;
area?: string;
}
export interface StockMovementOut {
stockContentId: string;
quantity: number;
}
export interface StockMovementTransfer {
articleVariantId: string;
fromStockId: string;
toStockId: string;
toArea?: string;
quantity: number;
batchNumber?: string;
}