260322:1648 Correct Coresspondence / Doing RFA / Correct CI
This commit is contained in:
@@ -4,7 +4,7 @@ import { useState, useEffect } from 'react';
|
||||
import { useParams } from 'next/navigation';
|
||||
import { TemplateEditor } from '@/components/numbering/template-editor';
|
||||
import { SequenceViewer } from '@/components/numbering/sequence-viewer';
|
||||
import { numberingApi } from '@/lib/api/numbering';
|
||||
import { numberingApi, SaveTemplateDto } from '@/lib/api/numbering';
|
||||
import { NumberingTemplate } from '@/lib/api/numbering';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
@@ -29,18 +29,18 @@ export default function EditTemplatePage() {
|
||||
const { data: disciplines = [] } = useDisciplines(contractId);
|
||||
|
||||
const selectedProjectName =
|
||||
projects.find((p: { id?: number; uuid?: string; projectCode: string; projectName: string }) => p.id === projectId)?.projectName ||
|
||||
'LCBP3';
|
||||
projects.find((p: { id?: number; uuid?: string; projectCode: string; projectName: string }) => p.id === projectId)
|
||||
?.projectName || 'LCBP3';
|
||||
|
||||
useEffect(() => {
|
||||
const fetchTemplate = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await numberingApi.getTemplate(parseInt(id));
|
||||
const data = await numberingApi.getTemplate(Number(id));
|
||||
if (data) {
|
||||
setTemplate(data);
|
||||
}
|
||||
} catch (error) {
|
||||
} catch {
|
||||
toast.error('Failed to load template');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -51,16 +51,28 @@ export default function EditTemplatePage() {
|
||||
}, [id]);
|
||||
|
||||
const handleSave = async (data: Partial<NumberingTemplate>) => {
|
||||
if (!template) return;
|
||||
try {
|
||||
await numberingApi.saveTemplate({ ...data, id: parseInt(id) });
|
||||
// Map to SaveTemplateDto ensuring all required fields are present
|
||||
const payload: SaveTemplateDto = {
|
||||
id: Number(id),
|
||||
projectId: data.projectId ?? template.projectId,
|
||||
correspondenceTypeId: data.correspondenceTypeId ?? template.correspondenceTypeId,
|
||||
formatTemplate: data.formatTemplate ?? template.formatTemplate,
|
||||
disciplineId: data.disciplineId ?? template.disciplineId,
|
||||
description: data.description ?? template.description,
|
||||
resetSequenceYearly: data.resetSequenceYearly ?? template.resetSequenceYearly,
|
||||
isActive: data.isActive ?? template.isActive,
|
||||
};
|
||||
await numberingApi.saveTemplate(payload);
|
||||
router.push('/admin/doc-control/numbering');
|
||||
} catch (error) {
|
||||
} catch {
|
||||
toast.error('Failed to update template');
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
router.push("/admin/numbering");
|
||||
router.push('/admin/doc-control/numbering');
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
"use client";
|
||||
'use client';
|
||||
|
||||
import { TemplateEditor } from "@/components/numbering/template-editor";
|
||||
import { numberingApi, NumberingTemplate } from "@/lib/api/numbering";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useCorrespondenceTypes, useContracts, useDisciplines } from "@/hooks/use-master-data";
|
||||
import { useProjects } from "@/hooks/use-projects";
|
||||
import { TemplateEditor } from '@/components/numbering/template-editor';
|
||||
import { numberingApi, NumberingTemplate } from '@/lib/api/numbering';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useCorrespondenceTypes, useContracts, useDisciplines } from '@/hooks/use-master-data';
|
||||
import { useProjects } from '@/hooks/use-projects';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
export default function NewTemplatePage() {
|
||||
@@ -24,8 +24,8 @@ export default function NewTemplatePage() {
|
||||
const handleSave = async (data: Partial<NumberingTemplate>) => {
|
||||
try {
|
||||
await numberingApi.saveTemplate(data);
|
||||
router.push("/admin/numbering");
|
||||
} catch (error) {
|
||||
router.push('/admin/numbering');
|
||||
} catch (_error) {
|
||||
toast.error('Failed to create template');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -58,7 +58,7 @@ export default function NumberingPage() {
|
||||
const contractId = firstContract?.uuid ?? firstContract?.id;
|
||||
const { data: disciplines = [] } = useDisciplines(contractId);
|
||||
|
||||
const { data: templateResponse, isLoading: isLoadingTemplates } = useTemplates();
|
||||
const { data: templateResponse, isLoading: _isLoadingTemplates } = useTemplates();
|
||||
const saveTemplateMutation = useSaveTemplate();
|
||||
|
||||
// Extract templates array from response
|
||||
@@ -144,7 +144,12 @@ export default function NumberingPage() {
|
||||
<div className="lg:col-span-2 space-y-4">
|
||||
<div className="grid gap-4">
|
||||
{templates
|
||||
.filter((t) => !t.projectId || String(t.project?.id ?? t.project?.uuid) === selectedProjectId || t.project?.uuid === selectedProjectId)
|
||||
.filter(
|
||||
(t) =>
|
||||
!t.projectId ||
|
||||
String(t.project?.id ?? t.project?.uuid) === selectedProjectId ||
|
||||
t.project?.uuid === selectedProjectId
|
||||
)
|
||||
.map((template) => (
|
||||
<Card key={template.id} className="p-6 hover:shadow-md transition-shadow">
|
||||
<div className="flex justify-between items-start">
|
||||
|
||||
Reference in New Issue
Block a user