Skip to content

aestheliaa/barkasiwa-fe

Repository files navigation

Frontend Barkasiwa πŸŽ“

Marketplace kampus untuk jual beli barang bekas antar mahasiswa. Dibangun dengan Next.js 16, React 19, dan Tailwind CSS 4.

✨ Fitur Lengkap

🌐 Public Pages

  • Landing Page - Hero section dengan featured products
  • Product List - Katalog produk dengan filter kategori
  • Product Detail - Detail produk dengan info penjual
  • Login & Register - Autentikasi user

πŸ‘€ User Features (Protected)

  • My Products - Kelola produk sendiri (view, edit, delete)
  • Upload Product - Form upload produk dengan foto
  • Edit Product - Update informasi produk
  • Wishlist - Simpan produk favorit

πŸ‘¨β€πŸ’Ό Admin Features (Admin Only)

  • Admin Dashboard - Statistics overview (users, products, categories, wishlists)
  • Manage Users - Lihat semua user dan role
  • Manage Products - Lihat & hapus semua produk
  • Manage Categories - Lihat & tambah kategori baru

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ atau Bun
  • Backend Barkasiwa running di http://localhost:4000

Installation

# Install dependencies
bun install
# atau
npm install

# Run development server
bun dev
# atau
npm run dev

Buka http://localhost:3000

πŸ“ Struktur Project

frontend-barkasiwa/
β”œβ”€β”€ app/                          # Next.js App Router
β”‚   β”œβ”€β”€ page.tsx                  # Landing page
β”‚   β”œβ”€β”€ layout.tsx                # Root layout dengan AuthProvider
β”‚   β”œβ”€β”€ login/                    # Login page
β”‚   β”œβ”€β”€ register/                 # Register page
β”‚   β”œβ”€β”€ products/                 # Public product pages
β”‚   β”‚   β”œβ”€β”€ page.tsx              # Product list
β”‚   β”‚   └── [id]/page.tsx         # Product detail
β”‚   β”œβ”€β”€ dashboard/                # Protected user pages
β”‚   β”‚   β”œβ”€β”€ products/
β”‚   β”‚   β”‚   β”œβ”€β”€ page.tsx          # My products
β”‚   β”‚   β”‚   β”œβ”€β”€ new/page.tsx      # Upload product
β”‚   β”‚   β”‚   └── [id]/edit/page.tsx # Edit product
β”‚   β”‚   └── wishlist/page.tsx     # My wishlist
β”‚   └── admin/                    # Admin pages
β”‚       β”œβ”€β”€ page.tsx              # Dashboard
β”‚       β”œβ”€β”€ users/page.tsx        # Manage users
β”‚       β”œβ”€β”€ products/page.tsx     # Manage products
β”‚       └── categories/page.tsx   # Manage categories
β”œβ”€β”€ components/                   # React components
β”‚   β”œβ”€β”€ Navbar.tsx                # Navigation bar
β”‚   └── ProductCard.tsx           # Product card component
β”œβ”€β”€ contexts/                     # React contexts
β”‚   └── AuthContext.tsx           # Authentication context
β”œβ”€β”€ lib/                          # Utilities
β”‚   β”œβ”€β”€ api.ts                    # API client
β”‚   └── utils.ts                  # Helper functions
β”œβ”€β”€ types/                        # TypeScript types
β”‚   └── api.ts                    # API types
└── .env.local                    # Environment variables

πŸ” Authentication

Authentication menggunakan JWT token (localStorage) dan HttpOnly cookie.

Usage

import { useAuth } from '@/contexts/AuthContext';

function MyComponent() {
  const { user, isAdmin, loading, login, logout } = useAuth();

  // Check if user is logged in
  if (user) {
    console.log('Logged in as:', user.nama);
  }

  // Check if user is admin
  if (isAdmin) {
    console.log('User has admin privileges');
  }

  // Login
  await login(email, password);

  // Logout
  await logout();
}

πŸ“‘ API Integration

API client tersedia di lib/api.ts:

import { api } from '@/lib/api';

// Get all products
const products = await api.getProducts();

// Get product detail
const product = await api.getProduct(id);

// Create product
const formData = new FormData();
formData.append('nama_barang', 'Laptop');
formData.append('harga', '5000000');
formData.append('category_id', '1');
formData.append('foto', file);
await api.createProduct(formData);

// Add to wishlist
await api.addToWishlist(productId);

// Admin: Get stats
const stats = await api.getAdminStats();

🎨 Styling

Menggunakan Tailwind CSS 4 dengan utility-first approach:

<div className="bg-white p-4 rounded-lg shadow-md hover:shadow-lg transition">
  <h1 className="text-3xl font-bold text-blue-600">Title</h1>
  <p className="text-gray-600 mt-2">Description</p>
</div>

πŸ”§ Utility Functions

Format Currency

import { formatCurrency } from '@/lib/utils';
formatCurrency(5000000); // "Rp 5.000.000"

Format Date

import { formatDate } from '@/lib/utils';
formatDate('2025-01-09'); // "9 Januari 2025"

Get Image URL

import { getImageUrl } from '@/lib/utils';
getImageUrl('abc123.jpg'); // "http://localhost:4000/uploads/abc123.jpg"

πŸ§ͺ Testing

Test Credentials

Admin:

User:

  • Register via /register

Test Flow

  1. Landing Page β†’ http://localhost:3000
  2. Register β†’ Create new account
  3. Login β†’ Login with credentials
  4. Browse Products β†’ View product list
  5. Product Detail β†’ Click on product
  6. Add to Wishlist β†’ Click wishlist button
  7. Upload Product β†’ Go to "Produk Saya" β†’ "+ Upload Produk"
  8. Admin Dashboard β†’ Login as admin β†’ Click "Admin"

🌍 Environment Variables

File .env.local:

NEXT_PUBLIC_API_URL=http://localhost:4000

πŸ“¦ Build & Deploy

Development

bun dev

Production Build

bun run build
bun start

Type Check

bun run build

πŸ› Troubleshooting

CORS Error

Pastikan backend .env memiliki:

CORS_ORIGIN=http://localhost:3000

Image Not Loading

  1. Pastikan backend running
  2. Check file ada di backend-barkasiwa/public/uploads/
  3. Verify next.config.ts sudah dikonfigurasi

Authentication Error

Clear localStorage dan cookies:

localStorage.clear();

Port Already in Use

# Kill process on port 3000
npx kill-port 3000

πŸ“š Tech Stack

  • Framework: Next.js 16 (App Router)
  • UI Library: React 19
  • Styling: Tailwind CSS 4
  • Language: TypeScript 5
  • Package Manager: Bun / npm
  • Image Optimization: Next.js Image

πŸ”— Links

πŸ“ Notes

  • Backend harus running sebelum start frontend
  • Protected routes akan redirect ke /login jika belum login
  • Admin routes akan redirect ke / jika bukan admin
  • Image upload max size sesuai backend config
  • Token disimpan di localStorage dan HttpOnly cookie

🎯 Next Steps

  • Add search functionality
  • Add pagination
  • Add product sorting
  • Add user profile page
  • Add chat/messaging feature
  • Add notifications
  • Add image gallery for products
  • Add product reviews/ratings

πŸ“„ License

Private project for Barkasiwa marketplace.


Happy Coding! πŸš€

About

Platform jual beli barang bekas khusus mahasiswa

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors