Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/admin user name change functionality #2840

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions packages/main/src/components/user-name/UserName.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
import React from "react";
import axios from "axios";
import React, { useState, useEffect } from "react";
import styles from "../user-name/SettingsTab.module.css";

const UserName = () => {
const [userName, setUserName] = useState("");
const [user, setUser] = useState(null);

let organization_id = JSON.parse(sessionStorage.organisations)[0].id;
let user_member_id = JSON.parse(sessionStorage.organisations)[0].member_id;

useEffect(() => {
const user = JSON.parse(sessionStorage.getItem("user"));
if (user) {
setUser(user);
}
}, []);

const updateUserName = event => {
event.preventDefault();
axios
.patch(
`https://api.zuri.chat/organizations/${organization_id}/members/${user_member_id}/profile`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the base url constant provided in the app
it should be coming from @zuri-utilities

{
display_name: userName
},

{
headers: {
Authorization: "Bearer " + user.token
}
}
)
.then(res => console.log(res))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you chaining a .then if you do not intend to use the response?

.catch(error => console.log(error.response));
Comment on lines +34 to +35
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console.log and console.error. Use toast to show notifications.

};

return (
<div className={styles.passwordsection}>
<form className="row d-flex flex-column">
<form
className="row d-flex flex-column"
onSubmit={e => {
updateUserName(e);
}}
>
<div className="col-md-5 mt-2">
<input type="text" className="form-control" required />
<input
type="text"
placeholder="New Username"
className="form-control"
onChange={e => setUserName(e.target.value)}
required
/>
</div>
<div className="col-md-4 mb-3 mt-3">
<button className="btn">Save</button>
Expand Down