Pass URL parameters into the 3rd page of the funnel

We have a optin page in clickfunnels where we collect user email address & name. This information is passed into the 2nd page of the funnel through URL parameters when the user submits. Like “mydomain.com/secondpage?cf_uvid=d1def16b1797acafa8c76348cc250104”, here the parameter is “?cf_uvid=d1def16b1797acafa8c76348cc250104”.

There’s a button on the second page only which sends the user to the 3rd page of the funnel. But unfortunately, the parameters don’t get passed onto the 3rd page. I need a script or a button code that’ll collect the parameters and send it to the 3rd page when someone clicks on it.

Thanks in advance.

React: Why the count values are different in useEffect and inc event handler?

In the below code snippet, the component is rendered thrice when user clicks on the button but the count values remain the same.

import React, { useEffect } from 'react';

const wait = () =>
  new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve();
    }, 2000);
  });

export default function App() {
  const [count, setCount] = React.useState(0);

  useEffect(() => {
    console.log('rerendered');
    console.log(count);
  });

  const inc = async () => {
    setCount(count + 1);
    setCount(count + 5);

    await wait();

    console.log(count);
    setCount(count + 1);
    console.log(count);
    setCount(count + 2);
    console.log(count);
  };

  return (
    <div>
      <h1>{count}</h1>
      <button onClick={inc}>Increment</button>
    </div>
  );
}

I know that first two setCount() are batched and after await they are not batched. If I use setCount(prev => prev +1), I will get the updated values but my question is

Why are the count values different in inc() and useEffect()? When does the count value actually changes coz certainly not on re-render?

TypeError: Cannot read properties of undefined (reading ‘catch’)

I am trying to get channel with an id or mention, the code itself works but when user gives wrong ID it says: TypeError: Cannot read properties of undefined (reading ‘catch’)

Can anyone help me?

I tried this:

message.guild.channels.cache.find(channel => channel.id == args[0]).catch(err => {});

And this:

message.guild.channels.cache.get(args[0]).catch(err => {});

These both things give me error.

Heres the code:

if (args[0].startsWith("<#")) channel = message.mentions.channels.first();
        else channel = message.guild.channels.cache.get(args[0]).catch(err => {
    //do stuff
    })
    

OnChange not working for dropdown & radioButton

I am trying to build the signup form. I have created the onChange fn to store the values( credentials) in a state. All the textfield values are stored correctly but the selected dropdown value and radiobutton value is not getting reflected when I console the state value.

Here credentials = {
name: texfield,
email: texfield,
password: texfield,
confmpassword: texfield,
role: radiobutton,
forgetQues: dropdown,
forgetAns: texfield,
}

Below is the code

import React, { useState } from "react";
import { useNavigate } from "react-router-dom";

