This repository contains the frontend code for the Store application. The application is built using Next.js and React, and it includes various components and pages to manage products, categories, orders, and settings.
To get started with the project, clone the repository and install the dependencies:
git clone https://github.com/BoDS-Group/store-frontend.git
cd store-frontend
npm install --legacy-peer-deps
Use the .env copy
file in your project. You need to rename it to .env
and ensure that the environment variables are correctly set.
To run the development server, use the following command:
npm run dev
Open http://localhost:3000 with your browser to see the application.
To build the project for production, use:
npm run build
To start the production server, use:
npm start
The project structure is as follows:
store-frontend/
├── components/
│ ├── AddEmployeeForm.js
│ ├── AxiosInstance.js
│ ├── Button.js
│ ├── DownloadBarcodeButton.js
│ ├── Layout.js
│ ├── LoginForm.js
│ ├── Logo.js
│ ├── Nav.js
│ ├── ProductForm.js
│ ├── Spinner.js
│ ├── Table.js
│ └── UserContext.js
├── pages/
│ ├── api/
│ │ ├── auth/
│ │ │ ├── google.js
│ │ │ └── google/callback.js
│ ├── categories.js
│ ├── employees.js
│ ├── index.js
│ ├── orders.js
│ ├── products/
│ │ ├── delete/[...id].js
│ │ ├── edit/[...id].js
│ │ ├── new.js
│ ├── sales.js
│ ├── settings.js
│ ├── _app.js
│ ├── _document.js
├── public/
│ ├── images/
│ └── styles/
├── styles/
│ ├── globals.css
│ └── Home.module.css
├── utils/
│ └── api.js
├── .env copy
├── .eslintrc.json
├── .gitignore
├── jsconfig.json
├── next.config.js
├── package.json
├── postcss.config.js
├── README.md
└── tailwind.config.js
Form to add a new employee.
Axios instance configured with base URL and interceptors for handling requests and responses.
Styled button component.
Button to download the barcode of a product.
Layout component that includes navigation and user authentication handling.
Form for user login.
Component to display the logo.
Component to render the navigation bar.
Form to add or edit a product.
Component to display a loading spinner.
Styled table component.
Context to manage user state.
The main landing page of the application. Displays store information and user greeting.
Displays a list of products with options to add, edit, delete, and download barcodes.
Form to add a new product.
Form to edit an existing product.
Page to confirm the deletion of a product.
Displays a list of categories with options to add, edit, and delete categories.
Displays a list of orders with details such as date, payment status, recipient, type, and products.
Displays a list of employees with options to add and delete employees.
Page to handle sales entry by scanning product barcodes and submitting orders.
Page to manage settings, including adding new employees.
API route to handle Google OAuth authentication. (Currently not in use)
API route to handle the callback from Google OAuth authentication. (Currently not in use)
Custom App component to initialize the UserProvider context.
Custom Document component to set up the HTML structure.
The application uses Axios for API calls. The AxiosInstance.js
file sets up an Axios instance with a base URL and interceptors for handling requests and responses.
import { fetchStoreData } from "@/utils/api";
useEffect(() => {
async function fetchData() {
const storeData = await fetchStoreData();
setStore(storeData);
}
fetchData();
}, []);
import { fetchProducts } from "@/utils/api";
useEffect(() => {
async function fetchData() {
const productsData = await fetchProducts();
setProducts(productsData);
}
fetchData();
}, []);
import { fetchCategories } from "@/utils/api";
useEffect(() => {
async function fetchData() {
const categoriesData = await fetchCategories();
setCategories(categoriesData);
}
fetchData();
}, []);
import { fetchProductById } from "@/utils/api";
useEffect(() => {
async function fetchData() {
const productData = await fetchProductById(id);
setProductInfo(productData);
}
fetchData();
}, [id]);
import { deleteProductById } from "@/utils/api";
async function deleteProduct() {
await deleteProductById(id);
router.push('/products');
}
import { updateCategoryById } from "@/utils/api";
async function saveCategory() {
await updateCategoryById(editedCategory.id, data);
}
import { deleteCategoryById } from "@/utils/api";
async function deleteCategory(id) {
await deleteCategoryById(id);
}
import { insertCategory } from "@/utils/api";
async function saveCategory() {
await insertCategory(data);
}