Go to file
2023-06-22 17:00:10 +02:00
.github/workflows ci(github actions): add create-.env-job 2022-08-30 03:47:22 +02:00
dist feat(shopping cart): list products, impl cart, impl checkout 2022-07-14 02:09:11 +02:00
nginx ci(docker): create dockerfile and compose files 2022-08-07 23:41:50 +02:00
public chore(favicon): add different favicons, change page html title and manifest.json 2022-09-12 02:42:27 +02:00
screenshots 📝 (README) v0.1.0 2022-09-14 07:11:46 +02:00
src Removed products scrolling. 2023-06-19 17:16:43 +02:00
.dockerignore ♻️ (UI) translations and help icons 2022-09-14 07:14:27 +02:00
.env.example refactor(translations): added German translations 2022-09-05 22:16:15 +09:00
.gitignore ci(docker): create dockerfile and compose files 2022-08-07 23:41:50 +02:00
docker-compose.with-traefik.yml build(docker): put env vars in dockerfile, seperate compose files for non-ssl-deployment 2022-08-26 17:24:42 +02:00
docker-compose.yml change default image name 2022-08-26 19:33:20 +02:00
Dockerfile Updates API URL to actual deployment URL 2022-10-04 16:02:55 +02:00
LICENSE refactor(project): init a new project after cleaning the repo 2022-07-07 00:06:33 +02:00
package.json ♻️ (UI) translations and help icons 2022-09-14 07:14:27 +02:00
README.md 🐳 (Dockerfile) try to solve arm64 build problem 2022-09-14 08:47:44 +02:00
tsconfig.json feat(shopping cart): list products, impl cart, impl checkout 2022-07-14 02:09:11 +02:00
yarn.lock ♻️ (UI) translations and help icons 2022-09-14 07:14:27 +02:00

Echtzeitkiosk - Frontend

At the department of Real-Time Systems Lab (ES) at the Technische Universität Darmstadt, employees of the department got together and opened a small kiosk with self-service in the common kitchen. The kiosk was independently filled with different goods to build up a certain stock. Initially it was financed by an appointed employee (from now on called administrator/superuser) who took over the administration of the kiosk and regularly checked the stock. As a result, any employee at the department is able to purchase available products from the kiosk with one payment. In the context of the project seminar software systems at the TU Darmstadt the two authors of this document are to develop a digital solution for inventory and invoice management. This GitHub repository contains the frontend code of the project. The backend code can be found here. You can fork this repository and use it as a template for your own project. The frontend is written in TypeScript with React.js and uses Material-UI with the react-admin library for the user interface. The backend is also written in TypeScript with Node.js and uses Express.js as web framework. The database is a PostgreSQL database and TypeORM is chosen as an object-relational mapper (ORM). Easy deployment with Docker and Docker Compose is supported. You can utilize Traefikv2 as a reverse proxy and Let's Encrypt for SSL certificates easily with the provided docker-compose files which contains also Portainer for container management & monitoring and Adminer for database management on browser. Customer invoices can be sent via email manually or automatically using cron jobs. JWT authentication with role based authorization is implemented.

Setup

Prerequisites

  • Basic knowledge of the command line, UNIX, Docker, Node.js, Git, and GitHub... or the willingness to learn
  • Finish this tutorial to learn CSS Flexbox, if you are not familiar with it. It's a quick and fun way to learn the basics. Also check this cheatsheet for a quick reference.
  • Docker
  • Docker Compose
  • Node - LTS (v16.17.0 at the time of writing) - installation with nvm is recommended
  • npm - LTS (v8.15.0 at the time of writing) - use it only to install yarn in order to make things consistent
  • yarn - stable (v1.22.15 at the time of writing) - install global packages with yarn instead of npm. Run yarn in the project root to install all dependencies of the project when you clone the repository.
  • TypeScript - stable (v4.4.2 at the time of writing)
  • Git
  • Visual Studio Code (optional)
  • Docker Desktop (optional)
  • GitHub Desktop (optional)
  • API - echtzeitkiosk-backend

.env

# production || development || test
NODE_ENV=production

# put this env variable in GitHub secrets if you want to build docker images with GitHub Actions
REACT_APP_API_URL=http://localhost:4000/v1

GitHub Actions

Docker and Docker Compose

Dockerfile

  • Two step build
    • FROM node:16-alpine AS builder
      • If you need to change your server local timezone, you can change it in this step.
      • ENV GENERATE_SOURCEMAP=false ensures that the source map is not generated in production mode.
      • You can also set REACT_APP_API_URL in this step, if you want to build docker images with GitHub Actions and you don't want to put REACT_APP_API_URL in GitHub secrets.
    • FROM nginx:stable-alpine
      • Serve static files from the build folder with nginx
      • nginx configuration file is located at ./nginx/nginx.conf

Docker Compose

docker-compose.yml

  • ./docker-compose.yml is used to run the application in development mode without SSL certificates and reverse proxy. You should use it only for development purposes. You can use it to run the application in production mode if you don't want to use Traefikv2 and Let's Encrypt. Be sure that you set open required ports in your firewall for the services that you want to expose to the internet.

docker-compose.with-traefik.yml