const SignupPage = () => {
  const navigate = useNavigate();

  const goToLogin = () => {
    navigate("/login");
  };

  const [credentials, setCredentials] = useState({
    name: "",
    email: "",
    password: "",
    confmpassword: "",
    role: "",
    forgetQues: "",
    forgetAns: "",
  });

  const onChange = (e, key) => {
    setCredentials((prevCredentials) => ({
      ...prevCredentials,
      [key]: e.target.value,
    }));
    //console.log(credentials);
  };

  return (
    <>
      <div className="container my-3">
        <div id="loginbody">
          <div className="mt-3">
            <h2 className="my-3 display-3">Create your account here </h2>
            <form className="login-form p-5">
              <div className="mb-3">
                <label htmlFor="name" className="form-label">
                  Name
                </label>
                <input
                  type="text"
                  className="form-control"
                  id="name"
                  name="name"
                  value={credentials.name}
                  onChange={(e) => onChange(e, "name")}
                  aria-describedby="emailHelp"
                />
              </div>

              <div className="mb-3">
                <label htmlFor="email" className="form-label">
                  Email{" "}
                </label>
                <input
                  type="email"
                  className="form-control"
                  id="email"
                  name="email"
                  value={credentials.email}
                  onChange={(e) => onChange(e, "email")}
                  aria-describedby="emailHelp"
                />
              </div>

              <div className="mb-3">
                <label htmlFor="password" className="form-label">
                  Password
                </label>
                <input
                  type="password"
                  className="form-control"
                  id="password"
                  name="password"
                  minLength={5}
                  value={credentials.password}
                  onChange={(e) => onChange(e, "password")}
                  required
                />
              </div>
              <div className="mb-3">
                <label htmlFor="confmpassword" className="form-label">
                  Confirm Password
                </label>
                <input
                  type="password"
                  className="form-control"
                  id="confmpassword"
                  name="confmpassword"
                  value={credentials.confmpassword}
                  onChange={(e) => onChange(e, "confmpassword")}
                  minLength={5}
                  required
                />
              </div>

              {/* ------see here----------------- */}

              <div className="mb-3 col-md">
                <label htmlFor="role" className="form-label">
                  <strong>Role</strong>
                </label>
                <div className="form-check form-check-inline mx-4">
                  <input
                    className="form-check-input"
                    type="radio"
                    name="roleOptions"
                    id="role1"
                    value={credentials.role}
                    onSelect={(e) => console.log(e)}
                  />
                  <label className="form-check-label" htmlFor="role1">
                    Admin
                  </label>
                </div>
                <div className="form-check form-check-inline">
                  <input
                    className="form-check-input"
                    type="radio"
                    name="roleOptions"
                    id="role2"
                    value={credentials.role}
                    onChange={(e) => onChange(e, "role")}
                  />
                  <label className="form-check-label" htmlFor="role2">
                    Client
                  </label>
                </div>
                <div className="form-check form-check-inline">
                  <input
                    className="form-check-input"
                    type="radio"
                    name="roleOptions"
                    id="role3"
                    value={credentials.role}
                    onChange={(e) => onChange(e, "role")}
                  />
                  <label className="form-check-label" htmlFor="role3">
                    Guest
                  </label>
                </div>
              </div>



              <div className="mb-3 row">
                <div className="form-floating col-6">
                  <select
                    className="form-select"
                    id="forgetQues"
                    name="forgetQues"
                    value={credentials.forgetQues}
                    aria-label="Floating label select example"
                    onChange={(e) => onChange(e, "forgetQues")}
                    required
                  >
                    <option>Open this select menu</option>
                    <option value={credentials.forgetQues} >Favourite Sport</option>
                    <option value={credentials.forgetQues} >Favourite Food</option>
                    <option value={credentials.forgetQues} >Favourite City To Visit</option>
                  </select>
                  <label htmlFor="forgetQues">Select Question</label>
                </div>

                {/* -------------upto here---------- */}


                <div className="col-6">
                  <div className="form-floating mb-3">
                    <input
                      type="email"
                      className="form-control"
                      id="forgetAns"
                      name="forgetAns"
                      value={credentials.forgetAns}
                      onChange={(e) => onChange(e, 'forgetAns')}
                    />
                    <label htmlFor="forgetAns">Answer</label>
                  </div>
                </div>
              </div>

              <div className="d-grid gap-2 my-4 col-6 mx-auto">
                <button type="submit" className="btn btn-success ">
                  SignUp
                </button>
              </div>
              <hr />
              <div className="mb-3 text-center">
                <div id="emailHelp" className="form-text center my-3">
                  Already have an account ?
                </div>
                <div className="d-grid gap-2 my-3 col-6 mx-auto">
                  <button onClick={goToLogin} className="btn btn-success ">
                    Login
                  </button>
                </div>
              </div>
            </form>
          </div>
        </div>
      </div>
    </>
  );
};

export default SignupPage;

I am solving this error for last one hour but it is not getting resolved. Can I get help?

javascript innerHTML is working because i can see it in my developer’s tools console log but its not rendering the items on my screen

  • List item

    const textBox = document.getElementsByClassName(“container1”)
    const button = document.getElementsByClassName(“submit”)
    const textInput = document.getElementsByClassName(“textinput”)
    let items = [“yam”, “apple”, “veggies”, “milk”]
    console.log(textInput)
    /this section below is just to render out the items in the items arrays on my screen/
    for(let i = 0;i<items.length;i++){
    textBox.innerHTML += <p>${items[i]}</p>
    textBox.textContent += items[i]
    console.log(textBox.innerHTML)
    }

InvalidOperationException: JavaScript interop calls when using onclick AuthenticationStateProvider

