|
@@ -1,6 +1,6 @@
|
|
|
'use client';
|
|
'use client';
|
|
|
|
|
|
|
|
-import { useState, useEffect } from 'react';
|
|
|
|
|
|
|
+import { useState, useEffect, useCallback } from 'react';
|
|
|
import { Plus, FileText, Calendar, Trash2, Edit } from 'lucide-react';
|
|
import { Plus, FileText, Calendar, Trash2, Edit } from 'lucide-react';
|
|
|
import { Button } from '@/components/ui/button';
|
|
import { Button } from '@/components/ui/button';
|
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|
@@ -23,6 +23,17 @@ interface Import {
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+interface RawImportData {
|
|
|
|
|
+ id: number;
|
|
|
|
|
+ name: string;
|
|
|
|
|
+ importDate: Date | string;
|
|
|
|
|
+ layoutId: number;
|
|
|
|
|
+ layout: {
|
|
|
|
|
+ id: number;
|
|
|
|
|
+ name: string;
|
|
|
|
|
+ };
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export default function ImportsPage() {
|
|
export default function ImportsPage() {
|
|
|
const [imports, setImports] = useState<Import[]>([]);
|
|
const [imports, setImports] = useState<Import[]>([]);
|
|
|
const [loading, setLoading] = useState(true);
|
|
const [loading, setLoading] = useState(true);
|
|
@@ -32,16 +43,12 @@ export default function ImportsPage() {
|
|
|
const [selectedImport, setSelectedImport] = useState<Import | null>(null);
|
|
const [selectedImport, setSelectedImport] = useState<Import | null>(null);
|
|
|
const { toast } = useToast();
|
|
const { toast } = useToast();
|
|
|
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- loadImports();
|
|
|
|
|
- }, []);
|
|
|
|
|
-
|
|
|
|
|
- async function loadImports() {
|
|
|
|
|
|
|
+ const loadImports = useCallback(async () => {
|
|
|
try {
|
|
try {
|
|
|
const result = await getImports();
|
|
const result = await getImports();
|
|
|
if (result.success && result.data) {
|
|
if (result.success && result.data) {
|
|
|
// Transform the data to match our Import interface
|
|
// Transform the data to match our Import interface
|
|
|
- const transformedImports = result.data.map(item => ({
|
|
|
|
|
|
|
+ const transformedImports = result.data.map((item: RawImportData) => ({
|
|
|
id: item.id,
|
|
id: item.id,
|
|
|
name: item.name,
|
|
name: item.name,
|
|
|
importDate: item.importDate instanceof Date
|
|
importDate: item.importDate instanceof Date
|
|
@@ -71,7 +78,11 @@ export default function ImportsPage() {
|
|
|
} finally {
|
|
} finally {
|
|
|
setLoading(false);
|
|
setLoading(false);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ }, [toast]);
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ loadImports();
|
|
|
|
|
+ }, [loadImports]);
|
|
|
|
|
|
|
|
async function handleDeleteImport(id: number) {
|
|
async function handleDeleteImport(id: number) {
|
|
|
if (!confirm('Are you sure you want to delete this import?')) return;
|
|
if (!confirm('Are you sure you want to delete this import?')) return;
|