Useful Tips and Notes

  • src/index.tsx is the entry point of the application like the main.cpp in C++ and Main.java in Java. However in React, the entry point is a component which is called App and it is located in src/App.tsx. The index.tsx file is responsible for rendering the App component.
  • Under the public folder, you can find the index.html file which is the template of the application. The index.html file is responsible for loading the index.js file which is the compiled JavaScript code of the application. The index.js file is generated by the build command of the react-scripts package. It is a big file which contains all the JavaScript code of the application since we implemented a single page application.
  • Check CORS settings of your backend if you get any problems after a deployment, when you try to access the API from a browser.
  • Check console logs of the browser if you get any problems after a deployment or while developing. Be sure that the API URL is correct. You should see someting like this in the console: API_URL http://localhost:4000/v1. You can also use the React Developer Tools extension of the browser to inspect the React components.
  • Do not delete the yarn.lock file. It is used to lock the versions of the dependencies of the project. If you delete it, you may get different versions of the dependencies and you may get errors. Do not use npm to install dependencies. Use yarn instead. If you use npm to install dependencies, you may get different versions of the dependencies and you may get errors. Furthermore npm is not compatible with yarn.lock file. If you use npm to install dependencies, you will get an extra package-lock.json file which will make the project inconsistent. So use yarn to install dependencies and if you want to install a global package, use yarn global add <package-name> instead of npm install -g <package-name>. yarn is also used for Docker images. So if you use npm to install dependencies, you may get different versions of the dependencies in the Docker image and you may get errors.
  • token, role, userId, email variables will be stored in the local storage of the browser on login. You can use the browser's developer tools to access them. Logout will remove them from the local storage.
  • `Language and theme preferences will also persist in the local storage of the browser and will be applied on the next visit. You can use the browser's developer tools to access them. Logout will remove them from the local storage.
  • The user will be logged out if the token expires. The token expiration time is set by the backend. The token expiration time can be changed in the backend's .env file.
  • src/authProvider.ts is responsible for the authentication of the application. It is a custom authentication provider which is used by the react-admin package. The react-admin package is a framework for building admin applications. It is a wrapper around the react package. It provides a lot of features out of the box. For example, it provides a data provider which is responsible for fetching data from the backend. It also provides a custom authentication provider which is responsible for the authentication of the application. The react-admin package also provides a custom theme which is responsible for the styling of the application. The react-admin package also provides a custom layout which is responsible for the layout of the application. The react-admin package also provides a custom menu which is responsible for the menu of the application.
  • i18n related files can be found under src/i18n and src/packages. You can edit the files under src/i18n to change the translations.
  • Data fetching functions of react-admin are not used. The react-admin library is used only for the UI, i18n and authentication.
  • Visit react-admin for more information about react-admin.

Commit Messages

yarn commit

This project uses commitizen with the cz-emoji extension to standardize commit messages. To use it, run yarn commit instead of git commit after staging your changes. You will be prompted to select a commit type and write a commit message. You can select the commit type by typing keywords or with arrow keys. The commit message will be automatically formatted according to the commit type. cz-cli package is also installed to use commitizen from the command line. Be sure that required dependencies are installed before using it. You can also use the normal git commit command. We don't validate commit messages, but it's a good practice to use commitizen.

Getting Started with Create React App (CRA)

This project was bootstrapped with Create React App.

CRA Scripts

In the project directory, you can run:

yarn dev

Runs the app in the development mode with hot reloading.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

yarn build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
Build process can take 1-15 minutes, especially with GitHub Actions.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.

yarn eject

Note: this is a one-way operation. Once you eject, you cant go back!

As written below, this project is bootstrapped with CRA and some configurations may not be optimized for your use case. If you arent satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the single build dependency from your project. There are also alternatives to eject that you can use to customize your build process without ejecting. You can check one of these: rewire, CRACO, react-app-rewired .

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject will still work, but they will point to the copied scripts so you can tweak them. At this point youre on your own.

You dont have to ever use eject. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.

Learn More

You can learn more in the Create React App documentation.

To learn React, check out the React documentation.

Credits

Changelog

[0.1.0] - 2022-09-14

Init release.

Major changes

  • Initial release

Changed features

  • Initial release

Roadmap (implicit post-mortem 🥲)

  • Code splitting 🙈
  • Better folder structure 🙈
  • Migration to Vite
  • Utilize react-admin or remove/replace it 🙈
  • Use JSON body instead of url-encoding 🙈
  • Testing 🙈
  • Better CI/CD and linting
    • lint-staged🤕
    • husky🤕
    • ...
  • Optimize nginx config
  • "DRY" components 🙈
  • Use proper strict TypeScript with TSC_COMPILE_ON_ERROR=false... 🥲
    • Use more TypeScript features like Interfaces, Enums, etc. 🙈
  • Add GDPR compliance (cookie consent, privacy policy, etc.) 👨‍⚖️
  • Improve/customize CSV export for the DataGrid component
  • Improve/customize search box for the DataGrid component
  • Improve/customize sorting, pagination and filtering for the DataGrid component
  • Optimize bundle size
  • Optimize images

Contributing

Feel free to contribute to this project. You can open an issue or a pull request. If you want to contribute to this project.

LICENSE

GNU General Public License v3.0