I am doing a semester project with my group (https://github.com/Tymon2115/ABDOT), and right now I am trying to create login functionality in blazor.

The problem I have is that when I log in i get correctly authorized, but I would like to get the returned User ID so I can load user’s profile page and so on, but I get that exception.

Code:

<NotAuthorized>
        <h3>Login</h3>
        <div class="form-group">
            <p>@confirmationMessage</p>
            <input type="text" placeholder="e-mail" @bind-value="email"/>
        </div>
        <div class="form-group">
            <input type="password" placeholder="password" @bind-value="password"/>
        </div>
        <div style="color:red">@errorMessage</div>
        <p class="actions">
            <button class="btn-outline-dark" @onclick="PerformLogin">Login</button>
            <button class="btn-outline-dark" @onclick="Cancel">Cancel</button>
        </p>
    </NotAuthorized>
@code{
public async Task PerformLogin()
    {
        errorMessage = " ";
        Console.WriteLine("logging in");

        try {
            User returnedUser = await ((CustomAuthenticationStateProvider) AuthenticationStateProvider).ValidateLogin(email, password);
            email = "";
            password = "";
            Id = returnedUser.Id;

        }
        catch (Exception e) {
            Console.WriteLine(e);
            errorMessage = e.Message;
            throw;
        }
            
            Console.WriteLine("Success");
        
        
    }
}
public class CustomAuthenticationStateProvider : AuthenticationStateProvider {
        private readonly IJSRuntime jsRuntime;
        private readonly IUserService userService;
        private User cachedUser;

        public CustomAuthenticationStateProvider(IJSRuntime jsRuntime, IUserService userService)
        {
            this.jsRuntime = jsRuntime;
            this.userService = userService;
        }
        

        public override async Task<AuthenticationState> GetAuthenticationStateAsync()
        {
            var identity = new ClaimsIdentity();
            if (cachedUser == null)
            {
                string userAsJson = await jsRuntime.InvokeAsync<string>("sessionStorage.getItem", "currentUser");
                if (!string.IsNullOrEmpty(userAsJson))
                {
                    cachedUser = JsonSerializer.Deserialize<User>(userAsJson);
                    identity = SetupClaimsForUser(cachedUser);
                }
            }
            else
            {
                identity = SetupClaimsForUser(cachedUser);
            }

            ClaimsPrincipal cachedClaimsPrincipal = new ClaimsPrincipal(identity);
            return await Task.FromResult(new AuthenticationState(cachedClaimsPrincipal));
        }

        public async Task<User> ValidateLogin(string username, string password)
        {
            Console.WriteLine("Validating log in");
            if (string.IsNullOrEmpty(username)) throw new Exception("Enter username");
            if (string.IsNullOrEmpty(password)) throw new Exception("Enter password");
            ClaimsIdentity identity = new ClaimsIdentity();
            try
            {
                User user = await userService.ValidateUser(username, password);
                identity = SetupClaimsForUser(user);
                string serialisedData = JsonSerializer.Serialize(user);
                await jsRuntime.InvokeVoidAsync("sessionStorage.setItem", "currentUser", serialisedData);
                cachedUser = user;
            }
            catch (Exception e)
            {
                throw e;
            }

            NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(new ClaimsPrincipal(identity))));
            return cachedUser;
        }

        public async Task Logout()
        {
            cachedUser = null;
            var user = new ClaimsPrincipal(new ClaimsIdentity());
            await jsRuntime.InvokeVoidAsync("sessionStorage.setItem", "currentUser", "");
            NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(user)));
        }
        
        private ClaimsIdentity SetupClaimsForUser(User user)
        {
            List<Claim> claims = new List<Claim>();
            ClaimsIdentity identity = new ClaimsIdentity(claims, "apiauth_type");
            return identity;
        }
}

How to check is html element is deleted in php?

I have some page with same html elements:

<form action="" method="post" id="form" class="form">
    <div id="div3">
    <input type="hidden" name="3" id="3" hidden="true" value="27">
    <input type="text" name="task3" id="task3" class="task input" placeholder="Enter Task" required="required" value="SOME VALUE">
    <input class="input hover-to-show" type="button" name="removetask3" id="removetask3" value="Remove" onclick="remove(3)">
    </div> //'3' is an id of the element

    <input style="position: fixed; right: 0;" name="done" type="submit" value="Save" />
</form>

And there is a script remove(j):

function remove(j) {
    id--;
    let element = document.getElementById("div" + j);
    let input = document.getElementById("task"+j);
    input.setAttribute("value", " ");
    element.parentNode.removeChild(element);
}

