React responsive nav component es6 function not firing

I’m not quite sure why the click event is not working.
I simply trying the use a responsive accessible navigation but looks like I’m missing something in the constructor or I’m not firing the function properly?
I have the feeling that my es6 constructor is not right.
Please let me know if you could help me

import React, { Component} from "react";
import {hot} from "react-hot-loader";
import { Link } from "react-router-dom";

import "../styles/navbar.scss"
import cart from '../assets/images/cart.png'


class NavBar extends Component{

  constructor(props){
    super(props);
    this.responsiveNav = this.responsiveNav.bind(this);
  
  }
responsiveNav(){
  const primaryNav = document.querySelector(".nav-items");
  const navToggle = document.querySelector(".mobile-nav-toggle");
  
  navToggle.addEventListener("click", () => {
    console.log('click')
    const visibility = primaryNav.getAttribute("data-visible");
  
    if (visibility === "false") {
      primaryNav.setAttribute("data-visible", true);
      navToggle.setAttribute("aria-expanded", true);
    } else if (visibility === "true") {
      primaryNav.setAttribute("data-visible", false);
      navToggle.setAttribute("aria-expanded", false);
    }
  });
  
  }

 

  render(){
    return(
      <div id={this.props.id} className="navbar">
        

        <button  className="mobile-nav-toggle" aria-controls="nav-items" aria-expanded="false">
        <span className="sr-only">Menu</span>
        </button>
        <nav className="nav">
          <div className="nav-menu flex-row">
            <div className="nav-brand">
                <h2><Link to="/">APP</Link></h2>
            </div>

            <ul className="menu" data-visible="false" className="primary-nav flex">
                <li>
                  <Link to="/">Products</Link>
                </li>
                <li>
                  <Link to="/">News</Link>
                </li>
                <li>
                  <Link to="/">Content</Link>
                </li>
                <li>
                  <Link to="/cart"><img src={cart} alt="cart icon"/><div id="yourcart">Your Cart</div></Link>
                </li>
              </ul>
          </div>
        </nav>
      </div>
    );
  }
} 

export default hot(module)(NavBar);

