Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    JavaScript

    Build Real-world React Native App #1: Splash screen and App Icon

    JavaScript

    Progressive Web Applications and Service Workers

    Interview

    Interview with Philipp

    Important Pages:
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Today's Picks:
    • Scaling Success: Monitoring Indexation of Programmatic SEO Content
    • Leveraging Influencers: Key Drivers in New Product Launches
    • How Privacy-First Marketing Will Transform the Industry Landscape
    • The Impact of Social Proof on Thought Leadership Marketing
    • Balancing Value-Driven Content and Promotional Messaging Strategies
    • Top Influencer Marketing Platforms to Explore in 2025
    • Emerging Trends in Marketing Automation and AI Tools for 2023
    • Strategies to Mitigate Duplicate Content in Programmatic SEO
    Wednesday, September 10
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Soshace Digital Blog
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Services
    • SaaS & Tech

      Maximizing Efficiency: How SaaS Lowers IT Infrastructure Costs

      August 27, 2025

      Navigating Tomorrow: Innovations Shaping the Future of SaaS

      August 27, 2025

      Maximizing Impact: Strategies for SaaS & Technology Marketing

      August 27, 2025
    • AI & Automation

      Enhancing Customer Feedback Analysis Through AI Innovations

      August 27, 2025

      Navigating the Impact of AI on SEO and Search Rankings

      August 27, 2025

      5 Automation Hacks Every Home Service Business Needs to Know

      May 3, 2025
    • Finance & Fintech

      Critical Missteps in Finance Marketing: What to Avoid

      August 27, 2025

      Analyzing Future Fintech Marketing Trends: Insights Ahead

      August 27, 2025

      Navigating the Complex Landscape of Finance and Fintech Marketing

      August 27, 2025
    • Legal & Compliance

      Exploring Thought Leadership’s Impact on Legal Marketing

      August 27, 2025

      Maximizing LinkedIn: Strategies for Legal and Compliance Marketing

      August 27, 2025

      Why Transparency Matters in Legal Advertising Practices

      August 27, 2025
    • Medical Marketing

      Enhancing Online Reputation Management in Hospitals: A Guide

      August 27, 2025

      Analyzing Emerging Trends in Health and Medical Marketing

      August 27, 2025

      Exploring Innovative Content Ideas for Wellness Blogs and Clinics

      August 27, 2025
    • E-commerce & Retail

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      August 27, 2025

      Emerging Trends in E-commerce and Retail Marketing Strategies

      August 27, 2025

      Maximizing Revenue: The Advantages of Affiliate Marketing for E-Commerce

      August 27, 2025
    • Influencer & Community

      Leveraging Influencers: Key Drivers in New Product Launches

      August 27, 2025

      Top Influencer Marketing Platforms to Explore in 2025

      August 27, 2025

      Key Strategies for Successful Influencer Partnership Negotiations

      August 27, 2025
    • Content & Leadership

      The Impact of Social Proof on Thought Leadership Marketing

      August 27, 2025

      Balancing Value-Driven Content and Promotional Messaging Strategies

      August 27, 2025

      Analyzing Storytelling’s Impact on Content Marketing Effectiveness

      August 27, 2025
    • SEO & Analytics

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      August 27, 2025

      Strategies to Mitigate Duplicate Content in Programmatic SEO

      August 27, 2025

      Effective Data Visualization Techniques for SEO Reporting

      August 27, 2025
    • Marketing Trends

      How Privacy-First Marketing Will Transform the Industry Landscape

      August 27, 2025

      Emerging Trends in Marketing Automation and AI Tools for 2023

      August 27, 2025

      Maximizing ROI: Key Trends in Paid Social Advertising

      August 27, 2025
    Soshace Digital Blog
    Blog / JavaScript / POS Tutorial / Create simple POS with React.js, Node.js, and MongoDB #7: Adding redux to other components
    JavaScript

    Create simple POS with React.js, Node.js, and MongoDB #7: Adding redux to other components

    Krissanawat KaewsanmuangBy Krissanawat KaewsanmuangJune 22, 2020Updated:June 22, 2020No Comments9 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Create simple POS with React.js, Node.js, and MongoDB #7: Adding redux to other components
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    Create simple POS with React.js, Node.js, and MongoDB #7: Adding redux to other component. Blog
    Create simple POS with React.js, Node.js, and MongoDB #7: Adding redux to other component

    Defenition: POS – “Point of Sale”. At the point of sale, the merchant calculates the amount owed by the customer, indicates that amount, may prepare an invoice for the customer (which may be a cash register printout), and indicates the options for the customer to make payment.

    In the previous part of this tutorial series, we learned how to install the redux configuration into our project. We also got an insight on how to integrate redux to our login component. This tutorial part serves as a continuation of the previous tutorial.

    In this tutorial part, we are going to integrate the redux to Register and Forget password component.

    Register Component

    First, we are going to start with the Register component. The process is the same as that in the Login component. We are going to configure, constants, and reducers into the Register component.

    In index.js, we define states for register fetching, success, failed as shown in the code snippet below:

    //Forgot password
    export const FORGOT_FETCHING = "FORGOT_FETCHING"
    export const FORGOT_SUCCESS = "FORGOT_SUCCESS";
    export const FORGOT_FAILED = "FORGOT_FAILED";

    Then, we create a new redux action named register.action.js and the imports as follows:

    import {
      REGISTER_FETCHING,
      REGISTER_FAILED,
      REGISTER_SUCCESS,
      server,
    } from "../constants";
    import swal from "sweetalert";
    import { httpClient } from "./../utils/HttpClient";

    Next, we are going to create the functions that handle the state changes based on the type of register as shown in the code snippet below:

    export const setRegisterStateToFetching = () => ({
      type: REGISTER_FETCHING,
    });
    export const setRegisterStateToFailed = () => ({
      type: REGISTER_FAILED,
    });
    export const setRegisterStateToSuccess = (payload) => ({
      type: REGISTER_SUCCESS,
      payload,
    });

    Now, we go to the register function register in the Register component and attach the dispatch function in order to capture the events. The coding implementation of the function is shown in the code snippet below:

    export const register = (values, history) => {
      return async (dispatch) => {
        dispatch(setRegisterStateToFetching());
        const response = await httpClient.post(
          process.env.REACT_APP_API_URL + "register",
          values
        );
        if (response.data.result == "success") {
          dispatch(setRegisterStateToSuccess(response.data));
          swal("Success!", response.data.message, "warning").then((value) => {
            history.push("/login");
          });
        } else if (response.data.result === "error") {
            dispatch(setRegisterStateToFailed())
        swal("Error!", response.data.message, "error");
        }
      };
    };

    Now, we are going to create the reducer for the register component.

    For reducer, we need to create a new file name register.reducer.js. Then, we need to import new state constants and define the initial state as shown in the code snippet below:

    import {
      REGISTER_FETCHING,
      REGISTER_FAILED,
      REGISTER_SUCCESS,
    } from "../constants";
    const initialState = {
      isFetching: false,
      isError: false,
      result: null,
    };

    The next step is to create a function that will set the value of states based on the register type. The coding implementation of the required function is provided in the code snippet below:

    export default (state = initialState, { type, payload }) => {
      switch (type) {
        case REGISTER_FETCHING:
          return { ...state, isFetching: true, isError: false, result: null };
        case REGISTER_FAILED:
          return { ...state, isFetching: false, isError: true, result: null };
        case REGISTER_SUCCESS:
          return { ...state, isFetching: false, isError: false, result: payload };
        default:
          return state;
      }
    };

    Now in order to activate new reducer, we need to add the reducer file to index file as shown in the code snippet below:

    import { combineReducers } from "redux";
    import loginReducer from "./login.reducer";
    import registerReducer from "./register.reducer";
    export default combineReducers({
      loginReducer,
      registerReducer,
    });

    Now, it is time to add the reducer to the register component. The process is the same as that in login component in which we change the class component to functional component.

    Read More:  Web Development Newsletters: JavaScript, React, Vue, Angular Email Newsletters

    In component/register.js file, we need to import actions and react-redux plugin as shown in the code snippet below:

    import * as registerActions from "./../../actions/register.action";
    import { useSelector, useDispatch } from "react-redux";

    Then, we need to change the class component to the functional component and initialize the dispatch function as shown in the code snippet below:

    export default (props) => {
      const dispatch = useDispatch();

    Now, in order to use the register function, we replace the old function with register action that we imported from actions. We integrate the dispatch function with register action as a parameter as shown in the code snippet below:

                  onSubmit={(values, { setSubmitting }) => {
                    dispatch(registerActions.register(values, props.history));
                    setSubmitting(false);
                  }}

    Hence, we have successfully completed the integration of redux functionality in the Register component of our POS system project.

    Thus, we can check out the test result in the simulation below:

    POS. Rigister componenet with Redux
    POS. Rigister componenet with Redux

    As our redux integration in the Register component is complete, We move on to our Forgot password component.

    Forgot Password Component

    In this part, we are going to integrate the redux mechanism to the forgot and reset password component. The process to similar to that of the register component that we completed above.

    Just as in Register component, we define the state constants first as shown in the code snippet below:

    //Forgot password
    export const FORGOT_FETCHING = "FORGOT_FETCHING";
    export const FORGOT_SUCCESS = "FORGOT_SUCCESS";
    export const FORGOT_FAILED = "FORGOT_FAILED";

    Then, we need to create a new action called forgotpassword action and make the necessary imports. We also need to define the functions that handle state changes. Lastly, we need to define the resetpassword function with dispatch function as shown in the code snippet below:

    import { FORGOT_FETCHING, FORGOT_SUCCESS, FORGOT_FAILED } from "../constants";
    import swal from "sweetalert";
    import { httpClient } from "./../utils/HttpClient";
    export const setForgotStateToFetching = () => ({
      type: FORGOT_FETCHING,
    });
    export const setForgotStateToFailed = () => ({
      type: FORGOT_SUCCESS,
    });
    export const setForgotStateToSuccess = (payload) => ({
      type: FORGOT_FAILED,
      payload,
    });
    export const resetpassword = (values, history, token) => {
      return async (dispatch) => {
        dispatch(setForgotStateToFetching());
        const response = await httpClient.put(
          process.env.REACT_APP_API_URL + "password/reset?token=" + token,
          values
        );
        if (response.data.result === "success") {
          dispatch(setForgotStateToSuccess(response.data));
          swal("Success!", response.data.message, "success").then((value) => {
            history.push("/login");
          });
        } else if (response.data.result === "error") {
          dispatch(setForgotStateToFailed());
          swal("Error!", response.data.message, "error");
        }
      };
    };

    Now, it is time to add the reducer to the Forgot Password component. First, we need to import new state constants and define the initial state.

    Then, we need to create a function that will set the value of states based on forgot state types. The coding implementation of the required function is provided in the code snippet below:

    import { FORGOT_FETCHING, FORGOT_SUCCESS, FORGOT_FAILED } from "../constants";
    const initialState = {
      isFetching: false,
      isError: false,
      result: null,
    };
    export default (state = initialState, { type, payload }) => {
      switch (type) {
        case FORGOT_FETCHING:
          return { ...state, isFetching: true, isError: false, result: null };
        case FORGOT_FAILED:
          return { ...state, isFetching: false, isError: true, result: null };
        case FORGOT_SUCCESS:
          return { ...state, isFetching: false, isError: false, result: payload };
        default:
          return state;
      }
    };

    Now, we integrate the forgot password reducer in the index file by importing it as shown in the code snippet below:

    import { combineReducers } from "redux";
    import loginReducer from "./login.reducer";
    import registerReducer from "./register.reducer";
    import forgotpasswordReducer from "./forgotpassword.reducer";
    export default combineReducers({
      loginReducer,
      registerReducer,
      forgotpasswordReducer
    });

    Then, we need to go to the Forgot password component and modify it to import actions and react-redux:

    import * as passwordForgotAction from "./../../actions/forgotpassword.action";
    import { useDispatch } from "react-redux";

    Then, we need to change the class component to the functional component and then initialize the dispatch function as shown in the code snippet below:

    export default (props) => {
      const dispatch = useDispatch();

    Next, we need to replace the old submit form code with action using dispatch function as shown in the code snippet below:

    onSubmit={(values, { setSubmitting }) => {
       dispatch(passwordForgotAction.forgotpassword(values, props.history));
                    setSubmitting(false);
            }}
       validationSchema={PasswordForgotSchema}
    >

    Hence, we will get the result as shown in the simulation below:

    Read More:  Creating Mock API using Mirage in a React application
    POS. Redux forgot password component
    POS. Redux forgot password component

    Reset password component

    Now in the Reset password component that appears after the Forgot password action, we will apply the same process.

    First, we create a new state constant

    //Reset password
    export const RESET_FETCHING = "RESET_FETCHING";
    export const RESET_SUCCESS = "RESET_SUCCESS";
    export const RESET_FAILED = "RESET_FAILED";

    Second, we are going to create the action file and implement state handler function and resetpassword function as shown in the code snippet below:

    import { RESET_FETCHING, RESET_SUCCESS, RESET_FAILED } from "../constants";
    import swal from "sweetalert";
    import { httpClient } from "./../utils/HttpClient";
    
    export const setResetStateToFetching = () => ({
      type: RESET_FETCHING,
    });
    
    export const setResetStateToFailed = () => ({
      type: RESET_SUCCESS,
    });
    
    export const setResetStateToSuccess = (payload) => ({
      type: RESET_FAILED,
      payload,
    });
    
    export const resetpassword = (values, history, token) => {
      return async (dispatch) => {
        dispatch(setResetStateToFetching());
        const response = await httpClient.put(
          process.env.REACT_APP_API_URL + "password/reset?token=" + token,
          values
        );
        if (response.data.result === "success") {
          dispatch(setResetStateToSuccess(response.data));
          swal("Success!", response.data.message, "success").then((value) => {
            history.push("/login");
          });
        } else if (response.data.result === "error") {
          dispatch(setResetStateToFailed());
          swal("Error!", response.data.message, "error");
        }
      };
    };

    Then, we need to create a new reducer file and make the following coding implementations:

    import { RESET_FETCHING, RESET_SUCCESS, RESET_FAILED } from "../constants";
    
    const initialState = {
      isFetching: false,
      isError: false,
      result: null,
    };
    
    export default (state = initialState, { type, payload }) => {
      switch (type) {
        case RESET_FETCHING:
          return { ...state, isFetching: true, isError: false, result: null };
        case RESET_FAILED:
          return { ...state, isFetching: false, isError: true, result: null };
        case RESET_SUCCESS:
          return { ...state, isFetching: false, isError: false, result: payload };
        default:
          return state;
      }
    };

    Lastly, we need to modify the password reset component the same as the password forgot. First, we need to import react-redux dependency and actions as well.

    import * as passwordReset from "./../../actions/resetpassword.action";
    import { useDispatch } from "react-redux";

    Then, we convert the component to the functional component and initialize dispatch function:

    export default (props) => {
      const dispatch = useDispatch();

    Then, we replace the old submit form code with the new action configuration with dispatch function as shown in the code snippet below:

    onSubmit={(values, { setSubmitting }) => {
                    dispatch(
                      passwordReset.resetpassword(
                        values,
                        props.history,
                        props.match.params["token"]
                      )
                    );
            setSubmitting(true);
    }}

    Hence, the result of the password reset test is shown in the simulation below:

    POS. Reset password component with Redux
    POS. Reset password component with Redux

    Finally, we have successfully completed the integration of the redux mechanism in both the Forgot Password and Reset Password component.

    Conclusion

    In this chapter, we learned how to integrate redux to Register, Forgot, and Reset password components. The process was the same as of that in the login component which we did in the previous chapter. Implementing the redux mechanism in different components will infuse deep knowledge and use the case of redux.

    In the next chapter, we will learn how to implement CRUD operation with redux by using crud POS machine data.

    Nonetheless, you can try out the live demo as well as get the code for this chapter in Github.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Krissanawat Kaewsanmuang
    • Website
    • X (Twitter)

    Developer Relation @instamobile.io

    Related Posts

    Streamlining Resource Allocation for Enhanced Project Success

    December 18, 2024

    Conducting Effective Post-Project Evaluations: A Guide

    December 16, 2024

    Strategies for Keeping Projects on Track and Meeting Deadlines

    December 10, 2024
    Leave A Reply Cancel Reply

    You must be logged in to post a comment.

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo
    Don't Miss
    Remote Job July 15, 2019

    Ultimate Onboarding Checklist for Web Developers (Bonus: Onboarding Checklist for Freelancers)

    In this piece, we’ll define the term onboarding, describe the process of onboarding for developers, and share a sample onboarding checklist for developers and remote employees or those both if you happen to hire remote developers.

    24. Уроки Node.js. Чтение параметров из командной строки и окружения.

    November 18, 2016

    Уроки React . Урок 10.

    October 27, 2016

    Performance Optimizations for React Native Applications

    August 6, 2020

    Categories

    • AI & Automation
    • Angular
    • ASP.NET
    • AWS
    • B2B Leads
    • Beginners
    • Blogs
    • Business Growth
    • Case Studies
    • Comics
    • Consultation
    • Content & Leadership
    • CSS
    • Development
    • Django
    • E-commerce & Retail
    • Entrepreneurs
    • Entrepreneurship
    • Events
    • Express.js
    • Facebook Ads
    • Finance & Fintech
    • Flask
    • Flutter
    • Franchising
    • Funnel Strategy
    • Git
    • GraphQL
    • Home Services Marketing
    • Influencer & Community
    • Interview
    • Java
    • Java Spring
    • JavaScript
    • Job
    • Laravel
    • Lead Generation
    • Legal & Compliance
    • LinkedIn
    • Machine Learning
    • Marketing Trends
    • Medical Marketing
    • MSP Lead Generation
    • MSP Marketing
    • NestJS
    • Next.js
    • Node.js
    • Node.js Lessons
    • Paid Advertising
    • PHP
    • Podcasts
    • POS Tutorial
    • Programming
    • Programming
    • Python
    • React
    • React Lessons
    • React Native
    • React Native Lessons
    • Recruitment
    • Remote Job
    • SaaS & Tech
    • SEO & Analytics
    • Soshace
    • Startups
    • Swarm Intelligence
    • Tips
    • Trends
    • Vue
    • Wiki
    • WordPress
    Top Posts

    Create simple POS with React, Node and MongoDB #2: Auth state, Logout, Update Profile

    JavaScript January 22, 2020

    Enhancing Interview Success: The Critical Role of Confidence

    Interview December 6, 2024

    React Lesson 15: Checking Homework progress from Lesson 14

    JavaScript July 29, 2020

    Effective Strategies for Recruiting Remote Work Talent

    Recruitment December 1, 2024

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    About Us
    About Us

    Soshace Digital delivers comprehensive web design and development solutions tailored to your business objectives. Your website will be meticulously designed and developed by our team of seasoned professionals, who combine creative expertise with technical excellence to transform your vision into a high-impact, user-centric digital experience that elevates your brand and drives measurable results.

    7901 4th St N, Suite 28690
    Saint Petersburg, FL 33702-4305
    Phone: 1(877)SOSHACE

    Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
    Our Picks
    Remote Job

    SMART Financial Goals for Remote Workers

    LinkedIn

    Strategic LinkedIn Branding: A Key to Effective Lead Generation

    Beginners

    Upload Multiple Images to a Django Model without plugins

    Most Popular

    Growth Hacking 101: Everything You Always Wanted to Know with Examples | 2019

    JavaScript

    React Lesson 11. Pt.1: Normalize Comments with Immutable.js

    JavaScript

    TOP SQL & Database Courses [Plus a List of Free SQL Courses]

    Beginners
    © 2025 Soshace Digital.
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.