And then i have php code with SQL statements:

if(isset($_POST["done"])){
    for($i = 1; $i < $count; $i++){
            if(htmlspecialchars(trim($_POST["task".$i])))
            {
                $index = $_POST[$i];
                $task = htmlspecialchars(trim($_POST["task".$i]));
                $imp = htmlspecialchars(trim($_POST["mark".$i]));
                mysqli_query($db, "UPDATE `data` SET `tasks`='$task',`imp`= '{$imp}' WHERE `id` = {$index} AND `customerid`={$id}");
                if($i > $rnum){
                    mysqli_query($db, "INSERT INTO `data` (`customerid`, `tasks`, `imp`) VALUES ({$id}, '{$task}', {$imp})");
                }
            }
            else{
                mysqli_query($db, "DELETE FROM `data` WHERE customerid={$id} AND id={$_POST[$i]}");
            }
        }
}

But

if(htmlspecialchars(trim($_POST["task".$i]))) {} is true for the deleted index

What is a possible solution to check, is element deleted or not?

How to change sytle properties of an element in JavaScript?

I am making a small online app that will require the user to input some options and the site will change it’s background and similar features based on their input.
However, I have not been able to change any of the document style properties through JavaScript code.

Am I missing something?

let bgType = prompt("Which type of background do you want? Color or image: ");

if (bgType == "color" || bgType == "Color") {
    let colBg = prompt("Enter the color you want");
    document.getElementById("background").style.backgroundColor = colBg; // I've tried putting default colors here for testing, but those didn't work either
} else if (bgType == "image" || bgType == "Image") {
    let imgBg = prompt("Enter the number of the image you want (1-3): ");
    document.getElementById("background").style.backgroundColor = ""; // Unfinished
}

In case it’s needed here is also the HTML and CSS code
HTML:

<!DOCTYPE html>
<html>
    <head>
        <meta charset='utf-8'>
        <meta http-equiv='X-UA-Compatible' content='IE=edge'>
        <title>Greeting card generator</title>
        <meta name='viewport' content='width=device-width, initial-scale=1'>
        <link rel='stylesheet' type='text/css' media='screen' href='gfx.css'>
    </head>
    <body>
        <script src='script.js'></script>
        <div id="background" class="content">
            <!-- <img src="Temp1.jpg" alt="Greeting card image"> -->
            <h1 id="Title" class="text">
                Sample title text
            </h1>
            <h2 id="Name" class="text">
                Sample name text
            </h2>
            <h3 id="Message" class="text">
                Sample message text
            </h3>
        </div>
    </body>
</html>

CSS:

html, body {
    height: 100%;
    margin: 0;
}

#background {
    width: 100%;
    min-height: 100%;
    background-image: url();
    background-color: white;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.text {
    font-family: verdana;
    text-align: center;
}

#Title {
    padding-top: 20%;
}

Error: Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime

when I start my react project in Fedora 32 using command yarn start, shows error like this:

./src/style/base.scss (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-5-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--6-oneOf-5-3!./node_modules/sass-loader/dist/cjs.js??ref--6-oneOf-5-4!./src/style/base.scss)
Error: Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime (93)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v4.14.1

my current node version is:

[dolphin@MiWiFi-R4CM-srv]~/Documents/GitHub/react-admin% nvm list
        v8.17.0
       v10.24.1
->     v16.13.0
        v17.2.0
         system
default -> 8 (-> v8.17.0)

I have tried different version of node but did not fix this problem, why did this happen? what should I do to fix this problem? I did not found any package dependencies of node sass in the package.json, this is the package.json file:

