690327:1426 Fixing Refactor ADR-019 Naming convention uuid #17
This commit is contained in:
@@ -21,20 +21,10 @@ import {
|
|||||||
ShopSubCategory,
|
ShopSubCategory,
|
||||||
ContractDrawingCategory,
|
ContractDrawingCategory,
|
||||||
} from '@/types/master-data';
|
} from '@/types/master-data';
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect, useMemo } from 'react';
|
||||||
import { Loader2 } from 'lucide-react';
|
import { Loader2 } from 'lucide-react';
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
|
|
||||||
// Helper to extract array data from various API response formats
|
|
||||||
const extractArrayData = <T,>(value: unknown): T[] => {
|
|
||||||
if (Array.isArray(value)) return value as T[];
|
|
||||||
if (value && typeof value === 'object' && 'data' in value) {
|
|
||||||
const data = (value as { data?: unknown }).data;
|
|
||||||
if (Array.isArray(data)) return data as T[];
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
};
|
|
||||||
|
|
||||||
// Base Schema
|
// Base Schema
|
||||||
const baseSchema = z.object({
|
const baseSchema = z.object({
|
||||||
drawingType: z.enum(['CONTRACT', 'SHOP', 'AS_BUILT']),
|
drawingType: z.enum(['CONTRACT', 'SHOP', 'AS_BUILT']),
|
||||||
@@ -90,7 +80,10 @@ export function DrawingUploadForm() {
|
|||||||
|
|
||||||
// Project list - ADR-019: useProjects returns array directly now
|
// Project list - ADR-019: useProjects returns array directly now
|
||||||
const { data: projectsData, isLoading: isLoadingProjects } = useProjects();
|
const { data: projectsData, isLoading: isLoadingProjects } = useProjects();
|
||||||
const projects = (projectsData ?? []) as { id?: number; publicId?: string; projectName: string; projectCode: string }[];
|
const projects = useMemo(
|
||||||
|
() => (projectsData ?? []) as { id?: number; publicId?: string; projectName: string; projectCode: string }[],
|
||||||
|
[projectsData]
|
||||||
|
);
|
||||||
|
|
||||||
// Selected project for category fetching
|
// Selected project for category fetching
|
||||||
const [selectedProjectId, setSelectedProjectId] = useState<number | string | undefined>(undefined);
|
const [selectedProjectId, setSelectedProjectId] = useState<number | string | undefined>(undefined);
|
||||||
@@ -192,7 +185,7 @@ export function DrawingUploadForm() {
|
|||||||
)}
|
)}
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{projects.map((project) => {
|
{projects.map((project: { publicId?: string; id?: number; projectCode: string; projectName: string }) => {
|
||||||
const projectValue = String(project.publicId ?? project.id ?? '');
|
const projectValue = String(project.publicId ?? project.id ?? '');
|
||||||
return (
|
return (
|
||||||
<SelectItem key={projectValue} value={projectValue}>
|
<SelectItem key={projectValue} value={projectValue}>
|
||||||
|
|||||||
@@ -96,9 +96,8 @@ export function useProjects(isActive: boolean = true) {
|
|||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['projects', { isActive }],
|
queryKey: ['projects', { isActive }],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const response = await projectService.getAll({ isActive });
|
// ADR-019: projectService.getAll() returns Project[] directly
|
||||||
// ADR-019: Handle paginated response { data: Project[], meta: {...} }
|
return await projectService.getAll({ isActive });
|
||||||
return extractArrayData(response);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user