GithubHelp home page GithubHelp logo

hermawangan / fe-test Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 164 KB

A simple login and fetch user, post and comments

Home Page: https://userloginpage1.netlify.app/

HTML 6.54% CSS 21.16% JavaScript 72.30%
html javascript react react-pagination redux tailwindcss

fe-test's Introduction

Front-End Test

This is a solution to the Front-end Test.

Table of contents

Overview

The challenge

Users should be able to:

  • View the optimal layout for the site depending on their device's screen size
  • See hover states for all interactive elements on the page
  • Login if the username and password are correct

My process

Built with

Code

  {success ? (
        <Dashboard />
      ) : (
        <div className="form-container">
          <form onSubmit={handlerForm} className="form">
            <h2 className="form-title">Login Page</h2>
            <div className="input-container">
              <input
                id="username"
                className="input"
                type="text"
                placeholder="username"
                value={user.username}
                onChange={controlFormUsername}
              />
              <input
                id="password"
                className="input"
                type="password"
                placeholder="password"
                value={user.password}
                onChange={controlFormPassword}
              />
              <button className="input button">Login </button>
            </div>
          </form>
        </div>
      )}

The Code above shows that if success is true it will render a new component called Dashboard and vice-versa. Variable Success wil only became true if users input the username and password correctly. else variable success wil never be true

export const fetchPost = () => {
  return (dispatch) => {
    dispatch(fetchPostReq);
    axios
      .get("https://jsonplaceholder.typicode.com/posts")
      .then((response) => {
        const post = response.data;
        dispatch(fetchPostSuccess(post));
      })
      .catch((error) => {
        const errorMsg = error.message;
        dispatch(fetchPostFail(errorMsg));
      });
  };
};

The code above wil fetch the post data. before fetching i created a fetchPostReq, fetchPostSuccess and fetchPostFail action builder. it then will tell to the reducer function based on the fetching data. first it will tell to the reducer when fetching the data. after fetching, the outcomes will be resolved or rejected. if it is resolved the the fetchPostSuccess will take a parameter data and pass it to the reducer function as action.payload. the same case as rejected.

const mapStateToProps = (state) => {
  return {
    id: state.id.id,
  };
};

const mapDispatchToState = (dispatch) => {
  return {
    userId: (id) => dispatch(userId(id)),
  };
};

export default connect(mapStateToProps, mapDispatchToState)(LoginForm);

Code above is a react-redux code concept basically is to connect redux state to react component. mapStateToProps function will take state as a parameter and wil return state. The code above mapStateToProps return a state called id. mapDispatchToState is a function that takes in dispatch and returning an action function called userId. The above code mapDispatchToState return an userId and takes in id as a parameter. the name for both function could be name anything but this is name that used by everyone. and connect method is actually to connect both function to the react components as a props.

Useful resources

  • Create Pagination in React APp - I able to create a pagination in this challenge by looking and reading the documentation in that website. -React-Redux - I learn to implement redux in React is from watching and learning in this channel.

Author

fe-test's People

Contributors

hermawangan avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.