Skip to content

Thomas465xd/morango-frontend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

72 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’ Morango E-commerce - Frontend

Customer-facing and admin e-commerce platform for jewelry sales built with Next.js 15, React 19, and TailwindCSS.

Overview

This is the frontend application for Morango Joyas, a full-stack e-commerce platform featuring:

  • πŸ›οΈ Product browsing and cart management
  • πŸ›’ Checkout flow with MercadoPago integration
  • πŸ‘€ User authentication & account management
  • πŸ“¦ Order tracking and history
  • πŸ” Admin dashboard for order and product management
  • πŸŒ™ Dark mode support
  • πŸ“± Mobile-responsive design

See also: Backend Repository


πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Backend API running on http://localhost:3000 (or configure via NEXT_PUBLIC_BACKEND_API_URL)

Installation & Development

# Clone and install dependencies
npm install

# Set up environment variables
cp .env.example .env.local
# Edit .env.local with your configuration

# Start development server
npm run dev

Open http://localhost:3000 in your browser.

Environment Variables

Create .env.local with:

NEXT_PUBLIC_BACKEND_API_URL=http://localhost:4000/api
NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME="asdfgh"
NEXT_PUBLIC_CLOUDINARY_API_KEY=cloudinary-key
NEXT_PUBLIC_MP_PUBLIC_KEY=mp-public-key
NEXT_PUBLIC_FREE_SHIPPING=public-shipping-value

πŸ“ Project Structure

client/
β”œβ”€β”€ app/                      # Next.js App Router pages
β”‚   β”œβ”€β”€ home/                 # Public customer pages
β”‚   β”‚   β”œβ”€β”€ page.tsx          # Home/product listing
β”‚   β”‚   β”œβ”€β”€ products/         # Product details
β”‚   β”‚   β”œβ”€β”€ cart/             # Shopping cart
β”‚   β”‚   β”œβ”€β”€ orders/           # Order history
β”‚   β”‚   └── profile/          # User account
β”‚   β”œβ”€β”€ admin/                # Protected admin routes
β”‚   β”‚   β”œβ”€β”€ orders/           # Order management
β”‚   β”‚   β”œβ”€β”€ products/         # Product management
β”‚   β”‚   β”œβ”€β”€ users/            # User management
β”‚   β”‚   └── analytics/        # Sales analytics
β”‚   β”œβ”€β”€ auth/                 # Authentication
β”‚   β”‚   β”œβ”€β”€ login/
β”‚   β”‚   β”œβ”€β”€ register/
β”‚   β”‚   β”œβ”€β”€ forgot-password/
β”‚   β”‚   └── reset-password/
β”‚   β”œβ”€β”€ checkout/             # Checkout & payment
β”‚   β”‚   β”œβ”€β”€ page.tsx
β”‚   β”‚   β”œβ”€β”€ success/
β”‚   β”‚   β”œβ”€β”€ failure/
β”‚   β”‚   └── pending/
β”‚   └── layout.tsx            # Root layout with providers
β”œβ”€β”€ components/               # Reusable React components
β”‚   β”œβ”€β”€ providers/            # Context providers (Query, Theme, Toast, MercadoPago)
β”‚   β”œβ”€β”€ admin/                # Admin-specific components
β”‚   β”œβ”€β”€ checkout/             # Checkout flow components
β”‚   β”œβ”€β”€ home/                 # Customer UI components
β”‚   β”œβ”€β”€ auth/                 # Authentication forms
β”‚   β”œβ”€β”€ payment/              # Payment status views
β”‚   β”œβ”€β”€ products/             # Product display components
β”‚   β”œβ”€β”€ ui/                   # Generic UI components
β”‚   └── skeletons/            # Loading skeletons
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ api/                  # Axios API clients
β”‚   β”‚   β”œβ”€β”€ AuthAPI.ts
β”‚   β”‚   β”œβ”€β”€ ProductAPI.ts
β”‚   β”‚   β”œβ”€β”€ OrderAPI.ts
β”‚   β”‚   └── PaymentAPI.ts
β”‚   β”œβ”€β”€ hooks/                # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ useAuth.ts        # Authentication state
β”‚   β”‚   β”œβ”€β”€ useTimer.ts       # Countdown timers
β”‚   β”‚   β”œβ”€β”€ useMobile.ts      # Mobile detection
β”‚   β”‚   └── useFilters.ts     # Query parameter filters
β”‚   β”œβ”€β”€ store/                # Zustand state stores
β”‚   β”‚   └── useCartStore.ts
β”‚   β”œβ”€β”€ types/                # TypeScript interfaces
β”‚   β”‚   └── index.ts          # Centralized types
β”‚   └── utils/                # Utility functions
β”‚       β”œβ”€β”€ date.ts           # Date formatting
β”‚       β”œβ”€β”€ price.ts          # Currency formatting (CLP)
β”‚       β”œβ”€β”€ text.ts           # Text transformations
β”‚       └── copy.ts           # Clipboard utilities
β”œβ”€β”€ lib/
β”‚   └── axios.ts              # Shared axios instance
β”œβ”€β”€ public/                   # Static assets
β”œβ”€β”€ globals.css               # Global styles
β”œβ”€β”€ next.config.ts            # Next.js configuration
β”œβ”€β”€ tsconfig.json             # TypeScript config
β”œβ”€β”€ tailwind.config.js        # TailwindCSS config
└── package.json

