260322:1648 Correct Coresspondence / Doing RFA / Correct CI
This commit is contained in:
@@ -1,19 +1,12 @@
|
||||
"use client";
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { documentNumberingService } from "@/lib/services/document-numbering.service";
|
||||
import { format } from "date-fns";
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
import { documentNumberingService } from '@/lib/services/document-numbering.service';
|
||||
import { format } from 'date-fns';
|
||||
|
||||
export function AuditLogsTable() {
|
||||
const [logs, setLogs] = useState<any[]>([]); // Replace with AuditLog type
|
||||
const [logs, setLogs] = useState<unknown[]>([]); // Replace with AuditLog type
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -21,9 +14,9 @@ export function AuditLogsTable() {
|
||||
try {
|
||||
const data = await documentNumberingService.getMetrics(); // Using metrics endpoint for now as it contains logs
|
||||
if (data && data.audit) {
|
||||
setLogs(data.audit);
|
||||
setLogs(data.audit);
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
// Failed to fetch audit logs - empty state shown
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -49,15 +42,17 @@ export function AuditLogsTable() {
|
||||
<TableBody>
|
||||
{logs.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={5} className="text-center">No logs found.</TableCell>
|
||||
<TableCell colSpan={5} className="text-center">
|
||||
No logs found.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
logs.map((log) => (
|
||||
<TableRow key={log.id}>
|
||||
<TableCell>{format(new Date(log.createdAt), "yyyy-MM-dd HH:mm:ss")}</TableCell>
|
||||
<TableCell>{format(new Date(log.createdAt), 'yyyy-MM-dd HH:mm:ss')}</TableCell>
|
||||
<TableCell>{log.operation}</TableCell>
|
||||
<TableCell>{log.generatedNumber}</TableCell>
|
||||
<TableCell>{log.createdBy || "System"}</TableCell>
|
||||
<TableCell>{log.createdBy || 'System'}</TableCell>
|
||||
<TableCell>{log.status}</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
"use client";
|
||||
'use client';
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { toast } from "sonner";
|
||||
import { documentNumberingService } from "@/lib/services/document-numbering.service";
|
||||
import { useState } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { toast } from 'sonner';
|
||||
import { documentNumberingService } from '@/lib/services/document-numbering.service';
|
||||
|
||||
export function BulkImportForm({ projectId = 1 }: { projectId?: number | string }) {
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
@@ -22,14 +22,14 @@ export function BulkImportForm({ projectId = 1 }: { projectId?: number | string
|
||||
setLoading(true);
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
formData.append("projectId", projectId.toString());
|
||||
formData.append('file', file);
|
||||
formData.append('projectId', projectId.toString());
|
||||
|
||||
await documentNumberingService.bulkImport(formData);
|
||||
toast.success("Bulk import initiated. Check audit logs for progress.");
|
||||
toast.success('Bulk import initiated. Check audit logs for progress.');
|
||||
setFile(null);
|
||||
} catch (error) {
|
||||
toast.error("Failed to import numbers.");
|
||||
} catch (_error) {
|
||||
toast.error('Failed to import numbers.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -37,17 +37,17 @@ export function BulkImportForm({ projectId = 1 }: { projectId?: number | string
|
||||
|
||||
return (
|
||||
<div className="border p-4 rounded-md space-y-4">
|
||||
<h3 className="text-lg font-medium">Bulk Import Numbers</h3>
|
||||
<p className="text-sm text-gray-500">Import legacy numbers via CSV to reserve them in the system.</p>
|
||||
<h3 className="text-lg font-medium">Bulk Import Numbers</h3>
|
||||
<p className="text-sm text-gray-500">Import legacy numbers via CSV to reserve them in the system.</p>
|
||||
|
||||
<div className="grid w-full max-w-sm items-center gap-1.5">
|
||||
<Label htmlFor="csv-file">CSV File</Label>
|
||||
<Input id="csv-file" type="file" accept=".csv,.xlsx" onChange={handleFileChange} />
|
||||
</div>
|
||||
<div className="grid w-full max-w-sm items-center gap-1.5">
|
||||
<Label htmlFor="csv-file">CSV File</Label>
|
||||
<Input id="csv-file" type="file" accept=".csv,.xlsx" onChange={handleFileChange} />
|
||||
</div>
|
||||
|
||||
<Button onClick={handleUpload} disabled={!file || loading}>
|
||||
{loading ? "Importing..." : "Upload & Import"}
|
||||
</Button>
|
||||
<Button onClick={handleUpload} disabled={!file || loading}>
|
||||
{loading ? 'Importing...' : 'Upload & Import'}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,19 @@
|
||||
"use client";
|
||||
'use client';
|
||||
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import * as z from "zod";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage
|
||||
} from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { toast } from "sonner";
|
||||
import { documentNumberingService } from "@/lib/services/document-numbering.service";
|
||||
import { CancelNumberDto } from "@/types/dto/numbering.dto";
|
||||
import { useState } from "react";
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import * as z from 'zod';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { toast } from 'sonner';
|
||||
import { documentNumberingService } from '@/lib/services/document-numbering.service';
|
||||
import { CancelNumberDto } from '@/types/dto/numbering.dto';
|
||||
import { useState } from 'react';
|
||||
|
||||
const formSchema = z.object({
|
||||
documentNumber: z.string().min(3, "Document Number is required"),
|
||||
reason: z.string().min(5, "Reason must be at least 5 characters"),
|
||||
documentNumber: z.string().min(3, 'Document Number is required'),
|
||||
reason: z.string().min(5, 'Reason must be at least 5 characters'),
|
||||
});
|
||||
|
||||
type CancelNumberFormData = z.infer<typeof formSchema>;
|
||||
@@ -31,8 +24,8 @@ export function CancelNumberForm() {
|
||||
const form = useForm<CancelNumberFormData>({
|
||||
resolver: zodResolver(formSchema) as any, // eslint-disable-line @typescript-eslint/no-explicit-any -- zod 4 + @hookform/resolvers compat
|
||||
defaultValues: {
|
||||
documentNumber: "",
|
||||
reason: "",
|
||||
documentNumber: '',
|
||||
reason: '',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -41,10 +34,10 @@ export function CancelNumberForm() {
|
||||
try {
|
||||
const dto: CancelNumberDto = values;
|
||||
await documentNumberingService.cancelNumber(dto);
|
||||
toast.success("Number cancelled successfully.");
|
||||
toast.success('Number cancelled successfully.');
|
||||
form.reset();
|
||||
} catch (error) {
|
||||
toast.error("Failed to cancel number. It may not exist or is already cancelled.");
|
||||
} catch (_error) {
|
||||
toast.error('Failed to cancel number. It may not exist or is already cancelled.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -54,30 +47,40 @@ export function CancelNumberForm() {
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4 border p-4 rounded-md">
|
||||
<h3 className="text-lg font-medium">Cancel Number</h3>
|
||||
<p className="text-sm text-gray-500">Permanently cancel a number (e.g. if generated by mistake). It cannot be reused.</p>
|
||||
<p className="text-sm text-gray-500">
|
||||
Permanently cancel a number (e.g. if generated by mistake). It cannot be reused.
|
||||
</p>
|
||||
|
||||
<FormField control={form.control} name="documentNumber" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Document Number</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="e.g. LCB3-COR-GGL-2025-0001" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="documentNumber"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Document Number</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="e.g. LCB3-COR-GGL-2025-0001" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField control={form.control} name="reason" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Reason</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Reason for cancellation..." {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="reason"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Reason</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Reason for cancellation..." {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button type="submit" variant="destructive" disabled={loading}>
|
||||
{loading ? "Cancelling..." : "Cancel Number"}
|
||||
{loading ? 'Cancelling...' : 'Cancel Number'}
|
||||
</Button>
|
||||
</form>
|
||||
</Form>
|
||||
|
||||
@@ -1,32 +1,24 @@
|
||||
"use client";
|
||||
'use client';
|
||||
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import * as z from "zod";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
FormDescription
|
||||
} from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { toast } from "sonner";
|
||||
import { documentNumberingService } from "@/lib/services/document-numbering.service";
|
||||
import { ManualOverrideDto } from "@/types/dto/numbering.dto";
|
||||
import { useState } from "react";
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import * as z from 'zod';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, FormDescription } from '@/components/ui/form';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { toast } from 'sonner';
|
||||
import { documentNumberingService } from '@/lib/services/document-numbering.service';
|
||||
import { ManualOverrideDto } from '@/types/dto/numbering.dto';
|
||||
import { useState } from 'react';
|
||||
|
||||
const formSchema = z.object({
|
||||
projectId: z.coerce.number().min(1, "Project is required"),
|
||||
originatorOrganizationId: z.coerce.number().min(1, "Originator is required"),
|
||||
recipientOrganizationId: z.coerce.number().min(1, "Recipient is required"),
|
||||
correspondenceTypeId: z.coerce.number().min(1, "Type is required"),
|
||||
newLastNumber: z.coerce.number().min(1, "New number is required"),
|
||||
reason: z.string().min(5, "Reason must be at least 5 characters"),
|
||||
resetScope: z.string().optional()
|
||||
projectId: z.coerce.number().min(1, 'Project is required'),
|
||||
originatorOrganizationId: z.coerce.number().min(1, 'Originator is required'),
|
||||
recipientOrganizationId: z.coerce.number().min(1, 'Recipient is required'),
|
||||
correspondenceTypeId: z.coerce.number().min(1, 'Type is required'),
|
||||
newLastNumber: z.coerce.number().min(1, 'New number is required'),
|
||||
reason: z.string().min(5, 'Reason must be at least 5 characters'),
|
||||
resetScope: z.string().optional(),
|
||||
});
|
||||
|
||||
export function ManualOverrideForm({ projectId = 1 }: { projectId?: number | string }) {
|
||||
@@ -40,8 +32,8 @@ export function ManualOverrideForm({ projectId = 1 }: { projectId?: number | str
|
||||
recipientOrganizationId: 0,
|
||||
correspondenceTypeId: 0,
|
||||
newLastNumber: 0,
|
||||
reason: "",
|
||||
resetScope: "YEAR_2025" // Example, should be dynamic or selected
|
||||
reason: '',
|
||||
resetScope: 'YEAR_2025', // Example, should be dynamic or selected
|
||||
},
|
||||
});
|
||||
|
||||
@@ -50,13 +42,13 @@ export function ManualOverrideForm({ projectId = 1 }: { projectId?: number | str
|
||||
try {
|
||||
const dto: ManualOverrideDto = {
|
||||
...values,
|
||||
resetScope: values.resetScope || "YEAR_" + new Date().getFullYear()
|
||||
resetScope: values.resetScope || 'YEAR_' + new Date().getFullYear(),
|
||||
};
|
||||
await documentNumberingService.manualOverride(dto);
|
||||
toast.success("Manual override applied successfully.");
|
||||
toast.success('Manual override applied successfully.');
|
||||
form.reset();
|
||||
} catch (error) {
|
||||
toast.error("Failed to apply override.");
|
||||
} catch (_error) {
|
||||
toast.error('Failed to apply override.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -66,65 +58,97 @@ export function ManualOverrideForm({ projectId = 1 }: { projectId?: number | str
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4 border p-4 rounded-md mt-4">
|
||||
<h3 className="text-lg font-medium">Manual Override Sequence</h3>
|
||||
<p className="text-sm text-gray-500">Careful: This updates the LAST generated number. Next number will receive +1.</p>
|
||||
<p className="text-sm text-gray-500">
|
||||
Careful: This updates the LAST generated number. Next number will receive +1.
|
||||
</p>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
{/* Allow simple text input for IDs for now, ideally Selects from Master Data */}
|
||||
<FormField control={form.control} name="projectId" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Project ID</FormLabel>
|
||||
<FormControl><Input type="number" {...field} /></FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField control={form.control} name="correspondenceTypeId" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Type ID</FormLabel>
|
||||
<FormControl><Input type="number" {...field} /></FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField control={form.control} name="originatorOrganizationId" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Originator Org ID</FormLabel>
|
||||
<FormControl><Input type="number" {...field} /></FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField control={form.control} name="recipientOrganizationId" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Recipient Org ID</FormLabel>
|
||||
<FormControl><Input type="number" {...field} /></FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
{/* Allow simple text input for IDs for now, ideally Selects from Master Data */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="projectId"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Project ID</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="number" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="correspondenceTypeId"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Type ID</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="number" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="originatorOrganizationId"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Originator Org ID</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="number" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="recipientOrganizationId"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Recipient Org ID</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="number" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<FormField control={form.control} name="newLastNumber" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Set Last Number To</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="number" {...field} />
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
If you set 99, the next auto-generated number will be 100.
|
||||
</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="newLastNumber"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Set Last Number To</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="number" {...field} />
|
||||
</FormControl>
|
||||
<FormDescription>If you set 99, the next auto-generated number will be 100.</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField control={form.control} name="reason" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Reason</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Why are you overriding?" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="reason"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Reason</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Why are you overriding?" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button type="submit" disabled={loading}>
|
||||
{loading ? "Applying..." : "Apply Override"}
|
||||
{loading ? 'Applying...' : 'Apply Override'}
|
||||
</Button>
|
||||
</form>
|
||||
</Form>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
"use client";
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card";
|
||||
import { Progress } from "@/components/ui/progress";
|
||||
import { documentNumberingService } from "@/lib/services/document-numbering.service";
|
||||
import { NumberingMetrics } from "@/types/dto/numbering.dto";
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Card, CardContent, CardHeader, CardTitle, _CardDescription } from '@/components/ui/card';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { documentNumberingService } from '@/lib/services/document-numbering.service';
|
||||
import { NumberingMetrics } from '@/types/dto/numbering.dto';
|
||||
|
||||
export function MetricsDashboard() {
|
||||
const [metrics, setMetrics] = useState<Partial<NumberingMetrics>>({});
|
||||
@@ -15,7 +15,7 @@ export function MetricsDashboard() {
|
||||
try {
|
||||
const data = await documentNumberingService.getMetrics();
|
||||
setMetrics(data);
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
// Failed to fetch metrics - handled by loading state
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -48,12 +48,12 @@ export function MetricsDashboard() {
|
||||
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">Sequence Utilization</CardTitle>
|
||||
<CardTitle className="text-sm font-medium">Sequence Utilization</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{utilization}%</div>
|
||||
<Progress value={utilization} className="mt-2" />
|
||||
<p className="text-xs text-muted-foreground mt-1">Average capacity used</p>
|
||||
<div className="text-2xl font-bold">{utilization}%</div>
|
||||
<Progress value={utilization} className="mt-2" />
|
||||
<p className="text-xs text-muted-foreground mt-1">Average capacity used</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -68,13 +68,13 @@ export function MetricsDashboard() {
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">Recent Errors</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{metrics.errors?.length || 0}</div>
|
||||
<p className="text-xs text-muted-foreground">In the last 24 hours</p>
|
||||
</CardContent>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">Recent Errors</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{metrics.errors?.length || 0}</div>
|
||||
<p className="text-xs text-muted-foreground">In the last 24 hours</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -18,7 +18,7 @@ export function SequenceViewer() {
|
||||
try {
|
||||
const response = await numberingApi.getSequences();
|
||||
// Handle wrapped response { data: [...] } or direct array
|
||||
const data = Array.isArray(response) ? response : (response as { data?: NumberSequence[] })?.data ?? [];
|
||||
const data = Array.isArray(response) ? response : ((response as { data?: NumberSequence[] })?.data ?? []);
|
||||
setSequences(data);
|
||||
} catch {
|
||||
// Failed to fetch sequences - show empty state
|
||||
@@ -43,12 +43,7 @@ export function SequenceViewer() {
|
||||
<Card className="p-6">
|
||||
<div className="flex justify-between items-center mb-4">
|
||||
<h3 className="text-lg font-semibold">Number Counters</h3>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={fetchSequences}
|
||||
disabled={loading}
|
||||
>
|
||||
<Button variant="outline" size="sm" onClick={fetchSequences} disabled={loading}>
|
||||
<RefreshCw className={`mr-2 h-4 w-4 ${loading ? 'animate-spin' : ''}`} />
|
||||
Refresh
|
||||
</Button>
|
||||
@@ -64,9 +59,7 @@ export function SequenceViewer() {
|
||||
|
||||
<div className="space-y-2">
|
||||
{filteredSequences.length === 0 && (
|
||||
<div className="text-center text-muted-foreground py-4">
|
||||
No sequences found
|
||||
</div>
|
||||
<div className="text-center text-muted-foreground py-4">No sequences found</div>
|
||||
)}
|
||||
{filteredSequences.map((seq, index) => (
|
||||
<div
|
||||
@@ -78,15 +71,11 @@ export function SequenceViewer() {
|
||||
<span className="font-medium">Year {seq.year}</span>
|
||||
<Badge variant="outline">Project: {seq.projectId}</Badge>
|
||||
<Badge>Type: {seq.typeId}</Badge>
|
||||
{seq.disciplineId > 0 && (
|
||||
<Badge variant="secondary">Disc: {seq.disciplineId}</Badge>
|
||||
)}
|
||||
{seq.disciplineId > 0 && <Badge variant="secondary">Disc: {seq.disciplineId}</Badge>}
|
||||
</div>
|
||||
<div className="text-sm text-muted-foreground">
|
||||
<span className="text-foreground font-medium">
|
||||
Counter: {seq.lastNumber}
|
||||
</span>{' '}
|
||||
| Originator: {seq.originatorId} | Recipient:{' '}
|
||||
<span className="text-foreground font-medium">Counter: {seq.lastNumber}</span> | Originator:{' '}
|
||||
{seq.originatorId} | Recipient:{' '}
|
||||
{seq.recipientOrganizationId === -1 ? 'All' : seq.recipientOrganizationId}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,21 +5,11 @@ import { Card } from '@/components/ui/card';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { NumberingTemplate } from '@/lib/api/numbering';
|
||||
import {
|
||||
HoverCard,
|
||||
HoverCardContent,
|
||||
HoverCardTrigger,
|
||||
} from '@/components/ui/hover-card';
|
||||
import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/components/ui/hover-card';
|
||||
|
||||
// Aligned with Backend replacement logic
|
||||
const VARIABLES = [
|
||||
@@ -36,13 +26,13 @@ const VARIABLES = [
|
||||
];
|
||||
|
||||
export interface TemplateEditorProps {
|
||||
template?: NumberingTemplate;
|
||||
projectId: number | string;
|
||||
projectName: string;
|
||||
correspondenceTypes: unknown[];
|
||||
disciplines: unknown[];
|
||||
onSave: (data: Partial<NumberingTemplate>) => void;
|
||||
onCancel: () => void;
|
||||
template?: NumberingTemplate;
|
||||
projectId: number | string;
|
||||
projectName: string;
|
||||
correspondenceTypes: unknown[];
|
||||
disciplines: unknown[];
|
||||
onSave: (data: Partial<NumberingTemplate>) => void;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
export function TemplateEditor({
|
||||
@@ -52,7 +42,7 @@ export function TemplateEditor({
|
||||
correspondenceTypes,
|
||||
disciplines,
|
||||
onSave,
|
||||
onCancel
|
||||
onCancel,
|
||||
}: TemplateEditorProps) {
|
||||
const [format, setFormat] = useState(template?.formatTemplate || '');
|
||||
const [typeId, setTypeId] = useState<string>(template?.correspondenceTypeId?.toString() || '');
|
||||
@@ -65,18 +55,20 @@ export function TemplateEditor({
|
||||
// Generate preview
|
||||
let previewText = format || '';
|
||||
VARIABLES.forEach((v) => {
|
||||
// Simple mock replacement for preview
|
||||
let replacement = v.example;
|
||||
if (v.key === '{YEAR:BE}') replacement = (new Date().getFullYear() + 543).toString();
|
||||
if (v.key === '{YEAR:CE}') replacement = new Date().getFullYear().toString();
|
||||
// Simple mock replacement for preview
|
||||
let replacement = v.example;
|
||||
if (v.key === '{YEAR:BE}') replacement = (new Date().getFullYear() + 543).toString();
|
||||
if (v.key === '{YEAR:CE}') replacement = new Date().getFullYear().toString();
|
||||
|
||||
// Dynamic context based on selection (optional visual enhancement)
|
||||
if (v.key === '{TYPE}' && typeId) {
|
||||
const t = (correspondenceTypes as { id: number; typeCode: string; typeName: string }[]).find((ct) => ct.id?.toString() === typeId);
|
||||
if (t) replacement = t.typeCode;
|
||||
}
|
||||
// Dynamic context based on selection (optional visual enhancement)
|
||||
if (v.key === '{TYPE}' && typeId) {
|
||||
const t = (correspondenceTypes as { id: number; typeCode: string; typeName: string }[]).find(
|
||||
(ct) => ct.id?.toString() === typeId
|
||||
);
|
||||
if (t) replacement = t.typeCode;
|
||||
}
|
||||
|
||||
previewText = previewText.replace(new RegExp(v.key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), replacement);
|
||||
previewText = previewText.replace(new RegExp(v.key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), replacement);
|
||||
});
|
||||
setPreview(previewText);
|
||||
}, [format, typeId, correspondenceTypes]);
|
||||
@@ -86,14 +78,14 @@ export function TemplateEditor({
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
onSave({
|
||||
...template,
|
||||
projectId: projectId,
|
||||
correspondenceTypeId: typeId && typeId !== '__default__' ? Number(typeId) : null,
|
||||
disciplineId: Number(disciplineId),
|
||||
formatTemplate: format,
|
||||
resetSequenceYearly: reset,
|
||||
});
|
||||
onSave({
|
||||
...template,
|
||||
projectId: projectId,
|
||||
correspondenceTypeId: typeId && typeId !== '__default__' ? Number(typeId) : null,
|
||||
disciplineId: Number(disciplineId),
|
||||
formatTemplate: format,
|
||||
resetSequenceYearly: reset,
|
||||
});
|
||||
};
|
||||
|
||||
const isValid = format.length > 0; // typeId is optional (null = default for all types)
|
||||
@@ -102,121 +94,125 @@ export function TemplateEditor({
|
||||
<Card className="p-6 space-y-6">
|
||||
<div className="flex justify-between items-start">
|
||||
<div>
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<h3 className="text-lg font-semibold">{template ? 'Edit Template' : 'New Template'}</h3>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">Define how document numbers are generated for this project.</p>
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<h3 className="text-lg font-semibold">{template ? 'Edit Template' : 'New Template'}</h3>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">Define how document numbers are generated for this project.</p>
|
||||
</div>
|
||||
<div className="flex flex-col items-end gap-2">
|
||||
<Badge variant="outline" className="text-base px-3 py-1 bg-slate-50">
|
||||
Project: {projectName}
|
||||
</Badge>
|
||||
<Badge variant="outline" className="text-base px-3 py-1 bg-slate-50">
|
||||
Project: {projectName}
|
||||
</Badge>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
{/* Configuration Column */}
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label>Document Type (Optional)</Label>
|
||||
<Select value={typeId} onValueChange={setTypeId}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Default (All Types)" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="__default__">Default (All Types)</SelectItem>
|
||||
{correspondenceTypes.map((type: unknown) => {
|
||||
const typedType = type as { id: number; typeCode: string; typeName: string };
|
||||
return (
|
||||
<SelectItem key={typedType.id} value={typedType.id.toString()}>
|
||||
{typedType.typeCode} - {typedType.typeName}
|
||||
</SelectItem>
|
||||
);
|
||||
})}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Leave empty to create a default template for this project.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label>Discipline (Optional)</Label>
|
||||
<Select value={disciplineId} onValueChange={setDisciplineId}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="All Disciplines" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="0">All Disciplines</SelectItem>
|
||||
{disciplines.map((d: any) => (
|
||||
<SelectItem key={d.id} value={d.id.toString()}>
|
||||
{d.disciplineCode} - {d.codeNameEn || d.codeNameTh}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Reset Rule</Label>
|
||||
<div className="flex items-center h-10">
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<Checkbox checked={reset} onCheckedChange={(c) => setReset(!!c)} />
|
||||
<span className="text-sm">Reset Annually</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* Configuration Column */}
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label>Document Type (Optional)</Label>
|
||||
<Select value={typeId} onValueChange={setTypeId}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Default (All Types)" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="__default__">Default (All Types)</SelectItem>
|
||||
{correspondenceTypes.map((type: unknown) => {
|
||||
const typedType = type as { id: number; typeCode: string; typeName: string };
|
||||
return (
|
||||
<SelectItem key={typedType.id} value={typedType.id.toString()}>
|
||||
{typedType.typeCode} - {typedType.typeName}
|
||||
</SelectItem>
|
||||
);
|
||||
})}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Leave empty to create a default template for this project.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Format Column */}
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label>Template Format *</Label>
|
||||
<Input
|
||||
value={format}
|
||||
onChange={(e) => setFormat(e.target.value)}
|
||||
placeholder="{ORG}-{TYPE}-{SEQ:4}"
|
||||
className="font-mono text-base mb-2"
|
||||
/>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{VARIABLES.map((v) => (
|
||||
<HoverCard key={v.key}>
|
||||
<HoverCardTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => insertVariable(v.key)}
|
||||
type="button"
|
||||
className="font-mono text-xs bg-slate-50 hover:bg-slate-100"
|
||||
>
|
||||
{v.key}
|
||||
</Button>
|
||||
</HoverCardTrigger>
|
||||
<HoverCardContent className="w-60 p-3">
|
||||
<p className="font-semibold text-sm">{v.name}</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">Example: <span className="font-mono">{v.example}</span></p>
|
||||
</HoverCardContent>
|
||||
</HoverCard>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-green-50/50 border border-green-200 rounded-lg p-4">
|
||||
<p className="text-xs uppercase tracking-wide text-green-700 font-semibold mb-2">Preview Output</p>
|
||||
<p className="text-2xl font-mono font-bold text-green-800 tracking-tight">
|
||||
{preview || '...'}
|
||||
</p>
|
||||
<p className="text-xs text-green-600 mt-2">
|
||||
* This is an approximation. Actual numbers depend on runtime context.
|
||||
</p>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label>Discipline (Optional)</Label>
|
||||
<Select value={disciplineId} onValueChange={setDisciplineId}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="All Disciplines" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="0">All Disciplines</SelectItem>
|
||||
{disciplines.map((d: unknown) => (
|
||||
<SelectItem key={d.id} value={d.id.toString()}>
|
||||
{d.disciplineCode} - {d.codeNameEn || d.codeNameTh}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Reset Rule</Label>
|
||||
<div className="flex items-center h-10">
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<Checkbox checked={reset} onCheckedChange={(c) => setReset(!!c)} />
|
||||
<span className="text-sm">Reset Annually</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Format Column */}
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label>Template Format *</Label>
|
||||
<Input
|
||||
value={format}
|
||||
onChange={(e) => setFormat(e.target.value)}
|
||||
placeholder="{ORG}-{TYPE}-{SEQ:4}"
|
||||
className="font-mono text-base mb-2"
|
||||
/>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{VARIABLES.map((v) => (
|
||||
<HoverCard key={v.key}>
|
||||
<HoverCardTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => insertVariable(v.key)}
|
||||
type="button"
|
||||
className="font-mono text-xs bg-slate-50 hover:bg-slate-100"
|
||||
>
|
||||
{v.key}
|
||||
</Button>
|
||||
</HoverCardTrigger>
|
||||
<HoverCardContent className="w-60 p-3">
|
||||
<p className="font-semibold text-sm">{v.name}</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Example: <span className="font-mono">{v.example}</span>
|
||||
</p>
|
||||
</HoverCardContent>
|
||||
</HoverCard>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-green-50/50 border border-green-200 rounded-lg p-4">
|
||||
<p className="text-xs uppercase tracking-wide text-green-700 font-semibold mb-2">Preview Output</p>
|
||||
<p className="text-2xl font-mono font-bold text-green-800 tracking-tight">{preview || '...'}</p>
|
||||
<p className="text-xs text-green-600 mt-2">
|
||||
* This is an approximation. Actual numbers depend on runtime context.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2 pt-4 border-t">
|
||||
<Button variant="outline" onClick={onCancel}>Cancel</Button>
|
||||
<Button onClick={handleSave} disabled={!isValid}>Save Template</Button>
|
||||
<Button variant="outline" onClick={onCancel}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={handleSave} disabled={!isValid}>
|
||||
Save Template
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -1,25 +1,14 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { NumberingTemplate, numberingApi } from '@/lib/api/numbering';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { useOrganizations, useCorrespondenceTypes, useDisciplines, useContracts } from '@/hooks/use-master-data';
|
||||
import { Organization } from '@/types/organization';
|
||||
|
||||
@@ -35,19 +24,18 @@ interface Discipline {
|
||||
disciplineCode: string;
|
||||
}
|
||||
|
||||
|
||||
interface TemplateTesterProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
template: NumberingTemplate | null;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
template: NumberingTemplate | null;
|
||||
}
|
||||
|
||||
export function TemplateTester({ open, onOpenChange, template }: TemplateTesterProps) {
|
||||
const [testData, setTestData] = useState({
|
||||
originatorId: "",
|
||||
recipientId: "",
|
||||
correspondenceTypeId: "",
|
||||
disciplineId: "",
|
||||
originatorId: '',
|
||||
recipientId: '',
|
||||
correspondenceTypeId: '',
|
||||
disciplineId: '',
|
||||
year: new Date().getFullYear(),
|
||||
});
|
||||
const [testResult, setTestResult] = useState<{ number: string; isDefault?: boolean } | null>(null);
|
||||
@@ -69,28 +57,28 @@ export function TemplateTester({ open, onOpenChange, template }: TemplateTesterP
|
||||
setLoading(true);
|
||||
setTestResult(null);
|
||||
try {
|
||||
const payload = {
|
||||
projectId: projectId,
|
||||
originatorOrganizationId: testData.originatorId || "0",
|
||||
recipientOrganizationId: testData.recipientId || "0",
|
||||
correspondenceTypeId: parseInt(testData.correspondenceTypeId || "0"),
|
||||
disciplineId: parseInt(testData.disciplineId || "0"),
|
||||
year: testData.year
|
||||
};
|
||||
console.log("TemplateTester: Sending payload:", payload);
|
||||
const result = await numberingApi.previewNumber(payload);
|
||||
console.log("TemplateTester: Received result:", result);
|
||||
|
||||
setTestResult({
|
||||
number: result.previewNumber,
|
||||
isDefault: result.isDefault
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error("Test Preview Error:", error);
|
||||
const errMsg = error?.response?.data?.message || error?.message || "Unknown error";
|
||||
setTestResult({ number: `Error: ${errMsg}`, isDefault: false });
|
||||
const payload = {
|
||||
projectId: projectId,
|
||||
originatorOrganizationId: testData.originatorId || '0',
|
||||
recipientOrganizationId: testData.recipientId || '0',
|
||||
correspondenceTypeId: Number(testData.correspondenceTypeId || '0'),
|
||||
disciplineId: Number(testData.disciplineId || '0'),
|
||||
year: testData.year,
|
||||
};
|
||||
// console.log("TemplateTester: Sending payload:", payload); /* TODO: Remove before prod */
|
||||
const result = await numberingApi.previewNumber(payload);
|
||||
// console.log("TemplateTester: Received result:", result); /* TODO: Remove before prod */
|
||||
|
||||
setTestResult({
|
||||
number: result.previewNumber,
|
||||
isDefault: result.isDefault,
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
// console.error("Test Preview Error:", error); /* TODO: Remove before prod */
|
||||
const errMsg = error?.response?.data?.message || error?.message || 'Unknown error';
|
||||
setTestResult({ number: `Error: ${errMsg}`, isDefault: false });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -102,132 +90,139 @@ export function TemplateTester({ open, onOpenChange, template }: TemplateTesterP
|
||||
</DialogHeader>
|
||||
|
||||
<div className="text-sm text-muted-foreground mb-2">
|
||||
Template: <span className="font-mono font-bold text-foreground">{template?.formatTemplate}</span>
|
||||
Template: <span className="font-mono font-bold text-foreground">{template?.formatTemplate}</span>
|
||||
</div>
|
||||
|
||||
<Card className="p-6 mt-6 bg-muted/50 rounded-lg">
|
||||
<h3 className="text-lg font-semibold mb-4">Template Tester</h3>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div className="md:col-span-2">
|
||||
<h4 className="text-sm font-medium mb-2">Test Parameters</h4>
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
{/* Originator */}
|
||||
<div className="space-y-2">
|
||||
<label className="text-xs font-medium">Originator (ORG)</label>
|
||||
<Select
|
||||
value={testData.originatorId}
|
||||
onValueChange={(val) => setTestData({...testData, originatorId: val})}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Originator" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{(organizations as Organization[])?.map((org) => (
|
||||
<SelectItem key={org.uuid} value={org.uuid}>
|
||||
{org.organizationCode} - {org.organizationName}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<h3 className="text-lg font-semibold mb-4">Template Tester</h3>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div className="md:col-span-2">
|
||||
<h4 className="text-sm font-medium mb-2">Test Parameters</h4>
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
{/* Originator */}
|
||||
<div className="space-y-2">
|
||||
<label className="text-xs font-medium">Originator (ORG)</label>
|
||||
<Select
|
||||
value={testData.originatorId}
|
||||
onValueChange={(val) => setTestData({ ...testData, originatorId: val })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Originator" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{(organizations as Organization[])?.map((org) => (
|
||||
<SelectItem key={org.uuid} value={org.uuid}>
|
||||
{org.organizationCode} - {org.organizationName}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* Recipient */}
|
||||
<div className="space-y-2">
|
||||
<label className="text-xs font-medium">Recipient (REC)</label>
|
||||
<Select
|
||||
value={testData.recipientId}
|
||||
onValueChange={(val) => setTestData({...testData, recipientId: val})}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Recipient" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{(organizations as Organization[])?.map((org) => (
|
||||
<SelectItem key={org.uuid} value={org.uuid}>
|
||||
{org.organizationCode} - {org.organizationName}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{/* Recipient */}
|
||||
<div className="space-y-2">
|
||||
<label className="text-xs font-medium">Recipient (REC)</label>
|
||||
<Select
|
||||
value={testData.recipientId}
|
||||
onValueChange={(val) => setTestData({ ...testData, recipientId: val })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Recipient" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{(organizations as Organization[])?.map((org) => (
|
||||
<SelectItem key={org.uuid} value={org.uuid}>
|
||||
{org.organizationCode} - {org.organizationName}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* Document Type */}
|
||||
<div className="space-y-2">
|
||||
<label className="text-xs font-medium">Document Type (TYPE)</label>
|
||||
<Select
|
||||
value={testData.correspondenceTypeId}
|
||||
onValueChange={(val) => setTestData({...testData, correspondenceTypeId: val})}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Type" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="0">Default (All Types)</SelectItem>
|
||||
{(correspondenceTypes as CorrespondenceType[])?.map((type) => (
|
||||
<SelectItem key={type.id} value={type.id.toString()}>
|
||||
{type.typeCode} - {type.typeName}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{/* Document Type */}
|
||||
<div className="space-y-2">
|
||||
<label className="text-xs font-medium">Document Type (TYPE)</label>
|
||||
<Select
|
||||
value={testData.correspondenceTypeId}
|
||||
onValueChange={(val) => setTestData({ ...testData, correspondenceTypeId: val })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Type" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="0">Default (All Types)</SelectItem>
|
||||
{(correspondenceTypes as CorrespondenceType[])?.map((type) => (
|
||||
<SelectItem key={type.id} value={type.id.toString()}>
|
||||
{type.typeCode} - {type.typeName}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* Discipline */}
|
||||
<div className="space-y-2">
|
||||
<label className="text-xs font-medium">Discipline (DIS)</label>
|
||||
<Select
|
||||
value={testData.disciplineId}
|
||||
onValueChange={(val) => setTestData({...testData, disciplineId: val})}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Discipline" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="0">None</SelectItem>
|
||||
{(disciplines as Discipline[])?.map((disc) => (
|
||||
<SelectItem key={disc.id} value={disc.id.toString()}>
|
||||
{disc.disciplineCode}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground mt-4">
|
||||
Format Preview: {template?.formatTemplate}
|
||||
</p>
|
||||
</div>
|
||||
{/* Discipline */}
|
||||
<div className="space-y-2">
|
||||
<label className="text-xs font-medium">Discipline (DIS)</label>
|
||||
<Select
|
||||
value={testData.disciplineId}
|
||||
onValueChange={(val) => setTestData({ ...testData, disciplineId: val })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select Discipline" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="0">None</SelectItem>
|
||||
{(disciplines as Discipline[])?.map((disc) => (
|
||||
<SelectItem key={disc.id} value={disc.id.toString()}>
|
||||
{disc.disciplineCode}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground mt-4">Format Preview: {template?.formatTemplate}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Button onClick={handleGenerate} className="w-full mt-4" disabled={loading || !template}>
|
||||
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||
Generate Test Number
|
||||
</Button>
|
||||
|
||||
{testResult && (
|
||||
<Card className={`p-4 mt-4 border text-center ${(testResult.number || '').startsWith('Error:') ? 'bg-red-50 border-red-200 text-red-700' : 'bg-green-50 dark:bg-green-950/30 border-green-200 dark:border-green-900'}`}>
|
||||
<div className="flex justify-between items-center mb-1">
|
||||
<p className="text-sm text-muted-foreground">{(testResult.number || '').startsWith('Error:') ? 'Generation Failed:' : 'Generated Number:'}</p>
|
||||
{testResult.isDefault && !(testResult.number || '').startsWith('Error:') && (
|
||||
<Badge variant="secondary" className="text-[10px] h-4 px-1">Default Template</Badge>
|
||||
)}
|
||||
{!testResult.isDefault && !(testResult.number || '').startsWith('Error:') && (
|
||||
<Badge variant="outline" className="text-[10px] h-4 px-1 border-green-300 text-green-700 bg-green-50">Specific Template</Badge>
|
||||
)}
|
||||
</div>
|
||||
<div className={`text-2xl font-mono font-bold ${(testResult.number || '').startsWith('Error:') ? 'text-red-700' : 'text-green-700 dark:text-green-400'}`}>
|
||||
{testResult.number || (
|
||||
<div className="text-xs font-mono text-left bg-slate-100 p-2 overflow-auto max-h-48 border rounded text-foreground">
|
||||
Empty Result. Raw: {JSON.stringify(testResult, null, 2)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
)}
|
||||
<Button onClick={handleGenerate} className="w-full mt-4" disabled={loading || !template}>
|
||||
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||
Generate Test Number
|
||||
</Button>
|
||||
|
||||
{testResult && (
|
||||
<Card
|
||||
className={`p-4 mt-4 border text-center ${(testResult.number || '').startsWith('Error:') ? 'bg-red-50 border-red-200 text-red-700' : 'bg-green-50 dark:bg-green-950/30 border-green-200 dark:border-green-900'}`}
|
||||
>
|
||||
<div className="flex justify-between items-center mb-1">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{(testResult.number || '').startsWith('Error:') ? 'Generation Failed:' : 'Generated Number:'}
|
||||
</p>
|
||||
{testResult.isDefault && !(testResult.number || '').startsWith('Error:') && (
|
||||
<Badge variant="secondary" className="text-[10px] h-4 px-1">
|
||||
Default Template
|
||||
</Badge>
|
||||
)}
|
||||
{!testResult.isDefault && !(testResult.number || '').startsWith('Error:') && (
|
||||
<Badge variant="outline" className="text-[10px] h-4 px-1 border-green-300 text-green-700 bg-green-50">
|
||||
Specific Template
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className={`text-2xl font-mono font-bold ${(testResult.number || '').startsWith('Error:') ? 'text-red-700' : 'text-green-700 dark:text-green-400'}`}
|
||||
>
|
||||
{testResult.number || (
|
||||
<div className="text-xs font-mono text-left bg-slate-100 p-2 overflow-auto max-h-48 border rounded text-foreground">
|
||||
Empty Result. Raw: {JSON.stringify(testResult, null, 2)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
@@ -1,30 +1,22 @@
|
||||
"use client";
|
||||
'use client';
|
||||
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import * as z from "zod";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
FormDescription
|
||||
} from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { toast } from "sonner";
|
||||
import { documentNumberingService } from "@/lib/services/document-numbering.service";
|
||||
import { VoidReplaceDto } from "@/types/dto/numbering.dto";
|
||||
import { useState } from "react";
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import * as z from 'zod';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, FormDescription } from '@/components/ui/form';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { toast } from 'sonner';
|
||||
import { documentNumberingService } from '@/lib/services/document-numbering.service';
|
||||
import { VoidReplaceDto } from '@/types/dto/numbering.dto';
|
||||
import { useState } from 'react';
|
||||
|
||||
const formSchema = z.object({
|
||||
documentNumber: z.string().min(3, "Document Number is required"),
|
||||
reason: z.string().min(5, "Reason must be at least 5 characters"),
|
||||
documentNumber: z.string().min(3, 'Document Number is required'),
|
||||
reason: z.string().min(5, 'Reason must be at least 5 characters'),
|
||||
replace: z.boolean(),
|
||||
projectId: z.number()
|
||||
projectId: z.number(),
|
||||
});
|
||||
|
||||
type VoidReplaceFormData = z.infer<typeof formSchema>;
|
||||
@@ -35,10 +27,10 @@ export function VoidReplaceForm({ projectId = 1 }: { projectId?: number | string
|
||||
const form = useForm<VoidReplaceFormData>({
|
||||
resolver: zodResolver(formSchema) as any, // eslint-disable-line @typescript-eslint/no-explicit-any -- zod 4 + @hookform/resolvers compat
|
||||
defaultValues: {
|
||||
documentNumber: "",
|
||||
reason: "",
|
||||
documentNumber: '',
|
||||
reason: '',
|
||||
replace: false,
|
||||
projectId: Number(projectId)
|
||||
projectId: Number(projectId),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -49,10 +41,10 @@ export function VoidReplaceForm({ projectId = 1 }: { projectId?: number | string
|
||||
...values,
|
||||
};
|
||||
await documentNumberingService.voidAndReplace(dto);
|
||||
toast.success("Number voided successfully. " + (values.replace ? "Replacement generated." : ""));
|
||||
toast.success('Number voided successfully. ' + (values.replace ? 'Replacement generated.' : ''));
|
||||
form.reset();
|
||||
} catch (error) {
|
||||
toast.error("Failed to void number. Check if it exists.");
|
||||
} catch (_error) {
|
||||
toast.error('Failed to void number. Check if it exists.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -64,47 +56,52 @@ export function VoidReplaceForm({ projectId = 1 }: { projectId?: number | string
|
||||
<h3 className="text-lg font-medium">Void & Replace Number</h3>
|
||||
<p className="text-sm text-gray-500">Void a generated number. Useful for skipped numbers or errors.</p>
|
||||
|
||||
<FormField control={form.control} name="documentNumber" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Document Number</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="e.g. LCB3-COR-GGL-2025-0001" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="documentNumber"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Document Number</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="e.g. LCB3-COR-GGL-2025-0001" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField control={form.control} name="reason" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Reason</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Reason for voiding..." {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="reason"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Reason</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Reason for voiding..." {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField control={form.control} name="replace" render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4">
|
||||
<FormControl>
|
||||
<Checkbox
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
<div className="space-y-1 leading-none">
|
||||
<FormLabel>
|
||||
Generate Replacement?
|
||||
</FormLabel>
|
||||
<FormDescription>
|
||||
If checked, a new number will be reserved immediately.
|
||||
</FormDescription>
|
||||
</div>
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="replace"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4">
|
||||
<FormControl>
|
||||
<Checkbox checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl>
|
||||
<div className="space-y-1 leading-none">
|
||||
<FormLabel>Generate Replacement?</FormLabel>
|
||||
<FormDescription>If checked, a new number will be reserved immediately.</FormDescription>
|
||||
</div>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button type="submit" variant="destructive" disabled={loading}>
|
||||
{loading ? "Processing..." : "Void Number"}
|
||||
{loading ? 'Processing...' : 'Void Number'}
|
||||
</Button>
|
||||
</form>
|
||||
</Form>
|
||||
|
||||
Reference in New Issue
Block a user