Compare commits
3 Commits
b7f5417e23
...
stampaci
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1f3a65dfd | ||
|
|
59304a88f4 | ||
|
|
2fefc805ef |
185
CLAUDE.md
185
CLAUDE.md
@@ -1,21 +1,22 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance for AI-assisted development in this repository.
|
||||
This file provides guidance when working with code in this repository.
|
||||
|
||||
## Project Overview
|
||||
|
||||
Filamenteka is a 3D printing filament inventory management system for tracking Bambu Lab filaments. It consists of:
|
||||
- **Frontend**: Next.js app with React, TypeScript, and Tailwind CSS (static export)
|
||||
- **Backend**: Node.js API server with PostgreSQL database
|
||||
- **Infrastructure**: AWS (Amplify for frontend, EC2 for API, RDS for database)
|
||||
Filamenteka is a 3D printing filament inventory management system for tracking Bambu Lab filaments with:
|
||||
- **Frontend**: Next.js 15 app with React 19, TypeScript 5.2.2, and Tailwind CSS (static export)
|
||||
- **Backend**: Node.js Express API server with PostgreSQL database
|
||||
- **Infrastructure**: AWS (Amplify for frontend, EC2 for API, RDS for database), managed via Terraform
|
||||
|
||||
## Critical Rules
|
||||
|
||||
- NEVER mention ANY author in commits. No author tags or attribution
|
||||
- NEVER mention AI/assistant names anywhere
|
||||
- NEVER mention AI/assistant names anywhere
|
||||
- Keep commit messages clean and professional with NO attribution
|
||||
- Build for AMD64 Linux when deploying (development is on ARM macOS)
|
||||
- Always run security checks before commits
|
||||
- NEVER use mock data - all tests must use real APIs/data
|
||||
|
||||
## Common Commands
|
||||
|
||||
@@ -24,57 +25,75 @@ Filamenteka is a 3D printing filament inventory management system for tracking B
|
||||
npm run dev # Start Next.js development server (port 3000)
|
||||
npm run build # Build static export to /out directory
|
||||
npm run lint # Run ESLint
|
||||
npm test # Run Jest tests
|
||||
npm test # Run Jest tests (includes no-mock-data validation)
|
||||
|
||||
# Security & Quality
|
||||
npm run security:check # Check for credential leaks
|
||||
npm run test:build # Test if build succeeds
|
||||
./scripts/pre-commit.sh # Full pre-commit validation (security, build, tests)
|
||||
|
||||
# Database Migrations
|
||||
npm run migrate # Run pending migrations
|
||||
npm run migrate:clear # Clear migration history
|
||||
|
||||
# Pre-commit Hook
|
||||
./scripts/pre-commit.sh # Runs security, build, and test checks
|
||||
# API Server Development
|
||||
cd api && npm start # Start API server locally (port 3001)
|
||||
cd api && npm run dev # Start API server with nodemon
|
||||
|
||||
# Deployment
|
||||
./scripts/deploy-api.sh # Deploy API to EC2 (builds AMD64 Docker image)
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
### Frontend Structure (Next.js App Router)
|
||||
- `/app` - Next.js 13+ app directory structure
|
||||
- `/page.tsx` - Public filament inventory table
|
||||
- `/upadaj` - Admin panel (password protected)
|
||||
- `/page.tsx` - Admin login
|
||||
- `/dashboard/page.tsx` - Filament CRUD operations
|
||||
- `/colors/page.tsx` - Color management
|
||||
```
|
||||
/app
|
||||
├── page.tsx # Public filament inventory table
|
||||
├── layout.tsx # Root layout with providers
|
||||
└── upadaj/ # Admin panel (JWT protected)
|
||||
├── page.tsx # Admin login
|
||||
├── dashboard/page.tsx # Filament CRUD operations
|
||||
├── colors/page.tsx # Color management
|
||||
└── requests/page.tsx # Color request management
|
||||
```
|
||||
|
||||
### API Structure
|
||||
- `/api` - Node.js Express server (runs on EC2)
|
||||
- `/server.js` - Main server file
|
||||
- `/routes` - API endpoints for filaments, colors, auth
|
||||
- Database: PostgreSQL on AWS RDS
|
||||
```
|
||||
/api
|
||||
├── server.js # Express server (port 3001)
|
||||
├── routes/
|
||||
│ ├── filaments.js # Filament CRUD + bulk operations
|
||||
│ ├── colors.js # Color management
|
||||
│ ├── colorRequests.js # Color request system
|
||||
│ └── auth.js # JWT authentication
|
||||
└── middleware/
|
||||
└── auth.js # JWT verification middleware
|
||||
```
|
||||
|
||||
### Key Components
|
||||
- `FilamentTableV2` - Main inventory display with sorting/filtering
|
||||
- `SaleManager` - Bulk sale management interface
|
||||
- `FilamentTableV2` - Main inventory display with sorting/filtering/searching
|
||||
- `SaleManager` - Bulk sale management with countdown timers
|
||||
- `ColorCell` - Smart color rendering with gradient support
|
||||
- `EnhancedFilters` - Advanced filtering system
|
||||
- `EnhancedFilters` - Multi-criteria filtering system
|
||||
- `ColorRequestModal` - Public color request form
|
||||
|
||||
### Data Models
|
||||
|
||||
#### Filament Schema (PostgreSQL)
|
||||
```sql
|
||||
filaments: {
|
||||
id: UUID,
|
||||
id: UUID PRIMARY KEY,
|
||||
tip: VARCHAR(50), # Material type (PLA, PETG, ABS)
|
||||
finish: VARCHAR(50), # Finish type (Basic, Matte, Silk)
|
||||
boja: VARCHAR(100), # Color name
|
||||
boja: VARCHAR(100), # Color name (links to colors.name)
|
||||
boja_hex: VARCHAR(7), # Color hex code
|
||||
refill: INTEGER, # Refill spool count
|
||||
spulna: INTEGER, # Regular spool count
|
||||
kolicina: INTEGER, # Total quantity (refill + spulna)
|
||||
cena: VARCHAR(50), # Price
|
||||
cena: VARCHAR(50), # Price string
|
||||
sale_active: BOOLEAN, # Sale status
|
||||
sale_percentage: INTEGER,# Sale discount
|
||||
sale_percentage: INTEGER,# Sale discount percentage
|
||||
sale_end_date: TIMESTAMP # Sale expiry
|
||||
}
|
||||
```
|
||||
@@ -82,11 +101,23 @@ filaments: {
|
||||
#### Color Schema
|
||||
```sql
|
||||
colors: {
|
||||
id: UUID,
|
||||
name: VARCHAR(100), # Color name (must match filament.boja)
|
||||
hex: VARCHAR(7), # Hex color code
|
||||
cena_refill: INTEGER, # Refill price (default: 3499)
|
||||
cena_spulna: INTEGER # Regular price (default: 3999)
|
||||
id: UUID PRIMARY KEY,
|
||||
name: VARCHAR(100) UNIQUE, # Color name (must match filament.boja)
|
||||
hex: VARCHAR(7), # Hex color code
|
||||
cena_refill: INTEGER, # Refill price (default: 3499)
|
||||
cena_spulna: INTEGER # Regular price (default: 3999)
|
||||
}
|
||||
```
|
||||
|
||||
#### Color Requests Schema
|
||||
```sql
|
||||
color_requests: {
|
||||
id: UUID PRIMARY KEY,
|
||||
color_name: VARCHAR(100),
|
||||
email: VARCHAR(255),
|
||||
message: TEXT,
|
||||
status: VARCHAR(50), # pending/approved/rejected
|
||||
created_at: TIMESTAMP
|
||||
}
|
||||
```
|
||||
|
||||
@@ -95,39 +126,49 @@ colors: {
|
||||
### Frontend (AWS Amplify)
|
||||
- Automatic deployment on push to main branch
|
||||
- Build output: Static files in `/out` directory
|
||||
- Build command: `npm run build`
|
||||
- Config: `amplify.yml`, `next.config.js` (output: 'export')
|
||||
|
||||
### API Server (EC2)
|
||||
- Manual deployment via `scripts/deploy-api.sh`
|
||||
- Server: `3.71.161.51`
|
||||
- Manual deployment via `./scripts/deploy-api.sh`
|
||||
- Docker containerized (Node.js 18 Alpine)
|
||||
- Server: `3.71.161.51`
|
||||
- Domain: `api.filamenteka.rs`
|
||||
- **Important**: Build for AMD64 architecture when deploying from ARM Mac
|
||||
|
||||
### Database (RDS PostgreSQL)
|
||||
- Host: `filamenteka.ci7fsdlbzmag.eu-central-1.rds.amazonaws.com`
|
||||
- Migrations in `/database/migrations/`
|
||||
- Migrations in `/database/migrations/` (numbered sequence)
|
||||
- Schema in `/database/schema.sql`
|
||||
- Connection via `DATABASE_URL` environment variable
|
||||
|
||||
## Important Patterns
|
||||
|
||||
### API Communication
|
||||
- All API calls use axios interceptors for auth (`src/services/api.ts`)
|
||||
- Auth token stored in localStorage
|
||||
- All API calls use axios with interceptors (`src/services/api.ts`)
|
||||
- Auth token stored in localStorage as 'adminToken'
|
||||
- Automatic redirect on 401/403 in admin routes
|
||||
- Base URL from `NEXT_PUBLIC_API_URL` env variable
|
||||
|
||||
### Color Management
|
||||
- Colors defined in `src/data/bambuLabColors.ts` and `bambuLabColorsComplete.ts`
|
||||
- Automatic row coloring based on filament color
|
||||
- Special handling for gradient filaments
|
||||
- Primary source: `src/data/bambuLabColors.ts` (hex mappings)
|
||||
- Extended data: `src/data/bambuLabColorsComplete.ts`
|
||||
- Refill-only colors: `src/data/refillOnlyColors.ts`
|
||||
- Automatic row coloring based on filament.boja_hex
|
||||
- Special gradient handling for multi-color filaments
|
||||
|
||||
### State Management
|
||||
- React hooks for local state
|
||||
- No global state management library
|
||||
- Data fetching in components with useEffect
|
||||
- React hooks for local state (no global state library)
|
||||
- Data fetching with useEffect in components
|
||||
- Form state managed with controlled components
|
||||
- Admin auth state in localStorage
|
||||
|
||||
### Testing
|
||||
- Jest + React Testing Library
|
||||
- Tests in `__tests__/` directory
|
||||
- Coverage goal: >80%
|
||||
### Testing Strategy
|
||||
- Jest + React Testing Library for component tests
|
||||
- Special `no-mock-data.test.ts` enforces real API usage
|
||||
- Integration tests connect to real database
|
||||
- Coverage reports in `/coverage/`
|
||||
- Test files in `__tests__/` directories
|
||||
|
||||
## Environment Variables
|
||||
|
||||
@@ -135,34 +176,56 @@ colors: {
|
||||
# Frontend (.env.local)
|
||||
NEXT_PUBLIC_API_URL=https://api.filamenteka.rs/api
|
||||
|
||||
# API Server
|
||||
DATABASE_URL=postgresql://...
|
||||
JWT_SECRET=...
|
||||
# API Server (.env)
|
||||
DATABASE_URL=postgresql://username:password@host/database
|
||||
JWT_SECRET=your-secret-key
|
||||
NODE_ENV=production
|
||||
PORT=3001
|
||||
```
|
||||
|
||||
## Security Considerations
|
||||
|
||||
- Admin routes protected by JWT authentication
|
||||
- Password hashing with bcrypt
|
||||
- JWT authentication for admin routes (24h expiry)
|
||||
- Password hashing with bcryptjs (10 rounds)
|
||||
- SQL injection prevention via parameterized queries
|
||||
- Credential leak detection in pre-commit hooks
|
||||
- CORS configured for production domains only
|
||||
- Author mention detection prevents attribution in commits
|
||||
|
||||
## Database Operations
|
||||
|
||||
When modifying the database:
|
||||
1. Create migration file in `/database/migrations/`
|
||||
2. Test locally first
|
||||
3. Run migration on production via scripts
|
||||
4. Update corresponding TypeScript types
|
||||
1. Create numbered migration file in `/database/migrations/`
|
||||
2. Test locally with `npm run migrate`
|
||||
3. Deploy to production via SSH or migration script
|
||||
4. Update TypeScript interfaces in `src/types/`
|
||||
5. Update relevant data files in `src/data/`
|
||||
|
||||
## Terraform Infrastructure
|
||||
|
||||
Infrastructure as Code in `/terraform/`:
|
||||
- VPC and networking setup
|
||||
- EC2 instance for API
|
||||
- RDS PostgreSQL database
|
||||
- Application Load Balancer
|
||||
- ECR for Docker images
|
||||
- Cloudflare DNS integration
|
||||
- VPC with public/private subnets
|
||||
- EC2 instance with Application Load Balancer
|
||||
- RDS PostgreSQL instance
|
||||
- ECR for Docker image registry
|
||||
- Cloudflare DNS integration
|
||||
- Environment separation (dev/prod)
|
||||
|
||||
## Special Considerations
|
||||
|
||||
### ARM to AMD64 Builds
|
||||
When deploying from ARM Mac to AMD64 Linux:
|
||||
- Docker builds must specify `--platform linux/amd64`
|
||||
- Deployment scripts handle architecture conversion
|
||||
- Test builds locally with `docker buildx`
|
||||
|
||||
### Color Data Synchronization
|
||||
- Colors must exist in both database and frontend data files
|
||||
- Use migration scripts to sync color data
|
||||
- Validate consistency with data consistency tests
|
||||
|
||||
### Sale Management
|
||||
- Bulk sale operations affect multiple filaments
|
||||
- Sale countdown timers update in real-time
|
||||
- Prices automatically calculated with discounts
|
||||
- Sale end dates trigger automatic deactivation
|
||||
114
app/page.tsx
114
app/page.tsx
@@ -3,7 +3,10 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { FilamentTableV2 } from '../src/components/FilamentTableV2';
|
||||
import { SaleCountdown } from '../src/components/SaleCountdown';
|
||||
import ColorRequestModal from '../src/components/ColorRequestModal';
|
||||
import TabbedNavigation from '../src/components/TabbedNavigation';
|
||||
import PrintersTable from '../src/components/PrintersTable';
|
||||
import GearTable from '../src/components/GearTable';
|
||||
import ColorRequestSection from '../src/components/ColorRequestSection';
|
||||
import { Filament } from '../src/types/filament';
|
||||
import { filamentService } from '../src/services/api';
|
||||
import { trackEvent } from '../src/components/MatomoAnalytics';
|
||||
@@ -15,7 +18,7 @@ export default function Home() {
|
||||
const [darkMode, setDarkMode] = useState(false);
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const [resetKey, setResetKey] = useState(0);
|
||||
const [showColorRequestModal, setShowColorRequestModal] = useState(false);
|
||||
const [activeTab, setActiveTab] = useState('filaments');
|
||||
// Removed V1/V2 toggle - now only using V2
|
||||
|
||||
// Initialize dark mode from localStorage after mounting
|
||||
@@ -175,40 +178,79 @@ export default function Home() {
|
||||
</svg>
|
||||
Pozovi +381 67 710 2845
|
||||
</a>
|
||||
|
||||
<button
|
||||
onClick={() => {
|
||||
setShowColorRequestModal(true);
|
||||
trackEvent('Navigation', 'Request Color', 'Homepage');
|
||||
}}
|
||||
className="inline-flex items-center gap-2 px-6 py-3 bg-gradient-to-r from-purple-500 to-purple-600 hover:from-purple-600 hover:to-purple-700 text-white font-semibold rounded-lg shadow-lg hover:shadow-xl transition-all duration-200 transform hover:scale-105"
|
||||
>
|
||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M7 21a4 4 0 01-4-4V5a2 2 0 012-2h4a2 2 0 012 2v12a4 4 0 01-4 4zm0 0h12a2 2 0 002-2v-4a2 2 0 00-2-2h-2.343M11 7.343l1.657-1.657a2 2 0 012.828 0l2.829 2.829a2 2 0 010 2.828l-8.486 8.485M7 17h.01" />
|
||||
</svg>
|
||||
Zatraži Novu Boju
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<SaleCountdown
|
||||
hasActiveSale={filaments.some(f => f.sale_active === true)}
|
||||
maxSalePercentage={Math.max(...filaments.filter(f => f.sale_active === true).map(f => f.sale_percentage || 0), 0)}
|
||||
saleEndDate={(() => {
|
||||
const activeSales = filaments.filter(f => f.sale_active === true && f.sale_end_date);
|
||||
if (activeSales.length === 0) return null;
|
||||
const latestSale = activeSales.reduce((latest, current) => {
|
||||
if (!latest.sale_end_date) return current;
|
||||
if (!current.sale_end_date) return latest;
|
||||
return new Date(current.sale_end_date) > new Date(latest.sale_end_date) ? current : latest;
|
||||
}).sale_end_date;
|
||||
return latestSale;
|
||||
})()}
|
||||
/>
|
||||
{/* Tabs Navigation */}
|
||||
<div className="mb-8">
|
||||
<TabbedNavigation
|
||||
tabs={[
|
||||
{
|
||||
id: 'filaments',
|
||||
label: 'Filamenti',
|
||||
icon: (
|
||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" />
|
||||
</svg>
|
||||
)
|
||||
},
|
||||
{
|
||||
id: 'printers',
|
||||
label: 'Štampači',
|
||||
icon: (
|
||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z" />
|
||||
</svg>
|
||||
)
|
||||
},
|
||||
{
|
||||
id: 'gear',
|
||||
label: 'Oprema',
|
||||
icon: (
|
||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
]}
|
||||
activeTab={activeTab}
|
||||
onTabChange={setActiveTab}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Tab Content */}
|
||||
{activeTab === 'filaments' && (
|
||||
<>
|
||||
<SaleCountdown
|
||||
hasActiveSale={filaments.some(f => f.sale_active === true)}
|
||||
maxSalePercentage={Math.max(...filaments.filter(f => f.sale_active === true).map(f => f.sale_percentage || 0), 0)}
|
||||
saleEndDate={(() => {
|
||||
const activeSales = filaments.filter(f => f.sale_active === true && f.sale_end_date);
|
||||
if (activeSales.length === 0) return null;
|
||||
const latestSale = activeSales.reduce((latest, current) => {
|
||||
if (!latest.sale_end_date) return current;
|
||||
if (!current.sale_end_date) return latest;
|
||||
return new Date(current.sale_end_date) > new Date(latest.sale_end_date) ? current : latest;
|
||||
}).sale_end_date;
|
||||
return latestSale;
|
||||
})()}
|
||||
/>
|
||||
|
||||
<FilamentTableV2
|
||||
key={resetKey}
|
||||
filaments={filaments}
|
||||
/>
|
||||
|
||||
{/* Color Request Section Below Table */}
|
||||
<div className="mt-16">
|
||||
<ColorRequestSection />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<FilamentTableV2
|
||||
key={resetKey}
|
||||
filaments={filaments}
|
||||
/>
|
||||
{activeTab === 'printers' && <PrintersTable />}
|
||||
|
||||
{activeTab === 'gear' && <GearTable />}
|
||||
</main>
|
||||
|
||||
<footer className="bg-gray-100 dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700 mt-16">
|
||||
@@ -230,12 +272,6 @@ export default function Home() {
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
{/* Color Request Modal */}
|
||||
<ColorRequestModal
|
||||
isOpen={showColorRequestModal}
|
||||
onClose={() => setShowColorRequestModal(false)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
67
src/components/ColorRequestSection.tsx
Normal file
67
src/components/ColorRequestSection.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import ColorRequestModal from './ColorRequestModal';
|
||||
import { trackEvent } from './MatomoAnalytics';
|
||||
|
||||
export default function ColorRequestSection() {
|
||||
const [showModal, setShowModal] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="max-w-2xl mx-auto">
|
||||
<div className="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-8">
|
||||
<div className="text-center">
|
||||
<div className="flex justify-center mb-6">
|
||||
<div className="p-4 bg-purple-100 dark:bg-purple-900/30 rounded-full">
|
||||
<svg className="w-16 h-16 text-purple-600 dark:text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M7 21a4 4 0 01-4-4V5a2 2 0 012-2h4a2 2 0 012 2v12a4 4 0 01-4 4zm0 0h12a2 2 0 002-2v-4a2 2 0 00-2-2h-2.343M11 7.343l1.657-1.657a2 2 0 012.828 0l2.829 2.829a2 2 0 010 2.828l-8.486 8.485M7 17h.01" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2 className="text-2xl font-bold text-gray-900 dark:text-gray-100 mb-4">
|
||||
Zatražite Novu Boju
|
||||
</h2>
|
||||
|
||||
<p className="text-gray-600 dark:text-gray-400 mb-8 max-w-md mx-auto">
|
||||
Ne možete pronaći boju koju tražite u našoj ponudi?
|
||||
Javite nam koju boju želite i mi ćemo je nabaviti za vas!
|
||||
</p>
|
||||
|
||||
<div className="space-y-4">
|
||||
<button
|
||||
onClick={() => {
|
||||
setShowModal(true);
|
||||
trackEvent('Navigation', 'Request Color', 'Color Request Tab');
|
||||
}}
|
||||
className="inline-flex items-center gap-3 px-8 py-4 bg-gradient-to-r from-purple-500 to-purple-600 hover:from-purple-600 hover:to-purple-700 text-white font-semibold rounded-lg shadow-lg hover:shadow-xl transition-all duration-200 transform hover:scale-105"
|
||||
>
|
||||
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" />
|
||||
</svg>
|
||||
Pošaljite Zahtev za Boju
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mt-12 grid grid-cols-1 sm:grid-cols-3 gap-6">
|
||||
<div className="text-center">
|
||||
<div className="text-3xl font-bold text-purple-600 dark:text-purple-400">1-3</div>
|
||||
<div className="text-sm text-gray-600 dark:text-gray-400 mt-1">Dana za odgovor</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-3xl font-bold text-purple-600 dark:text-purple-400">100+</div>
|
||||
<div className="text-sm text-gray-600 dark:text-gray-400 mt-1">Dostupnih boja</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-3xl font-bold text-purple-600 dark:text-purple-400">7-14</div>
|
||||
<div className="text-sm text-gray-600 dark:text-gray-400 mt-1">Dana za nabavku</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ColorRequestModal isOpen={showModal} onClose={() => setShowModal(false)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
256
src/components/GearRequestModal.tsx
Normal file
256
src/components/GearRequestModal.tsx
Normal file
@@ -0,0 +1,256 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { gearRequestService } from '@/src/services/api';
|
||||
|
||||
interface GearRequestModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export default function GearRequestModal({ isOpen, onClose }: GearRequestModalProps) {
|
||||
const [formData, setFormData] = useState({
|
||||
item_name: '',
|
||||
category: '',
|
||||
printer_model: '',
|
||||
quantity: '1',
|
||||
user_email: '',
|
||||
user_phone: '',
|
||||
message: ''
|
||||
});
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [message, setMessage] = useState<{ type: 'success' | 'error', text: string } | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) {
|
||||
setFormData({
|
||||
item_name: '',
|
||||
category: '',
|
||||
printer_model: '',
|
||||
quantity: '1',
|
||||
user_email: '',
|
||||
user_phone: '',
|
||||
message: ''
|
||||
});
|
||||
setMessage(null);
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setIsSubmitting(true);
|
||||
setMessage(null);
|
||||
|
||||
try {
|
||||
await gearRequestService.submit(formData);
|
||||
setMessage({
|
||||
type: 'success',
|
||||
text: 'Vaš zahtev za opremu je uspešno poslat!'
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
onClose();
|
||||
}, 2000);
|
||||
} catch (error) {
|
||||
setMessage({
|
||||
type: 'error',
|
||||
text: 'Greška pri slanju zahteva. Pokušajte ponovo.'
|
||||
});
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => {
|
||||
setFormData({
|
||||
...formData,
|
||||
[e.target.name]: e.target.value
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className="fixed inset-0 bg-black bg-opacity-50 z-40 transition-opacity"
|
||||
onClick={onClose}
|
||||
/>
|
||||
|
||||
<div className="fixed inset-0 z-50 overflow-y-auto">
|
||||
<div className="flex min-h-full items-center justify-center p-4">
|
||||
<div className="relative bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-md w-full p-6">
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="absolute top-4 right-4 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300"
|
||||
>
|
||||
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<h2 className="text-xl font-bold mb-4 text-gray-800 dark:text-gray-100">
|
||||
Zatraži Opremu ili Deo
|
||||
</h2>
|
||||
|
||||
<p className="text-sm text-gray-600 dark:text-gray-400 mb-4">
|
||||
Recite nam koji deo ili opremu tražite!
|
||||
</p>
|
||||
|
||||
{message && (
|
||||
<div className={`mb-4 p-3 rounded text-sm ${
|
||||
message.type === 'success'
|
||||
? 'bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400'
|
||||
: 'bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400'
|
||||
}`}>
|
||||
{message.text}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label htmlFor="item_name" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Naziv Proizvoda *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="item_name"
|
||||
name="item_name"
|
||||
required
|
||||
value={formData.item_name}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"
|
||||
placeholder="npr. Hardened Steel Nozzle"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label htmlFor="category" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Kategorija
|
||||
</label>
|
||||
<select
|
||||
id="category"
|
||||
name="category"
|
||||
value={formData.category}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"
|
||||
>
|
||||
<option value="">Izaberite</option>
|
||||
<option value="nozzle">Dizna</option>
|
||||
<option value="hotend">Hotend</option>
|
||||
<option value="extruder">Ekstruder</option>
|
||||
<option value="bed">Podloga</option>
|
||||
<option value="tool">Alat</option>
|
||||
<option value="spare_part">Rezervni Deo</option>
|
||||
<option value="accessory">Dodatak</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="quantity" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Količina
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
id="quantity"
|
||||
name="quantity"
|
||||
min="1"
|
||||
value={formData.quantity}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="printer_model" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Model Štampača
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="printer_model"
|
||||
name="printer_model"
|
||||
value={formData.printer_model}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"
|
||||
placeholder="npr. Bambu Lab X1C"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="message" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Dodatne Napomene
|
||||
</label>
|
||||
<textarea
|
||||
id="message"
|
||||
name="message"
|
||||
rows={3}
|
||||
value={formData.message}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"
|
||||
placeholder="Opišite šta vam je potrebno..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label htmlFor="user_email" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Email *
|
||||
</label>
|
||||
<input
|
||||
type="email"
|
||||
id="user_email"
|
||||
name="user_email"
|
||||
required
|
||||
value={formData.user_email}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"
|
||||
placeholder="vas@email.com"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="user_phone" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Telefon *
|
||||
</label>
|
||||
<input
|
||||
type="tel"
|
||||
id="user_phone"
|
||||
name="user_phone"
|
||||
required
|
||||
value={formData.user_phone}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"
|
||||
placeholder="06x xxx xxxx"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end space-x-3 pt-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="px-4 py-2 text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100"
|
||||
>
|
||||
Otkaži
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className={`px-6 py-2 rounded-md text-white font-medium ${
|
||||
isSubmitting
|
||||
? 'bg-gray-400 cursor-not-allowed'
|
||||
: 'bg-purple-600 hover:bg-purple-700'
|
||||
} transition-colors`}
|
||||
>
|
||||
{isSubmitting ? 'Slanje...' : 'Pošalji'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
270
src/components/GearTable.tsx
Normal file
270
src/components/GearTable.tsx
Normal file
@@ -0,0 +1,270 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { gearService } from '@/src/services/api';
|
||||
import GearRequestModal from './GearRequestModal';
|
||||
|
||||
interface GearItem {
|
||||
id: string;
|
||||
name: string;
|
||||
category: 'nozzle' | 'hotend' | 'extruder' | 'bed' | 'tool' | 'spare_part' | 'accessory';
|
||||
price: string;
|
||||
availability: 'available' | 'out_of_stock' | 'pre_order';
|
||||
description: string;
|
||||
compatible_with?: string[];
|
||||
image_url?: string;
|
||||
}
|
||||
|
||||
export default function GearTable() {
|
||||
const [gear, setGear] = useState<GearItem[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [isRequestModalOpen, setIsRequestModalOpen] = useState(false);
|
||||
const [selectedCategory, setSelectedCategory] = useState<string>('all');
|
||||
|
||||
useEffect(() => {
|
||||
fetchGear();
|
||||
}, []);
|
||||
|
||||
const fetchGear = async () => {
|
||||
try {
|
||||
const data = await gearService.getAll();
|
||||
setGear(data);
|
||||
} catch (error) {
|
||||
console.error('Error fetching gear:', error);
|
||||
// Use mock data for now until API is ready
|
||||
setGear([
|
||||
{
|
||||
id: '1',
|
||||
name: 'Hardened Steel Nozzle 0.4mm',
|
||||
category: 'nozzle',
|
||||
price: '29€',
|
||||
availability: 'available',
|
||||
description: 'Otporna na habanje, idealna za abrazivne materijale',
|
||||
compatible_with: ['X1C', 'P1S', 'A1']
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
name: 'PEI Textured Plate',
|
||||
category: 'bed',
|
||||
price: '39€',
|
||||
availability: 'available',
|
||||
description: 'Teksturisana PEI ploča za bolju adheziju',
|
||||
compatible_with: ['X1C', 'P1S']
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
name: 'AMS Hub',
|
||||
category: 'accessory',
|
||||
price: '149€',
|
||||
availability: 'available',
|
||||
description: 'Hub za povezivanje do 4 AMS jedinice',
|
||||
compatible_with: ['X1C', 'P1S']
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
name: 'Bambu Lab Tool Kit',
|
||||
category: 'tool',
|
||||
price: '49€',
|
||||
availability: 'available',
|
||||
description: 'Kompletan set alata za održavanje štampača'
|
||||
},
|
||||
{
|
||||
id: '5',
|
||||
name: 'Hotend Assembly',
|
||||
category: 'hotend',
|
||||
price: '89€',
|
||||
availability: 'pre_order',
|
||||
description: 'Kompletna hotend jedinica',
|
||||
compatible_with: ['X1C', 'P1S']
|
||||
},
|
||||
{
|
||||
id: '6',
|
||||
name: 'Carbon Filter',
|
||||
category: 'spare_part',
|
||||
price: '19€',
|
||||
availability: 'available',
|
||||
description: 'Aktivni ugljeni filter za X1C',
|
||||
compatible_with: ['X1C']
|
||||
},
|
||||
{
|
||||
id: '7',
|
||||
name: 'Extruder Gear Set',
|
||||
category: 'extruder',
|
||||
price: '25€',
|
||||
availability: 'available',
|
||||
description: 'Set zupčanika za ekstruder',
|
||||
compatible_with: ['X1C', 'P1S', 'A1']
|
||||
},
|
||||
{
|
||||
id: '8',
|
||||
name: 'LED Light Bar',
|
||||
category: 'accessory',
|
||||
price: '35€',
|
||||
availability: 'available',
|
||||
description: 'LED osvetljenje za komoru štampača',
|
||||
compatible_with: ['X1C', 'P1S']
|
||||
}
|
||||
]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const categories = [
|
||||
{ value: 'all', label: 'Sve' },
|
||||
{ value: 'nozzle', label: 'Dizne' },
|
||||
{ value: 'hotend', label: 'Hotend' },
|
||||
{ value: 'extruder', label: 'Ekstruder' },
|
||||
{ value: 'bed', label: 'Podloge' },
|
||||
{ value: 'tool', label: 'Alati' },
|
||||
{ value: 'spare_part', label: 'Rezervni Delovi' },
|
||||
{ value: 'accessory', label: 'Dodaci' }
|
||||
];
|
||||
|
||||
const filteredGear = selectedCategory === 'all'
|
||||
? gear
|
||||
: gear.filter(item => item.category === selectedCategory);
|
||||
|
||||
const getAvailabilityBadge = (availability: string) => {
|
||||
switch (availability) {
|
||||
case 'available':
|
||||
return (
|
||||
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400">
|
||||
Dostupno
|
||||
</span>
|
||||
);
|
||||
case 'out_of_stock':
|
||||
return (
|
||||
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400">
|
||||
Nema na stanju
|
||||
</span>
|
||||
);
|
||||
case 'pre_order':
|
||||
return (
|
||||
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400">
|
||||
Prednarudžba
|
||||
</span>
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const getCategoryBadge = (category: string) => {
|
||||
const categoryLabel = categories.find(c => c.value === category)?.label || category;
|
||||
return (
|
||||
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300">
|
||||
{categoryLabel}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex justify-center items-center py-12">
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-purple-600"></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-6 flex justify-between items-center">
|
||||
<h2 className="text-2xl font-bold text-gray-900 dark:text-gray-100">Oprema i Delovi</h2>
|
||||
<button
|
||||
onClick={() => setIsRequestModalOpen(true)}
|
||||
className="px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition-colors flex items-center space-x-2"
|
||||
>
|
||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" />
|
||||
</svg>
|
||||
<span>Zatraži Opremu</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mb-6">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{categories.map((category) => (
|
||||
<button
|
||||
key={category.value}
|
||||
onClick={() => setSelectedCategory(category.value)}
|
||||
className={`px-4 py-2 rounded-lg font-medium transition-colors ${
|
||||
selectedCategory === category.value
|
||||
? 'bg-purple-600 text-white'
|
||||
: 'bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-600'
|
||||
}`}
|
||||
>
|
||||
{category.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="overflow-x-auto">
|
||||
<table className="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
|
||||
<thead className="bg-gray-50 dark:bg-gray-800">
|
||||
<tr>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
|
||||
Proizvod
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
|
||||
Kategorija
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
|
||||
Kompatibilnost
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
|
||||
Cena
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
|
||||
Status
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="bg-white dark:bg-gray-900 divide-y divide-gray-200 dark:divide-gray-700">
|
||||
{filteredGear.map((item) => (
|
||||
<tr key={item.id} className="hover:bg-gray-50 dark:hover:bg-gray-800">
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<div>
|
||||
<div className="text-sm font-medium text-gray-900 dark:text-gray-100">
|
||||
{item.name}
|
||||
</div>
|
||||
<div className="text-sm text-gray-500 dark:text-gray-400">
|
||||
{item.description}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
{getCategoryBadge(item.category)}
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
{item.compatible_with ? (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{item.compatible_with.map((model) => (
|
||||
<span key={model} className="text-xs bg-blue-100 dark:bg-blue-900/30 text-blue-800 dark:text-blue-400 px-2 py-1 rounded">
|
||||
{model}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-sm text-gray-500 dark:text-gray-400">Univerzalno</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<div className="text-lg font-semibold text-purple-600 dark:text-purple-400">
|
||||
{item.price}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
{getAvailabilityBadge(item.availability)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<GearRequestModal isOpen={isRequestModalOpen} onClose={() => setIsRequestModalOpen(false)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
238
src/components/PrinterRequestModal.tsx
Normal file
238
src/components/PrinterRequestModal.tsx
Normal file
@@ -0,0 +1,238 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { printerRequestService } from '@/src/services/api';
|
||||
|
||||
interface PrinterRequestModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export default function PrinterRequestModal({ isOpen, onClose }: PrinterRequestModalProps) {
|
||||
const [formData, setFormData] = useState({
|
||||
printer_model: '',
|
||||
budget_range: '',
|
||||
intended_use: '',
|
||||
user_email: '',
|
||||
user_phone: '',
|
||||
message: ''
|
||||
});
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [message, setMessage] = useState<{ type: 'success' | 'error', text: string } | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) {
|
||||
setFormData({
|
||||
printer_model: '',
|
||||
budget_range: '',
|
||||
intended_use: '',
|
||||
user_email: '',
|
||||
user_phone: '',
|
||||
message: ''
|
||||
});
|
||||
setMessage(null);
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setIsSubmitting(true);
|
||||
setMessage(null);
|
||||
|
||||
try {
|
||||
await printerRequestService.submit(formData);
|
||||
setMessage({
|
||||
type: 'success',
|
||||
text: 'Vaš zahtev za štampač je uspešno poslat!'
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
onClose();
|
||||
}, 2000);
|
||||
} catch (error) {
|
||||
setMessage({
|
||||
type: 'error',
|
||||
text: 'Greška pri slanju zahteva. Pokušajte ponovo.'
|
||||
});
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => {
|
||||
setFormData({
|
||||
...formData,
|
||||
[e.target.name]: e.target.value
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className="fixed inset-0 bg-black bg-opacity-50 z-40 transition-opacity"
|
||||
onClick={onClose}
|
||||
/>
|
||||
|
||||
<div className="fixed inset-0 z-50 overflow-y-auto">
|
||||
<div className="flex min-h-full items-center justify-center p-4">
|
||||
<div className="relative bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-md w-full p-6">
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="absolute top-4 right-4 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300"
|
||||
>
|
||||
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<h2 className="text-xl font-bold mb-4 text-gray-800 dark:text-gray-100">
|
||||
Zatraži 3D Štampač
|
||||
</h2>
|
||||
|
||||
<p className="text-sm text-gray-600 dark:text-gray-400 mb-4">
|
||||
Recite nam koji štampač vas zanima ili koji vam odgovara!
|
||||
</p>
|
||||
|
||||
{message && (
|
||||
<div className={`mb-4 p-3 rounded text-sm ${
|
||||
message.type === 'success'
|
||||
? 'bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400'
|
||||
: 'bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400'
|
||||
}`}>
|
||||
{message.text}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label htmlFor="printer_model" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Model Štampača
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="printer_model"
|
||||
name="printer_model"
|
||||
value={formData.printer_model}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"
|
||||
placeholder="npr. Bambu Lab X1 Carbon"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="budget_range" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Budžet
|
||||
</label>
|
||||
<select
|
||||
id="budget_range"
|
||||
name="budget_range"
|
||||
value={formData.budget_range}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"
|
||||
>
|
||||
<option value="">Izaberite budžet</option>
|
||||
<option value="0-500">0 - 500€</option>
|
||||
<option value="500-1000">500 - 1000€</option>
|
||||
<option value="1000-2000">1000 - 2000€</option>
|
||||
<option value="2000+">2000€+</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="intended_use" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Namena Korišćenja
|
||||
</label>
|
||||
<select
|
||||
id="intended_use"
|
||||
name="intended_use"
|
||||
value={formData.intended_use}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"
|
||||
>
|
||||
<option value="">Izaberite namenu</option>
|
||||
<option value="hobby">Hobi</option>
|
||||
<option value="professional">Profesionalno</option>
|
||||
<option value="education">Edukacija</option>
|
||||
<option value="prototyping">Prototipovi</option>
|
||||
<option value="production">Proizvodnja</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="message" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Dodatne Napomene
|
||||
</label>
|
||||
<textarea
|
||||
id="message"
|
||||
name="message"
|
||||
rows={3}
|
||||
value={formData.message}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"
|
||||
placeholder="Opišite vaše potrebe..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label htmlFor="user_email" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Email *
|
||||
</label>
|
||||
<input
|
||||
type="email"
|
||||
id="user_email"
|
||||
name="user_email"
|
||||
required
|
||||
value={formData.user_email}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"
|
||||
placeholder="vas@email.com"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="user_phone" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
Telefon *
|
||||
</label>
|
||||
<input
|
||||
type="tel"
|
||||
id="user_phone"
|
||||
name="user_phone"
|
||||
required
|
||||
value={formData.user_phone}
|
||||
onChange={handleChange}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500"
|
||||
placeholder="06x xxx xxxx"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end space-x-3 pt-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="px-4 py-2 text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100"
|
||||
>
|
||||
Otkaži
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className={`px-6 py-2 rounded-md text-white font-medium ${
|
||||
isSubmitting
|
||||
? 'bg-gray-400 cursor-not-allowed'
|
||||
: 'bg-purple-600 hover:bg-purple-700'
|
||||
} transition-colors`}
|
||||
>
|
||||
{isSubmitting ? 'Slanje...' : 'Pošalji'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
161
src/components/PrintersTable.tsx
Normal file
161
src/components/PrintersTable.tsx
Normal file
@@ -0,0 +1,161 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { printersService } from '@/src/services/api';
|
||||
import PrinterRequestModal from './PrinterRequestModal';
|
||||
|
||||
interface Printer {
|
||||
id: string;
|
||||
name: string;
|
||||
model: string;
|
||||
price: string;
|
||||
availability: 'available' | 'out_of_stock' | 'pre_order';
|
||||
description: string;
|
||||
image_url?: string;
|
||||
features?: string[];
|
||||
}
|
||||
|
||||
export default function PrintersTable() {
|
||||
const [printers, setPrinters] = useState<Printer[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [isRequestModalOpen, setIsRequestModalOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
fetchPrinters();
|
||||
}, []);
|
||||
|
||||
const fetchPrinters = async () => {
|
||||
try {
|
||||
const data = await printersService.getAll();
|
||||
setPrinters(data);
|
||||
} catch (error) {
|
||||
console.error('Error fetching printers:', error);
|
||||
// Use mock data for now until API is ready
|
||||
setPrinters([
|
||||
{
|
||||
id: '1',
|
||||
name: 'Bambu Lab X1 Carbon',
|
||||
model: 'X1C',
|
||||
price: '1449€',
|
||||
availability: 'available',
|
||||
description: 'Professional 3D printer with automatic calibration',
|
||||
features: ['AMS compatible', 'LiDAR scanning', 'AI error detection']
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
name: 'Bambu Lab P1S',
|
||||
model: 'P1S',
|
||||
price: '849€',
|
||||
availability: 'available',
|
||||
description: 'Enclosed 3D printer for advanced materials',
|
||||
features: ['Enclosed chamber', 'Camera monitoring', 'Silent operation']
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
name: 'Bambu Lab A1 mini',
|
||||
model: 'A1 mini',
|
||||
price: '299€',
|
||||
availability: 'available',
|
||||
description: 'Compact desktop 3D printer',
|
||||
features: ['Auto-leveling', 'Compact size', 'Beginner friendly']
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
name: 'Bambu Lab A1',
|
||||
model: 'A1',
|
||||
price: '459€',
|
||||
availability: 'pre_order',
|
||||
description: 'Mid-size desktop 3D printer with AMS lite',
|
||||
features: ['AMS lite compatible', 'Auto-calibration', 'Quick-swap nozzle']
|
||||
}
|
||||
]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const getAvailabilityBadge = (availability: string) => {
|
||||
switch (availability) {
|
||||
case 'available':
|
||||
return (
|
||||
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400">
|
||||
Dostupno
|
||||
</span>
|
||||
);
|
||||
case 'out_of_stock':
|
||||
return (
|
||||
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400">
|
||||
Nema na stanju
|
||||
</span>
|
||||
);
|
||||
case 'pre_order':
|
||||
return (
|
||||
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400">
|
||||
Prednarudžba
|
||||
</span>
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex justify-center items-center py-12">
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-purple-600"></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-6 flex justify-between items-center">
|
||||
<h2 className="text-2xl font-bold text-gray-900 dark:text-gray-100">3D Štampači</h2>
|
||||
<button
|
||||
onClick={() => setIsRequestModalOpen(true)}
|
||||
className="px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition-colors flex items-center space-x-2"
|
||||
>
|
||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" />
|
||||
</svg>
|
||||
<span>Zatraži Štampač</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{printers.map((printer) => (
|
||||
<div key={printer.id} className="bg-white dark:bg-gray-800 rounded-lg shadow-md overflow-hidden">
|
||||
{printer.image_url && (
|
||||
<div className="h-48 bg-gray-200 dark:bg-gray-700">
|
||||
<img src={printer.image_url} alt={printer.name} className="w-full h-full object-cover" />
|
||||
</div>
|
||||
)}
|
||||
<div className="p-6">
|
||||
<div className="flex justify-between items-start mb-2">
|
||||
<h3 className="text-lg font-semibold text-gray-900 dark:text-gray-100">{printer.name}</h3>
|
||||
{getAvailabilityBadge(printer.availability)}
|
||||
</div>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400 mb-2">Model: {printer.model}</p>
|
||||
<p className="text-2xl font-bold text-purple-600 dark:text-purple-400 mb-3">{printer.price}</p>
|
||||
<p className="text-sm text-gray-600 dark:text-gray-300 mb-4">{printer.description}</p>
|
||||
{printer.features && printer.features.length > 0 && (
|
||||
<div className="space-y-1">
|
||||
{printer.features.map((feature, index) => (
|
||||
<div key={index} className="flex items-center text-sm text-gray-600 dark:text-gray-400">
|
||||
<svg className="w-4 h-4 mr-2 text-green-500" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />
|
||||
</svg>
|
||||
{feature}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<PrinterRequestModal isOpen={isRequestModalOpen} onClose={() => setIsRequestModalOpen(false)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
42
src/components/TabbedNavigation.tsx
Normal file
42
src/components/TabbedNavigation.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
interface Tab {
|
||||
id: string;
|
||||
label: string;
|
||||
icon?: React.ReactNode;
|
||||
}
|
||||
|
||||
interface TabbedNavigationProps {
|
||||
tabs: Tab[];
|
||||
activeTab: string;
|
||||
onTabChange: (tabId: string) => void;
|
||||
}
|
||||
|
||||
export default function TabbedNavigation({ tabs, activeTab, onTabChange }: TabbedNavigationProps) {
|
||||
return (
|
||||
<div className="border-b border-gray-200 dark:border-gray-700">
|
||||
<nav className="-mb-px flex justify-center space-x-4 sm:space-x-8" aria-label="Tabs">
|
||||
{tabs.map((tab) => (
|
||||
<button
|
||||
key={tab.id}
|
||||
onClick={() => onTabChange(tab.id)}
|
||||
className={`
|
||||
whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm transition-colors
|
||||
${activeTab === tab.id
|
||||
? 'border-purple-500 text-purple-600 dark:text-purple-400'
|
||||
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 dark:text-gray-400 dark:hover:text-gray-300'
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
{tab.icon}
|
||||
<span>{tab.label}</span>
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -131,4 +131,48 @@ export const colorRequestService = {
|
||||
},
|
||||
};
|
||||
|
||||
export const printersService = {
|
||||
getAll: async () => {
|
||||
try {
|
||||
const response = await api.get('/printers');
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const printerRequestService = {
|
||||
submit: async (request: any) => {
|
||||
try {
|
||||
const response = await api.post('/printer-requests', request);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
return { success: true };
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const gearService = {
|
||||
getAll: async () => {
|
||||
try {
|
||||
const response = await api.get('/gear');
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const gearRequestService = {
|
||||
submit: async (request: any) => {
|
||||
try {
|
||||
const response = await api.post('/gear-requests', request);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
return { success: true };
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default api;
|
||||
Reference in New Issue
Block a user