Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
JavaScript
export default function UserProfile(props) {
  const { isLoggedIn, user, profile  } = useSelector((state) => state.AuthReducer);
  const { wallet, paired_curency_price, coins, wallet_loading } = useSelector(
    (state) => state.coinDBReducer
  );
  const dispatch = useDispatch();
  const [loading, setLoading] = useState(true);
  const [hide, setHide] = useState(false);
  const [nodisplay, setDisplay] = useState(false);
  const [name, setName] = useState("");
  const [total_btc, setTotalBtc] = useState(0);
  const [total_usdt, setTotalUsdt] = useState(0);
  const updateProfile = (e) => {
    e.preventDefault();
    if (checkName(name)) {
      N_updateName(
        user?.params ? user.params.token: user.token,
        name
      ).then((res) => {
        if (res.status.matchedCount == 1) {
          setName("");
          setDisplay(!nodisplay);
          N_getProfile(user?.params ? user.params.token: user.token)
        .then((d) => {
          if (d.status === 200) {
            dispatch({type:'PROFILE', data:d?.params.profile_info})
          }
        })
        .catch((e) => {
          console.log(e);
        });
          NotificationManager.success("Updated Successfully");
        } else {
          NotificationManager.error(res.message);
        }
      });
    } else {
      NotificationManager.error("Enter valid nick Name");
    }
  };

  <main className="s-layout__content">
    <div className="container-fluid">
      <div className="account_page">
        <div className="col-lg-12">
          <div className="jambotron">
            <div className="horizontal_display_with_justify">
              <div className="flex_row">
                {" "}
                <div className="name_circle">
                  {profile?.name
                    ? profile?.name
                      ?.split("")
                      .slice(0, 2)
                      .join("")
                      .toUpperCase()
                    : profile?.email
                       ?.split("")
                       .slice(0, 2)
                       .join("")
                       .toUpperCase()}
                </div>
                {" "}
                {nodisplay 
                  ? <><span>Hello</span>
                    <div>
                      <input
                        className="editable-input-box"
                        type="text"
                        contentEditable={true}
                        value={name}
                        onChange={(e) => {
                          setName(e.target.value.replace("/a-zA-z*/i", ""));
                        }}
                      />
                    </div>
                    </>
                  : <div className="big_heading text-capitalize me-2 text-truncate mob_mw_150">
                      {" "}Hello,{" "}
                      {hide
                        ? "**********"
                        : profile?.name
                        ? profile.name
                        : profile?.email}{" "}
                    </div>}
                    <div>
                      {nodisplay ?
                        <>
                          <div className="d-flex gap-1">
                            <button
                              className="btn btn-pink btn-sm fs-14"
                              onClick={(e) => {
                                updateProfile(e);
                              }}
                            >
                              Update
                            </button>
                          </div>
                        </> : <></>  
                      }
                    </div>
                    <div>
                      <span
                        className="cursor_pointer"
                        onClick={() => {
                          setDisplay(!nodisplay);
                          setName(profile?.name)
                        }}
                      >


What I have tried:

In this code, inputfield shows the inputfield in when edit cursor shows inputfield. However, my question is when I click edit cursor, it does not show inputfield, only edit at the same place and click update button updates at the same place and edit at the same place, not open new input field. I click edit cursor, edit text does not show inputfield in the browser.
Posted
Updated 1-Oct-23 8:20am
v3

This is a very common, so there is lots of documentation, tutorials, and examples on this. Here is a Google search with many answers for you: react working with the input field - Google[^]

Here is the official documentation with examples: <input> – React[^]
 
Share this answer
 
Comments
[no name] 1-Oct-23 3:22am    
bro plese send solution in this code
Dave Kreskowiak 1-Oct-23 10:27am    
The only code you're ever going to get is the code YOU write. Dropping a bunch of code here and demanding people fix it for you teaches you nothing at all.
Quote:
bro plese send solution in this code

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Just dumping a pile of code on us and saying "fix this!" isn't going to get you anywhere.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
[no name] 1-Oct-23 3:27am    
at same code please answer me
Richard Deeming 2-Oct-23 4:32am    
You have had your answer, twice: nobody is going to write the code for you.

But by all means, keep demanding that someone else does your work for you and hands it to you on a plate. See how far that gets you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900