A modern, responsive web application for calculating shipping costs for boxes to specific locations worldwide from India. Built with React, TypeScript, and Tailwind CSS.
- Log in to vercel
- Navigate to [https://shipping-fi3kfca75-swastiks-projects-22cd5f0f.vercel.app/]
- Features
- Tech Stack
- Project Structure
- Getting Started
- Available Scripts
- Application Architecture
- Features Breakdown
- Design Decisions
- β Add Shipping Boxes - Create new shipping entries with receiver details
- β Dynamic Cost Calculation - Automatic shipping cost calculation based on weight and destination
- β Color Visualization - Visual representation of box colors with RGB values
- β Real-time Validation - Form validation with instant error feedback
- β Persistent Storage - Data saved locally using localStorage
- β Responsive Design - Fully responsive across mobile, tablet, and desktop
- β Clean UI/UX - Modern interface with smooth transitions and hover effects
- React 19.2.0 - UI library
- TypeScript 4.9.5 - Type-safe JavaScript
- Tailwind CSS 3.4.18 - Utility-first CSS framework
- React Router DOM 6.x - Client-side routing
- Context API - Centralized state management
- localStorage - Data persistence
- Create React App - React application setup
- PostCSS - CSS processing
- Autoprefixer - Browser compatibility
shipping-box/
βββ public/ # Static files
βββ src/
β βββ components/ # React components
β β βββ Navbar.tsx # Navigation component
β β βββ AddBox.tsx # Form for adding boxes
β β βββ BoxList.tsx # Table displaying boxes
β βββ context/ # State management
β β βββ BoxContext.tsx # Box context provider
β βββ types/ # TypeScript definitions
β β βββ index.ts # Type definitions
β βββ utils/ # Utility functions
β β βββ calculations.t s # Shipping cost calculator
β βββ App.tsx # Main app component
β βββ index.tsx # Entry point
βββ tailwind.config.js # Tailwind configuration
βββ postcss.config.js # PostCSS configuration
βββ tsconfig.json # TypeScript configuration
βββ package.json # Dependencies
- Node.js (v16 or higher)
- npm or yarn
-
Clone the repository
git clone git@github.com:Swastik1/shipping-box.git cd shipping-box -
Install dependencies
npm install
-
Start the development server
npm start
-
Open your browser Navigate to http://localhost:3000
Runs the app in development mode at http://localhost:3000
- Hot reload enabled
- Error reporting in browser
Builds the app for production to the build folder
- Optimized and minified
- Ready for deployment
Launches the test runner in interactive watch mode
The application follows the Model-View-Controller (MVC) design pattern:
- Types (
src/types/index.ts) - Data structure definitions - Context (
src/context/BoxContext.tsx) - Data management and business logic - Calculations (
src/utils/calculations.ts) - Shipping cost computation
- Components (
src/components/) - UI componentsNavbar.tsx- Navigation between viewsAddBox.tsx- Form for adding boxesBoxList.tsx- Table for displaying boxes
- BoxContext - Manages state and provides data to views
- React Hooks -
useState,useContext,useEffectfor component logic
User Action β Component β Context API β localStorage
β
State Update
β
Component Re-render
Fields:
- Receiver Name (text input) - Required field
- Weight (number input) - In kilograms, validates negative values
- Box Color (color picker) - Returns RGB format
- Destination Country (dropdown) - 4 countries with shipping rates
Validation:
- All fields required
- Weight cannot be negative (auto-resets to 0)
- Weight must be greater than 0
- Real-time error clearing on input
Shipping Rates:
- Sweden: βΉ7.35/kg
- China: βΉ11.53/kg
- Brazil: βΉ15.63/kg
- Australia: βΉ50.09/kg
Columns:
- Receiver Name
- Weight (kg)
- Box Color (visual color box + RGB values)
- Destination Country
- Shipping Cost (INR format)
Features:
- Responsive table with horizontal scroll on mobile
- Hover effects on rows
- Empty state message when no boxes added
- Color visualization with actual colored boxes
Navbar Component:
- Two routes: Add Box and Box List
- Active route highlighting
- Responsive design (stacked on mobile, horizontal on desktop)
- Simplicity - Small-to-medium sized application
- No boilerplate - Less code to maintain
- Built-in - No additional dependencies
- Sufficient - Handles our state management needs perfectly
- Persistence - Data survives page refreshes
- No backend needed - Meets "local storage" requirement
- Simple API - Easy to implement and maintain
- Synchronous - No async complexity
- Rapid development - Utility-first approach speeds up styling
- Responsive design - Built-in responsive utilities
- Consistency - Design system out of the box
- Performance - Purges unused styles in production
- Type safety - Catch errors at compile time
- Better IDE support - Autocomplete and IntelliSense
- Code quality - Self-documenting code
- Refactoring - Safe and confident code changes
The color picker returns hex values (#FF5733), which are converted to RGB format (255, 87, 51) using a custom utility function.
const hexToRgb = (hex: string): string => {
// Regex pattern extracts RGB components
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
if (result) {
return `${parseInt(result[1], 16)}, ${parseInt(
result[2],
16
)}, ${parseInt(result[3], 16)}`;
}
return "255, 255, 255";
};export const calculateShippingCost = (
weight: number,
country: Country
): number => {
const rate = COUNTRY_RATES[country];
const cost = weight * rate;
return Math.round(cost * 100) / 100; // Round to 2 decimals
};- On Mount: Load boxes from localStorage
- On Change: Auto-save to localStorage
- Key:
shippingBoxes
- Mobile: < 640px
- Tablet: β₯ 640px
- Desktop: β₯ 768px
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
This project demonstrates:
- React component architecture
- TypeScript type safety
- State management with Context API
- Form handling and validation
- Responsive design principles
- Data persistence strategies
- Clean code organization
- MVC design pattern implementation
This project is created for educational purposes.
[Swastik Panda]
- GitHub: [@Swastik1]
- Email: swastik.panda.official@gmail.com
- Create React App for the initial setup
- Tailwind CSS for the styling framework
- React community for excellent documentation
Built with β€οΈ using React, TypeScript, and Tailwind CSS