This project is built using Next.js and is designed to handle multiple image uploads, data submissions, and theme management. Below you will find comprehensive details on how to set up the project, run it, contribute, and understand the codebase.
- Setup and Installation
- Running the Project
- How to Contribute
- Features
- Edge Cases
- Code Flow
- Code Explanation
- Clone the repository:
git clone https://github.com/soi-20/shopix-fe.git
- Navigate to the project directory:
cd shopix-fe
- Install dependencies:
npm install
- Copy the
.env.sample
file to.env
and fill in the necessary environment variables:cp .env.sample .env
To run the project locally:
npm run dev
This will start the Next.js development server on http://localhost:3000
.
a Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or fix.
- Make your changes.
- Write or update tests as necessary.
- Submit a pull request against the main branch.
- Go through the Github Workflow document thoroughly to get the complete instructions on how to contribute.
Please ensure your code adheres to the established linting and formatting standards.
- Multiple image uploads.
- Data submission to a backend server.
- Dynamic theme switching between light and dark modes.
- Ensure that file uploads do not exceed the size limits.
- Handle network failures during data submission gracefully.
- Validate URLs and file types on the client side to prevent unnecessary server load.
- .env and .env.sample: Configuration files for environment variables.
- .eslintrc.json, .prettierrc: Configuration files for ESLint and Prettier for code linting and formatting rules.
- next.config.mjs: Configuration file for Next.js settings.
- next-env.d.ts: TypeScript declaration file for Next.js types.
- lib/db.ts: Establishes a PostgreSQL database connection using the
pg
library. - lib/utils.ts: Contains utility functions like
cn
for class name merging andisValidUrl
for URL validation. - lib/validation.ts: Defines Zod schemas for form validation.
- components/ui: Contains reusable UI components like buttons, inputs, cards, and forms.
- button.tsx, input.tsx, card.tsx, label.tsx: Basic UI components with styling.
- form.tsx: Form components integrated with React Hook Form for state management.
- components/theme-toggle/theme-toggle.tsx: A toggle switch component for changing theme modes using
next-themes
.
- app/uploadData/page.tsx: A React component for handling multiple image uploads and data submission.
- app/uploadData/layout.tsx: Layout component that wraps around other components.
- actions/uploadThing.ts: Functions to handle file uploads using a fictional API
UTApi
.
- lib/ThemeWrapper.tsx: A component that provides theme context to its children, disabling theming on specific routes.
- .next: Contains build files and cache for Next.js, including dynamic imports and image optimization cache.
- Upload Data Flow: The
page.tsx
usesuploadThing.ts
actions to handle file uploads and submits data to the server. - UI Components: Reusable UI components are imported and used across different parts of the application, ensuring a consistent look and feel.
- Database Interaction: The
db.ts
file is crucial for database interactions, used by server-side pages or APIs to fetch or store data. - Theme Management:
ThemeWrapper.tsx
andtheme-toggle.tsx
manage the application's theme, allowing users to switch between light and dark modes.
-
lib/db.ts
- Sets up a PostgreSQL connection pool. Configures connection details from environment variables and exports the pool for database interactions.
-
actions/uploadThing.ts
- Contains functions for handling file uploads using
UTApi
. Functions includeuploadFiles
anduploadFromUrl
, which handle file and URL uploads respectively.
- Contains functions for handling file uploads using
-
lib/utils.ts
- Utility functions like
cn
for class name management andisValidUrl
for URL validation.
- Utility functions like
-
lib/ThemeWrapper.tsx
- Provides theme support, disables theming for specific routes, and manages theme states.
-
app/uploadData/page.tsx
- Handles multiple image uploads, manages image state, and submits data to the server.
-
app/uploadData/layout.tsx
- Acts as a layout wrapper for children components.
-
components/ui
- Contains UI components like
card.tsx
,input.tsx
,form.tsx
,button.tsx
,label.tsx
, andinsta-card.tsx
for styled UI elements and form management.
- Contains UI components like
-
components/theme-toggle/theme-toggle.tsx
- Toggle switch for theme management, switching between light and dark modes.
Each component and utility file is designed to provide specific functionality to the frontend, ensuring a modular and maintainable codebase. The backend code supports data persistence and file management tasks, crucial for the application's operations.