yarn start not working | error `ERR_PACKAGE_PATH_NOT_EXPORTED’

I have been trying to make this React App, but when I try to do yarn start it shows the following error message:

yarn run v1.22.17
$ react-scripts start
node:internal/modules/cjs/loader:488
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/tokenize' is not defined by "exports" in /home/abhishek/Documents/Code/weather-react/weather-react/node_modules/postcss-safe-parser/node_modules/postcss/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:429:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:683:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/abhishek/Documents/Code/weather-react/weather-react/node_modules/postcss-safe-parser/lib/safe-parser.js:1:17) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v17.2.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

How do I fix this?

I am fairly new to JS and React, so forgive me if this is a dumb question.

Thank you 🙂

How to manage dynamic form data using useState?

I have a form that gets it’s input fields dynamically, it can have hundreds of fields so i can’t create a state individually, I was planning on doing something like using an object using the unique key of a form field but need some help.

Suppose the form has fields like this.

<form>
 {inputFields.map((i) => {
    <input type={i.type} />
  })}
</form>

Now i would need a state like the one below

 inputState = {
  "INPUT_FIELD_NAME1": "INPUT FIELD VALUE 1",
  "INPUT_FIELD_NAME2": "INPUT FIELD VALUE 2",
  "INPUT_FIELD_NAME3": "INPUT FIELD VALUE 3",
}

I need help with this, how do i set values in such a manner in my input onChange and how do i access the values from the state and use them for the matching input field?

how to close the dropdown menus when I clicked outside the box in JavaScript?

here is my HTML code.

<body>
  <section class="section">
      <div class="container"></div>
      <button class="account-avatar">DK</button>
      <div class="box hidden container-fluid">
        <div class="row">
          <div class="name col-12">NAME</div>
        </div>
        <div class="row">
          <div class="account col-12">My Account</div>
        </div>
        <div class="row">
          <div class="logout col-12">Logout</div>
        </div>
      </div>

      <div class="container h-100">
        <div class="row justify-content-center align-items-center h-100">
          <div class="container">
            <div class="row">
              <div class="col-12">
                <div class="row justify-content-center">
                  <div class="col-lg-1 col-sm-3 p-0">
                    <div class="selector">
                      <div class="dropdown">
                        <button class="dropbtn py-3">
                          Dropdown<i
                            class="fas fa-chevron-down"
                            style="font-size: 10px; margin-left: 7px"
                          ></i>
                        </button>
                        <div class="dropdown-content hidden">
                          <a href="#">Link 1</a>
                          <a href="#">Link 2</a>
                          <a href="#">Link 3</a>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="col-5 p-0">
                    <div class="search-bar">
                      <input
                        type="text"
                        id="arama"
                        class="px-5"
                        placeholder="Search.."
                      />
                      <label id="icerik"></label>
                    </div>
                    <div class="search-bar_content hidden">
                      <a href="#"
                        ><strong>
                          HOST INFORMATİON HADKJAKDJLKAJDKLAJLKSDJKLSAJD
                        </strong></a
                      >
                      <a href="#">Ip</a>
                      <a href="#">Link 3</a>
                      <a href="#"><strong> HOST OPERATING SYSTEM </strong></a>
                      <a href="#">Link 2</a>
                      <a href="#">Link 3</a>
                    </div>
                  </div>
                  <div class="col-lg-1 col-sm-3 p-0">
                    <div class="btn-search_container">
                      <button class="btn-search">
                        <!-- Search --><i
                          class="fas fa-search"
                          style="font-size: 20px; margin-left: -65px"
                        ></i>
                      </button>
                    </div>
                  </div>
                  <div class="col-12">
                    <div class="row">
                      <div class="col-12 text-center mt-5">
                        <p class="display-4">
                          Lorem ipsum dolor sit amet, consectetur adipiscing
                          elit
                        </p>
                      </div>
                    </div>
                  </div>
                  <div class="col-12 mt-5">
                    <div class="row justify-content-center text-center">
                      <div class="col-lg-3 col-md-5">
                        <button class="btn btn-outline-primary p-3 w-100">
                          View Documentation
                        </button>
                      </div>
                      <div class="col-lg-3 col-md-5 mt-5 mt-md-0">
                        <button class="btn btn-primary p-3 w-100">
          
              Something
                      </button>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>
</body>

And I want to dropdowns close when I clicked “section” part or anywhere except dropdown button or search-bar part.
When I clicked section part it takes all the elements it contains and then dropdown buttons never open.

And here is my JavaScript code:

"use strict";

let btnAvatar = document.querySelector(".account-avatar");
let box = document.querySelector(".box");
let section = document.querySelector(".section");
let btnDrop = document.querySelector(".dropbtn");
let dropDownContent = document.querySelector(".dropdown-content");
let searchBar = document.querySelector(".search-bar");
let searchBarContent = document.querySelector(".search-bar_content");
let overlay = document.querySelector(".overlay");

btnAvatar.addEventListener("click", function () {
  box.classList.toggle("hidden");
});

btnDrop.addEventListener("click", function () {
  dropDownContent.classList.toggle("hidden");
  searchBarContent.classList.add("hidden");
});

searchBar.addEventListener("click", function () {
  searchBarContent.classList.toggle("hidden");
  dropDownContent.classList.add("hidden");
});

section.addEventListener("click", function () {
  searchBarContent.classList.add("hidden");
  dropDownContent.classList.add("hidden");
});

dummy text : Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus at lectus orci. Quisque maximus hendrerit consequat. Donec blandit facilisis est. Integer ac massa vitae ante vulputate sagittis nec at nisl. Cras sit amet sem nec metus sodales eleifend a ac nulla. Duis porta nisl in erat aliquet hendrerit. Integer mollis non odio et pellentesque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse cursus fringilla sem, facilisis malesuada orci varius in. Nullam tristique nisi sed sem mattis, a finibus magna mollis. Fusce erat sem, semper ac vulputate sit amet, imperdiet sagittis ex

Master reset filter

I have the variations displayed on the product archive page. This works well. However, when is used together with sorting function, it doesn’t work.

The reset button shows even when no variables is selected. When the reset button is clicked, it doesn’t reset anything, it added a “#” to the slug /?orderby=date#. When the sorting function is activated, the variable value is not clickable nor accepted.

Added an image for illustration purpose

I’ve also explored several plugins but none of them is able to resolve this issue. Not sure if my thought process is correct, I wonder if there is a way to have a master reset to clear all filters on the product archive page?

Can I create an array of constructor call functions and call them?

I have inherited a code with a lot of duplication, basically I have 4 different types and for all of them I have to do the same actions. I have managed to refactor most of my code and got stuck to mapping part. Basically, I need to take each object, map it to its corresponding type and save it to a corresponding array. I wanted to put all my constructor calls for each type in an array, iterate over that array and return a function in which I can pass some parameters.

something like this:

    arrayOfArraysToStoreValues = [frstArray, secondArray, thirdArray]

    getGoodConstructor(index, firstParam, secondParam) {
       const arrayOfConstructors = [ new typeOne(firstParam, secondParam), new 
       typeTwo(firstParam, secondParam), new TypeThree(firstParam, secondParam)]
       return arrayOfConstructors[index] 
    }

and I wanted to iterate over it inside my forEach loop

arrayOfArraysToStoreValues[index].push(getGoodConstrucor(index, firstParam, secondParam))

But when I try to do it like this I have an error:

Argument of type ‘type1 | type3 | Type3’ is not assignable to parameter of type ‘Type1 & Type2 & Type3’.
(notice difference between | and & )

Can I do something like this? Is there any other solution that might help me refactor and avoid duplication?
Thank you

ReferenceError: localStorage is not defined at Object

I am using local storage to save the updatet variable value every time I run my test case but fore some reasons I get the error:

ReferenceError: localStorage is not defined at Object ReferenceError:
localStorage is not defined at Object.
(/app/Projects/Javascript/Mocha/27403_9907/Libraries/addNewBeneficiary.js:17:49)
at Module._compile (internal/modules/cjs/loader.js:1085:14) at
Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32) at
Function.Module._load (internal/modules/cjs/loader.js:790:12) at
Module.require (internal/modules/cjs/loader.js:974:19) at require
(internal/modules/cjs/helpers.js:93:18) at Object.
(/app/Projects/Javascript/Mocha/27403_9907/run/test.js:13:39) at
Module._compile (internal/modules/cjs/loader.js:1085:14) at
Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32) at
Function.Module._load (internal/modules/cjs/loader.js:790:12) at
ModuleWrap. (internal/modules/esm/translators.js:199:29) at
ModuleJob.run (internal/modules/esm/module_job.js:183:25) at async
Loader.import (internal/modules/esm/loader.js:178:24) at async
formattedImport
(/usr/lib/node_modules/mocha/lib/nodejs/esm-utils.js:7:14) at async
Object.exports.requireOrImport
(/usr/lib/node_modules/mocha/lib/nodejs/esm-utils.js:48:32) at async
Object.exports.loadFilesAsync
(/usr/lib/node_modules/mocha/lib/nodejs/esm-utils.js:88:20) at async
singleRun (/usr/lib/node_modules/mocha/lib/cli/run-helpers.js:125:3)
at async Object.exports.handler
(/usr/lib/node_modules/mocha/lib/cli/run.js:374:5)

I have created a JS file and uploaded it in a customized platform called Momentum, which we use for automated test. the code file is as following:

const { wd } = require("../setup/v2setup");

                    var isStepFailed = false;

                    var assert = require('assert');
                    var should = require('should');
                    var windowSize = null;
                    const axios = require('axios').default;

let storedXPathIndex = localStorage.getItem("storedXPathIndex");
                    let xPathIndex = (storedXPathIndex) ? ++storedXPathIndex : 0;
                    localStorage.setItem("storedXPathIndex", xPathIndex);
                    const max = 5;

                    exports.setAddNewBeneficiaryMethods = (driver) =>{

wd.addPromiseChainMethod('SelectAcc', () => {


                    
   if( ++xPathIndex > max ) xPathIndex = 0;
    return 

driver.swipeUntilElement("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.ScrollView/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup["+ xPathIndex +"]")
})
}

wating for response from consumer in rabitmq and nodejs

I have two project with nodejs and typescript and a want to start comunication with rabitmq .

i install amqplib library from npm and use this config for published and subscriber project :

import amqp from ‘amqplib’;

export class MessageBroker {

    private static channel: amqp.Channel;

    public static async Initial(exchange: string, queue: string) {

        let cluster = await amqp.connect('amqps://mcbzjnsn:0hHb-M1u_XwvuyYch3fM9vJOQUaVBmPQ@cow.rmq2.cloudamqp.com/mcbzjnsn');
        let channel = await cluster.createChannel();

        await channel.assertExchange(exchange, 'direct', { durable: true, autoDelete: true });

        await channel.assertQueue(queue + '.' + exchange, {
            exclusive: true
        });

        await channel.bindQueue(queue + '.' + exchange, exchange, queue);

        channel.prefetch(1);

        this.channel = channel;

    }

    //Random id generator
    private static randomid() {
        return new Date().getTime().toString() + Math.random().toString() + Math.random().toString();
    }
    static async Publish(exchange: string, queue: string, message: any): Promise<void> {

        let id = this.randomid();

        MessageBroker.channel.sendToQueue(exchange, queue,
            Buffer.from(JSON.stringify(message)), { correlationId: id, replyTo: 'amq.rabbitmq.reply-to' })

    }

    static async SendToQueue(queue: string, message: any): Promise<void> {

        let id = this.randomid();

        MessageBroker.channel.sendToQueue(queue, Buffer.from('10'), {
            correlationId: id,
            replyTo: queue
        });
    }

    private static async Consume(exchange: string, queue: string): Promise<void> {



    }


}

now i want to use send message from project A to Project B with this code :

await MessageBroker.Publish('coin', 'transaction',{
            type:MessageBrokerType.Transfer,
            to:'0x36f5C37B48c7888634b9285ae30eeACa5AD427C0',
            amount:100
        });

and I need wait to projectB response but it does not wait for response from projectB and go the next line.

now, how can I do it? ( wait for response from the result of project B )

Re-use email of deleted Apple ID

I have an old Apple ID, is created by email “x” and I deleted it over 2 months ago.

Now, I want to re-use the email “x” to set for my current Apple ID.

But, they said that, this email is used, although it was deleted.

Can I re-use it one more time ? Do I have any mistakes ? Thanks all.

Script error when Transform PO to Item Receipt Error

I’m new to suitescript, I’ve got a schedule script to Transform a PO to Item Receipt. Which needs to create a record on Subrecord on inventorydetail sub record, I get “USER_ERROR”,”message”:”The total inventory detail quantity must be 1.” – Not sure what I have done wrong. If i use the same code for a non stock and remove the sub record insert line and coding it works

   var csvPOId = 73586;
        var csvPOLocationId = 1;
        var csvPOQty = 1;
        var csvBinId = '';
        var csvSerialLot = '';
        var csvInvQty = 1;
        //

        try {
            var itemReceiptRec = record.transform({
                fromType: record.Type.PURCHASE_ORDER,
                fromId: csvPOId,
                toType: record.Type.ITEM_RECEIPT,
                isDynamic: false
            });
        } catch (e) {
            log.error({
                title: e.name,
                details: e.message
            });
        }


        // Get count - Sublist Lines
        var count = itemReceiptRec.getLineCount({
            sublistId: 'item'
        });

        for (var i=0; i < count; i++) {

            // Item Sub List - Mark as Received
            var itemReceived = itemReceiptRec.getSublistValue({
                sublistId: 'item',
                fieldId: 'itemreceive',
                line: i
            });

            // Location
            itemReceiptRec.setSublistValue({
                sublistId: 'item',
                fieldId: 'location',
                value: csvPOLocationId, // '11 - Central Main Warehouse',
                line: i
            });
            // Quantity

            itemReceiptRec.setSublistValue({
                sublistId: 'item',
                fieldId: 'quantity',
                value: csvPOQty,
                line: i
            });

            // Inventory Detail Sub Record [inventorydetail]

            var subrec = itemReceiptRec.getSublistSubrecord({
                sublistId: 'item',
                line: i,
                fieldId: 'inventorydetail'
            });
            subrec.insertLine({
                sublistId: 'inventoryassignment',
                line: 0
            });
            // // Quantity - Mandatory
            subrec.setSublistValue({
                sublistId: 'inventoryassignment',
                fieldId: 'quantity',
                line: 0,
                value: csvInvQty
            });
        var itemRecID = itemReceiptRec.save({
            enableSourceing: true
        });

        log.debug({
            title: 'New Item Receipt Record',
            details: 'Internal ID ' + itemRecID
        });

Javascript onclick how to undo when clicked again

I’m creating a filter to search for your perfect shoe’s by answering questions. Right now I’ve got a couple of questions, each with multiple answers. By clicking on an answer a variable gets edited with the data of the value of that answer. The problemm is that you can click on the variable as many times as you like and the value will keep being added. Is there a way to change the color of the answer button when clicked and when clicked again it undo’s adding the value to the variable and changes the color back?

Code:

<div class="container">
    <div id="question"></div>
    <div id="answer"></div>
    <button onclick="check()" id="nextbtn">Next</button>
    <div id="finalLink"></div>      
</div>
<script type="text/javascript">

    var ShoeTest = [
        [
            'Whats your size?',
            ['41', '41'],
            ['42', '42'],
            ['43', '43']
        ],
        [
            'What color would you like?',
            ['Red', 'red'],
            ['Blue', 'blue'],
            ['Yellow', 'yellow'],
            ['Green', 'green']
        ],
        [
            'What brand would you like?',
            ['Adidas', 'adidas'],
            ['Nike', 'nike'],
            ['Puma', 'puma']
        ]
    ];

    let parms = [];

    count = 1;
    var questionNumber = 0;
    var button = document.getElementById('answer');
    var question = document.getElementById('question');
    var answerButton;
    var flag = true;

    function getLink(parms) {
        return ""+parms.join("&")
      };

      button.addEventListener("click",function(e) {
        const tgt = e.target;
        parms.push(tgt.value);
        console.log(getLink(parms))
      })

    function check(){
        oldAnswerButton = document.querySelectorAll('.filter_anwser');
        oldQuestion = document.getElementById('question');
        for(let z = 0; z < oldAnswerButton.length; z++){
            oldAnswerButton[z].style.display = 'none';
        }
        //question 
        for (let y = 1; y < ShoeTest[questionNumber].length; y++){
            // button
            var btn = document.createElement('button');
            btn.value = ShoeTest[questionNumber][y][1];
            btn.className = "filter_anwser";
            btn.textContent = ShoeTest[questionNumber][y][0];
            btn.setAttribute('data-el', 1);
            btn.onclick = ButtonColor();
            button.appendChild(btn);
            // class
            answerButton = document.querySelectorAll('.filter_anwser');
        }
        // question
        question.textContent = ShoeTest[questionNumber][0];
        question.id = "questionID";
                
        console.log(".....");
        // adds 1 to question to see a different question
        questionNumber++;
    }

    function ButtonColor(){
        btn = document.getElementById('answer');
        btn.style.backgroundcolor = flag ? "unclicked" : "clicked"
       flag = !flag;
    }

Also if you have multiple answers of one questions add a , between instead of a &?

Failure to get response from POST jQeury [duplicate]

So I got a quick script working with HTML and JS, but I can’t for the love of me get the response from the POST request. Here is what I have currently have:

<!DOCTYPE html>
<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button onclick="something()">Click Me!</button>
<script>
function something(){
  const Url = 'https://somelink.com';
  const date = 'somedata'
  var V
  
  $.post(Url,date,function(data) {
  V = data
  });
  
  alert(V)
}
</script>
</body>
</html>

I did try having the alert in the function(data) part but it would not register for some exact reason so I moved it out. Now it registers the alert but it can not get the response from the request.

I am testing it in JS Fiddle and the console log is “50:9 Uncaught ReferenceError: V is not defined”. Any and all help/nudges will be greatly appreciated. My goal is to get the response from the request and use it further down the line, so I am just testing as a proof of concept/correct coding with the alert.