import React from "react"; import Router from "next/router"; import NavBar from…
- User
import React from "react"; import Router from "next/router"; import NavBar from "../components/NavBar";
import dashboardStyles from "../../styles/Dashboard.module.scss"; import bodyStyles from "../../styles/Home.module.scss"; import { Form, Button, Card } from "react-bootstrap"; import { useEffect } from "react"; import { useState } from "react"; import Authority from "../../helpers/Authority";
import { pinFileToIPFS } from "../../helpers/uploadIpfs";
import axios from "axios";
function NewFundRequest() { const authority = new Authority(); const [account, setAccount] = useState(""); const [amount, setAmount] = useState(""); const [toAddr, setToAddr] = useState(""); const [description, setDescription] = useState("");
const [nationalOfficers, setNationalOfficers] = useState([]);
const [isSubmitting, setIsSubmitting] = useState(false);
const [file, setFile] = useState(null); const [fileUrl, setFileUrl] = useState(null);
useEffect(() => { //fetch account address and populate the your address field window.ethereum.enable().then((myAccount) => setAccount(myAccount[0]));
codeaxios .get(`${process.env.NEXT_PUBLIC_API_URL}/api/fetch-national-officers/`) .then((response) => setNationalOfficers(response.data.data)) .catch((err) => console.log(err));}, []);
function onChange(e) { const file = e.target.files[0]; setFile(file); }
async function onUpload(e) { /* upload image to IPFS */ // const file = e.target.files[0] try { const url = await pinFileToIPFS(file);
code// const url = `https://ipfs.infura.io/ipfs/${added.path}` console.log(url, " fileURL"); setFileUrl(url); console.log(url, " URL"); alert(`fileURL: ${url}`); } catch (error) { <inputs type="file" name="Asset" className="my-4" onChange={onChange} />; console.log("Error uploading file: ", error); }}
const onSubmit = async (e) => { e.preventDefault(); if (!toAddr) { toAddr = "0x598518be171D592b24041e92324988035C9429F5"; } alert(toAddr) // await onUpload(); // description = description.concat(
\nSupporting Documents Link: ${fileUrl}); // const res = await authority.requestFunds(amount, toAddr, description); // console.log(amount, toAddr, description); // alert(res); // setAmount(""); // setToAddr(""); // setDescription(""); // Router.push("/dashboard"); }; - Assistant
It seems that you are displaying the correct values (officer.fname and officer.lname) as the text for the option elements, but you are not correctly setting the value attribute for each option. The value attribute should be set to officer.accid, which can be done in the following way:
Change this line:
javascript<option key={officer.accid} value={officer.accid}>to this:
javascript<option key={officer.accid} value={officer.accid}>This should ensure that the selected value for the toAddr field will be the officer's accid as intended.