{
    "name": "react-admin",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "@ant-design/compatible": "1.0.8",
        "animate.css": "^3.7.2",
        "antd": "^4.0.0",
        "axios": "^0.19.0",
        "braft-editor": "^2.3.8",
        "echarts": "^4.4.0",
        "is-core-module": "2.2.0",
        "moment": "2.29.1",
        "nprogress": "^0.2.0",
        "react": "^17.0.2",
        "react-dom": "^17.0.2",
        "react-highlight-words": "0.17.0",
        "react-loadable": "^5.5.0",
        "react-redux": "^7.1.1",
        "react-router-dom": "^5.1.1",
        "react-scripts": "^3.2.0",
        "redux": "^4.0.4",
        "redux-logger": "3.0.6",
        "redux-promise-middleware": "^6.1.2",
        "redux-thunk": "^2.3.0",
        "screenfull": "^5.0.0"
    },
    "scripts": {
        "start": "react-app-rewired start",
        "build": "CI=false && react-app-rewired build",
        "test": "react-app-rewired test",
        "eject": "react-scripts eject"
    },
    "eslintConfig": {
        "extends": "react-app"
    },
    "browserslist": {
        "production": [
            ">0.2%",
            "not dead",
            "not op_mini all"
        ],
        "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version"
        ]
    },
    "husky": {
        "hooks": {
            "pre-commit": "lint-staged"
        }
    },
    "lint-staged": {
        "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
            "node_modules/.bin/prettier --write",
            "git add"
        ],
        "src/**/*.{css,scss,less,json,html,md,markdown}": [
            "node_modules/.bin/prettier --write",
            "git add"
        ]
    },
    "devDependencies": {
        "@babel/helper-builder-react-jsx": "^7.12.13",
        "babel-plugin-import": "^1.12.2",
        "customize-cra": "^0.8.0",
        "husky": "^3.0.9",
        "lint-staged": "^9.4.2",
        "sass": "1.37.0",
        "prettier": "^1.18.2",
        "react-app-rewired": "^2.1.4"
    }
}

React Force horizontal scrolling as vertical scroll when reaching element view

