Fix API connectivity and import filament data from PDF

- Update all environment files to use new PostgreSQL API endpoint
- Fix CORS configuration in API server
- Import 35 filaments and 29 colors from PDF data
- Fix TypeScript type error in dashboard
- Add back emoji icons for dark mode toggle
- Remove debugging code and test buttons
- Clean up error handling
This commit is contained in:
DaX
2025-06-20 15:40:40 +02:00
parent 62a4891112
commit 82c476430f
13 changed files with 737 additions and 29 deletions

View File

@@ -42,9 +42,19 @@ export default function Home() {
const filaments = await filamentService.getAll();
setFilaments(filaments);
} catch (err) {
} catch (err: any) {
console.error('API Error:', err);
setError(err instanceof Error ? err.message : 'Greška pri učitavanju filamenata');
// More descriptive error messages
if (err.code === 'ERR_NETWORK') {
setError('Network Error - Unable to connect to API');
} else if (err.response) {
setError(`Server error: ${err.response.status} - ${err.response.statusText}`);
} else if (err.request) {
setError('No response from server - check if API is running');
} else {
setError(err.message || 'Greška pri učitavanju filamenata');
}
} finally {
setLoading(false);
}
@@ -91,7 +101,7 @@ export default function Home() {
className="p-2 bg-white/50 dark:bg-gray-700/50 backdrop-blur text-gray-800 dark:text-gray-200 rounded-full hover:bg-white/80 dark:hover:bg-gray-600/80 transition-all duration-200 hover:scale-110 shadow-md ml-2"
title={darkMode ? 'Svetla tema' : 'Tamna tema'}
>
{darkMode ? 'Svetla' : 'Tamna'}
{darkMode ? '☀️' : '🌙'}
</button>
)}
</div>

View File

@@ -2,8 +2,8 @@
import { useState, useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { colorService } from '../../../src/services/api';
import '../../../src/styles/select.css';
import { colorService } from '@/src/services/api';
import '@/src/styles/select.css';
interface Color {
id: string;
@@ -170,7 +170,7 @@ export default function ColorsManagement() {
className="px-4 py-2 bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-gray-200 rounded hover:bg-gray-300 dark:hover:bg-gray-600 transition-colors"
title={darkMode ? 'Svetla tema' : 'Tamna tema'}
>
{darkMode ? 'Svetla' : 'Tamna'}
{darkMode ? '☀️' : '🌙'}
</button>
)}
<button

View File

@@ -2,9 +2,9 @@
import { useState, useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { filamentService, colorService } from '../../../src/services/api';
import { Filament } from '../../../src/types/filament';
import '../../../src/styles/select.css';
import { filamentService, colorService } from '@/src/services/api';
import { Filament } from '@/src/types/filament';
import '@/src/styles/select.css';
interface FilamentWithId extends Filament {
id: string;
@@ -188,7 +188,7 @@ export default function AdminDashboard() {
className="px-4 py-2 bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-gray-200 rounded hover:bg-gray-300 dark:hover:bg-gray-600 transition-colors"
title={darkMode ? 'Svetla tema' : 'Tamna tema'}
>
{darkMode ? 'Svetla' : 'Tamna'}
{darkMode ? '☀️' : '🌙'}
</button>
)}
<button
@@ -502,7 +502,7 @@ function FilamentForm({
name="bojaHex"
value={formData.bojaHex || '#000000'}
onChange={handleChange}
disabled={formData.boja && formData.boja !== 'custom' && availableColors.some(c => c.name === formData.boja)}
disabled={!!(formData.boja && formData.boja !== 'custom' && availableColors.some(c => c.name === formData.boja))}
className="w-full h-10 px-1 py-1 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed"
/>
{formData.bojaHex && (

View File

@@ -2,7 +2,7 @@
import { useState, useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { authService } from '../../src/services/api';
import { authService } from '@/src/services/api';
export default function AdminLogin() {
const router = useRouter();
@@ -30,7 +30,7 @@ export default function AdminLogin() {
// Redirect to admin dashboard
router.push('/upadaj/dashboard');
} catch (err) {
} catch (err: any) {
setError('Neispravno korisničko ime ili lozinka');
console.error('Login error:', err);
} finally {