{"size": 1474, "ext": "js", "max_stars_repo_path": "src/components/demoAccountButton.js", "max_stars_repo_name": "KaterinaLupacheva/financial-manager", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/demoAccountButton.js", "max_issues_repo_name": "KaterinaLupacheva/financial-manager", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/demoAccountButton.js", "max_forks_repo_name": "KaterinaLupacheva/financial-manager", "max_forks_repo_forks_event_min_datetime": "2021-12-10T02:07:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-10T02:07:40.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 26.8, "max_line_length": 69, "alphanum_fraction": 0.5997286296}
import React, { useState, useContext } from "react";
import { Button } from "@material-ui/core";
import { makeStyles } from "@material-ui/core/styles";
import axios from "axios";
import SimpleBackdrop from "../components/simple-backdrop";
import UserContext from "../contexts/user.context";
import { doSignInWithEmailAndPassword } from "../firebase/firebase";
import { useHistory } from "react-router-dom";

const useStyles = makeStyles((theme) => ({
  margin: {
    margin: theme.spacing(5),
  },
}));

const DemoAccountButton = () => {
  const classes = useStyles();
  const history = useHistory();
  const { setUser } = useContext(UserContext);
  const [isLoading, setIsLoading] = useState(false);
  const [errors, setErrors] = useState({});

  const handleSubmit = (event) => {
    event.preventDefault();
    setIsLoading(true);
    doSignInWithEmailAndPassword("demo@demo.com", "111111")
      .then((data) => {
        setUser(data.user);
        setIsLoading(false);
        history.push("/month");
      })
      .catch((err) => {
        setErrors(err);
        setIsLoading(false);
      });
  };

  return (
    <>
      <Button
        variant="contained"
        color="secondary"
        size="large"
        className={classes.margin}
        onClick={handleSubmit}
      >
        Demo account
      </Button>
      <SimpleBackdrop open={isLoading} />
    </>
  );
};

export default DemoAccountButton;