I’ve been trying to achieve this effect of default horizontal scrolling when reaching element’s view.
I still could not find some decent way to implement it correctly, for now I was only able to achieve it with pure CSS (the problem is – it doesn’t scrolled horizontal correctly, I need to click on the element so it will be aware I’m in the right view.
This is my code for now –

::-webkit-scrollbar {
      width: 1px;
      height: 1px;
    }

    ::-webkit-scrollbar-button {
      width: 1px;
      height: 1px;
    }


    .test {
      position: absolute;
      display: block;
      top: 0;
      left: 0;
      width: calc(250px + 1px);
      max-height: 750px;
      margin: 0;
      padding-top: 1px;
      background: #abc;
      overflow-y: auto;
      overflow-x: hidden;
      transform: rotate(-90deg) translateY(-250px);
      transform-origin: right top;
      padding: 250px 0 0 0;
    }

    .test div {
      display: block;
      padding: 5px;
      background: #cab;
      transform: rotate(90deg);
      transform-origin: right top;
      width: 250px;
      height: 250px;
      margin: 10px 0;
    }
<div class="test">
      <div>div</div>
      <div>div</div>
      <div>div</div>
      <div>div</div>
      <div>div</div>
      <div>div</div>
      <div>div</div>
      <div>div</div>
    </div>

I’d love to know if there is any way to make the scrolling automatically start horizontally as I reach the view, and if that’s not possible I’d love to know how would you implement it with JS in React.
Thank you!

event not firing after some clicks

i don’t understand after certain clicks add element is not firing , it just stops, my count variables are working fine but don’t know what seems to be the issue here,

 $(document).on('click','.add-role-btn',function(e){
                    console.log('working')
                    if (add_count < 3){
                        $('.role-name-container').append(
                            $('<input type="text" name="role_name" class="form-control mt-3" placeholder="Role name">')
                        )
                     }
                     add_count += 1;
                    
    
                })

            $(document).on('click','.delete-role-btn',function(e){
                console.log('working')
                let last_elem = $('.role-name-container').children().last();
                
                if ($('.role-name-container').first().not(last_elem))
                {
                    last_elem.remove()
                }
                add_count -= 1;

               
                
            })

Take a screenshot of a new tab using Puppeteer

I’m using puppeteer to click on a link that opens a new tab, and take a screenshot of this tab using :

const pages = await browser.pages()
const new_page = pages[pages.length-1]
await new_page.screenshot()

but I made some research and I found that browser.pages() contains only the default blank pages and my current tab but not the new one.

Hence, when I take a screenshot, it takes a screenshot of the current tab.
To give you some context, the new tab is a PHP url and it display a pdf file. I tried waitForNavigation, bringToFront and nearly every possible console.log().

Does anyone know how to help me ?

How to change property with a condition inside React.useState()

I have a component that uses React.useState to keep a property named available
and what I want to do is to change its value to true with a conditional statement, so that my component gets rendered based on that condition, but I can’t set up a conditional statement inside React.useState. I tried changing it in my other component with a conditional statement:

  const [isUserLogged] = React.useState(true);
  const arrowDir = props['data-expanded']
    ? 'k-i-arrow-chevron-down'
    : 'k-i-arrow-chevron-right';

  if (isUserLogged === true) {
    props.available === true;
  }

But that didn’t work too. How can I achieve this with a conditional statement? Here is my entire code:

import * as React from 'react';
import { withRouter } from 'react-router-dom';
import {
  Drawer,
  DrawerContent,
  DrawerItem,
} from '@progress/kendo-react-layout';
import { Button } from '@progress/kendo-react-buttons';

const CustomItem = (props) => {
  const { visible, ...others } = props;
  const [isUserLogged] = React.useState(true);
  const arrowDir = props['data-expanded']
    ? 'k-i-arrow-chevron-down'
    : 'k-i-arrow-chevron-right';

  if (isUserLogged === true) {
    props.available === true;
  }

  return (
    <React.Fragment>
      {props.available === false ? null : (
        <DrawerItem {...others}>
          <span className={'k-icon ' + props.icon} />
          <span className={'k-item-text'}>{props.text}</span>
          {props['data-expanded'] !== undefined && (
            <span
              className={'k-icon ' + arrowDir}
              style={{
                position: 'absolute',
                right: 10,
              }}
            />
          )}
        </DrawerItem>
      )}
    </React.Fragment>
  );
};

const DrawerContainer = (props) => {
  const [drawerExpanded, setDrawerExpanded] = React.useState(true);
  const [isUserLogged] = React.useState(true);

  const [items, setItems] = React.useState([
    {
      text: 'Education',
      icon: 'k-i-pencil',
      id: 1,
      selected: true,
      route: '/',
    },
    {
      separator: true,
    },
    {
      text: 'Food',
      icon: 'k-i-heart',
      id: 2,
      ['data-expanded']: true,
      route: '/food',
    },
    {
      text: 'Japanese Food',
      icon: 'k-i-minus',
      id: 4,
      parentId: 2,
      route: '/food/japanese',
    },
    {
      text: 'Secret Food',
      icon: 'k-i-minus',
      id: 5,
      parentId: 2,
      route: '/food/italian',
      available: false,
    },
    {
      separator: true,
    },
    {
      text: 'Travel',
      icon: 'k-i-globe-outline',
      ['data-expanded']: true,
      id: 3,
      route: '/travel',
    },
    {
      text: 'Europe',
      icon: 'k-i-minus',
      id: 6,
      parentId: 3,
      route: '/travel/europe',
    },
    {
      text: 'North America',
      icon: 'k-i-minus',
      id: 7,
      parentId: 3,
      route: '/travel/america',
    },
  ]);

  const handleClick = () => {
    setDrawerExpanded(!drawerExpanded);
  };

  const onSelect = (ev) => {
    const currentItem = ev.itemTarget.props;
    const isParent = currentItem['data-expanded'] !== undefined;
    const nextExpanded = !currentItem['data-expanded'];
    const newData = items.map((item) => {
      const {
        selected,
        ['data-expanded']: currentExpanded,
        id,
        ...others
      } = item;
      const isCurrentItem = currentItem.id === id;
      return {
        selected: isCurrentItem,
        ['data-expanded']:
          isCurrentItem && isParent ? nextExpanded : currentExpanded,
        id,
        ...others,
      };
    });
    props.history.push(ev.itemTarget.props.route);
    setItems(newData);
  };

  const data = items.map((item) => {
    const { parentId, ...others } = item;

    if (parentId !== undefined) {
      const parent = items.find((parent) => parent.id === parentId);
      return { ...others, visible: parent['data-expanded'] };
    }

    return item;
  });
  return (
    <div>
      <div className="custom-toolbar">
        <Button icon="menu" look="flat" onClick={handleClick} />
        <span className="title">Categories</span>
      </div>
      <Drawer
        expanded={drawerExpanded}
        mode="push"
        width={180}
        items={data}
        item={CustomItem}
        onSelect={onSelect}
      >
        <DrawerContent>{props.children}</DrawerContent>
      </Drawer>
    </div>
  );
};

export default withRouter(DrawerContainer);