checks
This commit is contained in:
parent
baf11f19d6
commit
e9eb2e9ab6
1 changed files with 7 additions and 1 deletions
|
@ -13,17 +13,23 @@ function ChangeUsername(): JSX.Element {
|
||||||
const handleSubmit = async (): Promise<void> => {
|
const handleSubmit = async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
// Call the API function to change the username
|
// Call the API function to change the username
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
const token = localStorage.getItem("accessToken");
|
||||||
|
if (!token) {
|
||||||
|
throw new Error("Access token not found");
|
||||||
|
}
|
||||||
|
|
||||||
const response = await api.changeUserName(
|
const response = await api.changeUserName(
|
||||||
{ prevName: "currentName", newName: newUsername },
|
{ prevName: "currentName", newName: newUsername },
|
||||||
token,
|
token,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
// Optionally, add a success message or redirect the user
|
// Optionally, add a success message or redirect the user
|
||||||
console.log("Username changed successfully");
|
console.log("Username changed successfully");
|
||||||
} else {
|
} else {
|
||||||
// Handle the error message
|
// Handle the error message
|
||||||
console.error("Failed to change username:", response.message);
|
console.error("Failed to change username:", response.message);
|
||||||
|
setErrorMessage(response.message ?? "Failed to change username");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error changing username:", error);
|
console.error("Error changing username:", error);
|
||||||
|
|
Loading…
Reference in a new issue