πŸ”¨ Available Scripts

# Development with Turbopack
npm run dev

# Production build
npm run build

# Start production server
npm start

# Lint code
npm run lint

πŸ—οΈ Architecture

Technology Stack

  • Framework: Next.js 15 (App Router)
  • UI Library: React 19
  • Styling: TailwindCSS 4 with dark mode
  • State Management:
    • Server State: React Query (TanStack Query)
    • Client State: Zustand
    • Async Forms: react-hook-form + zod
  • HTTP Client: Axios (shared instance with credentials)
  • Payment: MercadoPago SDK
  • Icons: Lucide React
  • Notifications: React Toastify + SweetAlert2
  • Theming: next-themes

Key Data Flows

Authentication Flow:

  1. User logs in via LoginForm β†’ calls AuthAPI.login()
  2. Backend issues JWT in httpOnly cookie
  3. Subsequent requests auto-include cookie
  4. useAuth() hook verifies session on app load
  5. Protected routes redirect unauthenticated users to /auth/login

Shopping Flow:

  1. User browses products (fetched via ProductAPI)
  2. Adds items to cart (stored in useCartStore)
  3. Proceeds to checkout β†’ CheckoutForm captures shipping address
  4. Payment collected via CheckoutPayment (MercadoPago)
  5. Backend webhook updates order status
  6. Redirect to success/failure page with order tracking

State Management:

  • useQuery: Product lists, user orders, admin data (cached + auto-refetch)
  • useMutation: Form submissions with error/success handlers
  • Zustand: Cart items (persists across page navigation)

πŸ’» Development Guidelines

Adding a New Feature

  1. Create API client in src/api/FeatureAPI.ts

    export const fetchData = async (params) => {
      const response = await api.get('/endpoint', { params });
      return response.data;
    };
  2. Create components in components/feature/

    • Use functional components with hooks
    • Keep components focused and single-responsibility
  3. Create pages in app/feature/page.tsx

    • Leverage Next.js App Router layout nesting
    • Use useQuery/useMutation for data fetching
  4. Add types to src/types/index.ts

    export interface Feature {
      id: string;
      name: string;
    }

Styling Patterns

Use the status badge pattern from components/admin/orders/OrderEntry.tsx:

const statusConfig: Record<StatusType, { color: string; bgColor: string }> = {
  "Active": { 
    color: "text-green-800 dark:text-green-300", 
    bgColor: "bg-green-100 dark:bg-green-900/30" 
  },
};

<div className={`${statusConfig[status].bgColor} ${statusConfig[status].color}`}>
  {status}
</div>

Data Fetching Patterns

Reading data:

const { data, isLoading, error } = useQuery({
  queryKey: ['products'],
  queryFn: () => ProductAPI.getProducts()
});

Mutating data:

const { mutate } = useMutation({
  mutationFn: (data) => ProductAPI.updateProduct(data),
  onSuccess: () => {
    toast.success('Updated!');
    queryClient.invalidateQueries({ queryKey: ['products'] });
  },
  onError: (error) => toast.error(error.message)
});

Dark Mode

All new components should support dark mode:

className="text-zinc-900 dark:text-zinc-100 bg-white dark:bg-zinc-900"

πŸ“¦ Deployment

Docker Build

docker build -t morango-frontend .
docker run -p 3000:3000 \
  -e NEXT_PUBLIC_BACKEND_API_URL=https://api.morango.com \
  -e NEXT_PUBLIC_MERCADOPAGO_PUBLIC_KEY=your_key \
  morango-frontend

πŸ”— Integration Points

  • Backend API: NEXT_PUBLIC_BACKEND_API_URL (Express.js server)
  • MercadoPago: SDK initialization in MercadoPagoProvider
  • Cloudinary: Image hosting via remotePatterns in next.config.ts
  • EmailJS: Contact form submissions (client-side)

πŸ“ Important Notes

  • Language: All UI text is in Spanish (es-ES)
  • Currency: Chilean Peso (CLP) - use formatToCLP() utility
  • Date Format: Use formatDate() from src/utils/date.ts
  • Authentication: Always verify routes with useAuth() before rendering protected content
  • Caching: Invalidate React Query on mutations: queryClient.invalidateQueries({ queryKey: [...] })

Made with β™₯️ Thomas SchrΓΆdinger.

About

Morango E-Commerce website Frontend made using Next.js βœ¨πŸ› οΈ

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages