Skip to content

muhammedmokbel/react-task-astudio

Repository files navigation

React + TypeScript + Vite Project

A modern, feature-rich React application built with Vite, TypeScript, and cutting-edge technologies for managing and displaying user and product data.

πŸš€ Features

  • βœ… React 19 with TypeScript for type-safe development
  • βœ… Vite 7 for lightning-fast development and building
  • βœ… React Router DOM 7 for client-side routing
  • βœ… Axios for HTTP requests with request/response interceptors
  • βœ… Context API for global state management
  • βœ… Tailwind CSS v4 for modern utility-first styling
  • βœ… Ant Design 5 for professional UI components
  • βœ… Reusable DataTable Component with advanced features:
    • Server-side pagination
    • Dynamic page size selection (5, 10, 20, 50)
    • Server-side filtering (key-value pairs)
    • Client-side search functionality
    • Custom color scheme
  • βœ… Tab Navigation for categorized product views
  • βœ… Field Selection via query parameters for optimized API responses
  • βœ… Responsive design with custom styling

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v18 or higher recommended)
  • npm (v9 or higher) or yarn

πŸ› οΈ Installation & Setup

1. Clone or Download the Project

git clone <repository-url>
cd astudio-task

2. Install Dependencies

npm install

This will install all required dependencies including:

  • React, React DOM, React Router DOM
  • Axios for API calls
  • Ant Design for UI components
  • Tailwind CSS v4 for styling
  • TypeScript and all type definitions

3. Start Development Server

npm run dev

The application will start at http://localhost:5173/

4. Build for Production

npm run build

5. Preview Production Build

npm run preview

πŸ“ Project Structure

astudio-task/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ axios.ts              # Axios instance with interceptors
β”‚   β”‚   β”œβ”€β”€ userService.ts        # User API service with filters & select fields
β”‚   β”‚   └── productService.ts     # Product API service with category support
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ DataTable.tsx         # Reusable table with pagination, filters, search
β”‚   β”‚   β”œβ”€β”€ DataTable.css         # Custom table styling
β”‚   β”‚   β”œβ”€β”€ TabComponent.tsx      # Reusable tab wrapper component
β”‚   β”‚   β”œβ”€β”€ TabComponent.css      # Tab styling
β”‚   β”‚   └── Navbar.tsx            # Navigation bar
β”‚   β”œβ”€β”€ context/
β”‚   β”‚   └── AppContext.tsx        # Global state management with Context API
β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”œβ”€β”€ Home.tsx              # Landing page
β”‚   β”‚   β”œβ”€β”€ Users.tsx             # Users table with 9 columns
β”‚   β”‚   └── Products.tsx          # Products with tabs (All/Laptops)
β”‚   β”œβ”€β”€ App.tsx                   # Main app with routing configuration
β”‚   β”œβ”€β”€ App.css                   # App-level styles
β”‚   β”œβ”€β”€ main.tsx                  # Application entry point
β”‚   └── index.css                 # Global styles with Tailwind imports
β”œβ”€β”€ public/                       # Static assets
β”œβ”€β”€ index.html                    # HTML template
β”œβ”€β”€ package.json                  # Dependencies and scripts
β”œβ”€β”€ tsconfig.json                 # TypeScript configuration
β”œβ”€β”€ tailwind.config.js            # Tailwind CSS configuration
β”œβ”€β”€ postcss.config.js             # PostCSS configuration for Tailwind v4
└── vite.config.ts                # Vite configuration

🌐 API Integration

The project uses DummyJSON API for data:

Users Endpoint

  • Base URL: https://dummyjson.com/users
  • Features: Pagination, filtering, field selection
  • Example: https://dummyjson.com/users?limit=10&skip=0&select=firstName,lastName,age,gender,email,username,bloodGroup,eyeColor,maidenName

Products Endpoints

  • All Products: https://dummyjson.com/products
  • Category Products: https://dummyjson.com/products/category/laptops
  • Features: Pagination, filtering, field selection, category filtering
  • Example: https://dummyjson.com/products?limit=10&skip=0&select=title,brand,category

API Service Features

  • βœ… Automatic request/response interceptors
  • βœ… Error handling
  • βœ… Dynamic query parameter building
  • βœ… Server-side filtering with key-value pairs
  • βœ… Field selection for optimized responses
  • βœ… Category-based product fetching

🎨 UI Features

Users Page

Displays a table with 9 columns:

  1. First Name
  2. Last Name
  3. Maiden Name
  4. Age
  5. Gender
  6. Email
  7. Username
  8. Blood Group
  9. Eye Color

Features:

  • Server-side pagination (10 items per page default)
  • Adjustable page size (5, 10, 20, 50)
  • Filters: firstName, age, gender
  • Client-side search across all fields
  • Custom color scheme

