feat(modules): connections, products, jobs (list/form/detail-placeholder)

Connections (clinic ↔ lab)
  - request via member number, approve/reject (counterparty), cancel pending,
    delete approved
  - permission rows opened to both teams; audit log for every mutation
  - /connections page: own code card, request form, pending inbound/outbound
    tables, approved connections table with delete confirm

Products (lab catalog)
  - createProstheticAction + update + archive/restore + delete (lab-only)
  - zod validation, dev-mode error surfacing
  - /products page: catalog table + add form + edit dialog. Hidden from
    clinic accounts via requireTenantKind.

Jobs (work orders)
  - createJobAction (clinic-only) — checks approved connection before write,
    permissions opened to both clinic and lab teams
  - listInboundJobs (lab perspective), listOutboundJobs (clinic perspective),
    listApprovedLabsForClinic for the new-job form
  - /jobs/inbound + /jobs/outbound tables with role-aware copy
  - /jobs/new full form (lab select, patient code, prosthetic type, member
    count, color, due date, price/currency, description)
  - /jobs/[jobId] placeholder detail page with stepper visualisation;
    status/step updates and file upload come next session

All new mutations follow the memory rules: schema-checked row payloads,
admin client behind requireTenant + requireRole/requireTenantKind, audit
log calls best-effort, no empty-string Radix Select values.
This commit is contained in:
kovakmedya
2026-05-21 19:59:23 +03:00
parent 7fb8288f79
commit 76e02754b8
26 changed files with 2765 additions and 42 deletions
@@ -0,0 +1,189 @@
"use client";
import { useActionState, useEffect } from "react";
import { useRouter } from "next/navigation";
import { Loader2, Send } from "lucide-react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { Textarea } from "@/components/ui/textarea";
import { createJobAction } from "@/lib/appwrite/job-actions";
import {
PROSTHETIC_TYPE_LABELS,
initialJobFormState,
} from "@/lib/appwrite/job-types";
import type { JobCounterpart } from "@/lib/appwrite/job-queries";
import type { ProstheticType } from "@/lib/appwrite/schema";
const PROSTHETIC_TYPES: ProstheticType[] = [
"metal_porselen",
"zirkonyum",
"implant_ustu_zirkonyum",
"gecici",
"e_max",
"diger",
];
export function NewJobForm({
labs,
defaultCurrency,
}: {
labs: JobCounterpart[];
defaultCurrency: string;
}) {
const router = useRouter();
const [state, action, pending] = useActionState(createJobAction, initialJobFormState);
useEffect(() => {
if (state.ok) {
toast.success("İş yayınlandı.");
router.push("/jobs/outbound");
} else if (state.error) {
toast.error(state.error);
}
}, [state, router]);
return (
<form action={action} className="grid gap-5">
<div className="grid gap-3 md:grid-cols-2">
<div className="grid gap-2 md:col-span-2">
<Label htmlFor="labTenantId">Laboratuvar *</Label>
<Select name="labTenantId" required defaultValue={labs[0]?.tenantId}>
<SelectTrigger id="labTenantId">
<SelectValue placeholder="Bir laboratuvar seçin" />
</SelectTrigger>
<SelectContent>
{labs.map((l) => (
<SelectItem key={l.tenantId} value={l.tenantId}>
{l.companyName}
</SelectItem>
))}
</SelectContent>
</Select>
{state.fieldErrors?.labTenantId && (
<p className="text-destructive text-xs">{state.fieldErrors.labTenantId}</p>
)}
</div>
<div className="grid gap-2">
<Label htmlFor="patientCode">Hasta Kodu *</Label>
<Input
id="patientCode"
name="patientCode"
required
maxLength={50}
placeholder="Örn. 000892"
/>
{state.fieldErrors?.patientCode && (
<p className="text-destructive text-xs">{state.fieldErrors.patientCode}</p>
)}
</div>
<div className="grid gap-2">
<Label htmlFor="memberCount">Üye Sayısı *</Label>
<Input
id="memberCount"
name="memberCount"
type="number"
min="1"
max="32"
required
defaultValue={1}
/>
{state.fieldErrors?.memberCount && (
<p className="text-destructive text-xs">{state.fieldErrors.memberCount}</p>
)}
</div>
<div className="grid gap-2">
<Label htmlFor="prostheticType">Protez Türü *</Label>
<Select name="prostheticType" required>
<SelectTrigger id="prostheticType">
<SelectValue placeholder="Tür seçin" />
</SelectTrigger>
<SelectContent>
{PROSTHETIC_TYPES.map((t) => (
<SelectItem key={t} value={t}>
{PROSTHETIC_TYPE_LABELS[t]}
</SelectItem>
))}
</SelectContent>
</Select>
{state.fieldErrors?.prostheticType && (
<p className="text-destructive text-xs">{state.fieldErrors.prostheticType}</p>
)}
</div>
<div className="grid gap-2">
<Label htmlFor="color">Renk (Vita)</Label>
<Input id="color" name="color" maxLength={20} placeholder="Örn. A2" />
</div>
<div className="grid gap-2">
<Label htmlFor="dueDate">Termin Tarihi</Label>
<Input id="dueDate" name="dueDate" type="date" />
</div>
<div className="grid grid-cols-[1fr_100px] gap-2">
<div className="grid gap-2">
<Label htmlFor="price">Fiyat</Label>
<Input
id="price"
name="price"
type="number"
step="0.01"
min="0"
placeholder="0.00"
/>
</div>
<div className="grid gap-2">
<Label htmlFor="currency">Para</Label>
<Input
id="currency"
name="currency"
defaultValue={defaultCurrency}
maxLength={8}
style={{ textTransform: "uppercase" }}
/>
</div>
</div>
<div className="grid gap-2 md:col-span-2">
<Label htmlFor="description">Açıklama</Label>
<Textarea
id="description"
name="description"
rows={4}
maxLength={2000}
placeholder="Lab'a iletmek istediğiniz notlar — hijyenik gövde, materyal tercihi, vs."
/>
</div>
</div>
<div className="flex justify-end">
<Button type="submit" disabled={pending || labs.length === 0}>
{pending ? (
<>
<Loader2 className="size-4 animate-spin" />
Gönderiliyor...
</>
) : (
<>
<Send className="size-4" />
İşi Yayınla
</>
)}
</Button>
</div>
</form>
);
}
+39 -9
View File
@@ -1,7 +1,15 @@
import Link from "next/link";
import { redirect } from "next/navigation";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { listApprovedLabsForClinic } from "@/lib/appwrite/job-queries";
import { requireTenant, requireTenantKind } from "@/lib/appwrite/tenant-guard";
import { NewJobForm } from "./components/new-job-form";
export const metadata = {
title: "DLS — Yeni İş Yayınla",
};
export default async function NewJobPage() {
let ctx;
@@ -12,6 +20,9 @@ export default async function NewJobPage() {
redirect("/dashboard");
}
const labs = await listApprovedLabsForClinic(ctx.tenantId);
const defaultCurrency = ctx.settings?.defaultCurrency ?? "TRY";
return (
<div className="flex-1 space-y-6 px-6">
<div className="flex flex-col gap-1">
@@ -20,15 +31,34 @@ export default async function NewJobPage() {
Bağlı laboratuvarınıza yeni bir protez işi gönderin.
</p>
</div>
<Card>
<CardHeader>
<CardTitle>Yapım aşamasında</CardTitle>
<CardDescription>
Form (lab seçimi, hasta kodu, protez türü, renk, dosya yükleme) sonraki sürümde eklenecek.
</CardDescription>
</CardHeader>
<CardContent />
</Card>
{labs.length === 0 ? (
<Card>
<CardHeader>
<CardTitle>Önce bir laboratuvarla bağlantı kurun</CardTitle>
<CardDescription>
İş gönderebilmeniz için onaylanmış bir laboratuvar bağlantınız olmalı.
</CardDescription>
</CardHeader>
<CardContent>
<Button asChild>
<Link href="/connections">Bağlantı Kur</Link>
</Button>
</CardContent>
</Card>
) : (
<Card>
<CardHeader>
<CardTitle>İş Bilgileri</CardTitle>
<CardDescription>
Hasta kodu, protez türü ve diğer detayları girin. Dosya yüklemesi sonraki sürümde.
</CardDescription>
</CardHeader>
<CardContent>
<NewJobForm labs={labs} defaultCurrency={defaultCurrency} />
</CardContent>
</Card>
)}
</div>
);
}