Products Page

Displays products with tabbed navigation:

Tabs:

  • All: Shows all products from /products
  • Laptops: Shows only laptops from /products/category/laptops

Columns:

  1. Title
  2. Brand
  3. Category

Features:

  • Server-side pagination (10 items per page default)
  • Adjustable page size (5, 10, 20, 50)
  • Filters: title, brand, category
  • Client-side search across all fields
  • Tab switching resets pagination
  • Filters work independently in each tab

Custom Color Scheme

  • Black: #322625
  • Grey: #ebebeb
  • Blue: #c0e3e5
  • Yellow: #fdc936

🧩 Key Components

DataTable Component

A highly reusable table component with props:

  • data: Array of items to display
  • columns: Column definitions
  • loading: Loading state
  • total: Total number of items for pagination
  • pageSize: Current page size
  • currentPage: Current page number
  • onPageChange: Page change handler
  • onPageSizeChange: Page size change handler
  • onSearch: Search handler
  • onFilterChange: Filter change handler
  • filters: Array of filter field definitions

TabComponent

A reusable tab wrapper with props:

  • items: Array of tab items (key, label, children)
  • activeKey: Currently active tab key
  • onChange: Tab change handler
  • defaultActiveKey: Default tab (optional)

πŸ“ Available Scripts

Command Description
npm run dev Start development server at http://localhost:5173
npm run build Build for production (outputs to dist/)
npm run preview Preview production build locally
npm run lint Run ESLint to check code quality

πŸ”§ Configuration Files

TypeScript (tsconfig.json)

Configured for strict type checking and React development.

Tailwind CSS (tailwind.config.js)

  • Content paths configured for all .tsx and .ts files
  • Extensible theme configuration
  • Tailwind CSS v4 with PostCSS plugin

Vite (vite.config.ts)

  • React plugin enabled
  • Fast refresh for development
  • Optimized build output

πŸ§ͺ Testing the Application

1. Navigate to Home Page

  • Visit http://localhost:5173/
  • You should see the home page with navigation links

2. Test Users Page

  • Click "Users" in the navbar
  • Verify the table loads with 10 users
  • Try changing page size (5, 10, 20, 50)
  • Test pagination by navigating pages
  • Apply a filter (e.g., firstName = "Emily")
  • Use the search feature to find specific users
  • Verify all 9 columns display correctly

3. Test Products Page

  • Click "Products" in the navbar
  • Verify "All" tab is active by default
  • Check that products load correctly
  • Switch to "Laptops" tab
  • Verify only laptops are displayed
  • Test pagination in both tabs
  • Apply filters (e.g., brand = "Apple")
  • Use search to find products
  • Change page size and verify it works

4. Test Navigation

  • Use the navbar to switch between pages
  • Verify routing works without page reload
  • Check that state persists appropriately

πŸ› Troubleshooting

Development server won't start

# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm install
npm run dev

Tailwind styles not applying

  • Ensure @import "tailwindcss"; is in src/index.css
  • Check that PostCSS config includes @tailwindcss/postcss
  • Restart dev server

API calls failing

  • Check network connection
  • Verify DummyJSON API is accessible: https://dummyjson.com/
  • Check browser console for error messages
  • Ensure axios interceptors are properly configured

TypeScript errors

# Check TypeScript compilation
npm run build

# Or run type checking
npx tsc --noEmit

πŸ“¦ Dependencies

Production Dependencies

  • react (^19.1.1) - UI library
  • react-dom (^19.1.1) - React DOM rendering
  • react-router-dom (^7.9.4) - Routing
  • axios (^1.12.2) - HTTP client
  • antd (^5.27.4) - UI component library

Development Dependencies

  • vite (^7.1.7) - Build tool
  • typescript (~5.9.3) - Type safety
  • tailwindcss (^4.1.14) - CSS framework
  • @tailwindcss/postcss (^4.1.14) - Tailwind PostCSS plugin
  • @vitejs/plugin-react (^5.0.4) - React plugin for Vite
  • ESLint and related plugins for code quality

🎯 Features Highlights

  1. Optimized API Calls: Uses select parameter to fetch only needed fields
  2. Server-Side Filtering: Filters applied at API level for better performance
  3. Reusable Components: DataTable and TabComponent can be used across the app
  4. Type Safety: Full TypeScript coverage for all components and services
  5. Modern Stack: Latest versions of React, Vite, and other libraries
  6. Professional UI: Ant Design components with custom styling
  7. Responsive Design: Works on desktop and mobile devices
  8. Clean Architecture: Separated concerns (API, components, pages, context)

πŸ“„ License

MIT

πŸ‘₯ Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ž Support

For issues or questions, please open an issue in the repository.


Happy Coding! πŸš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published