Can now change username in this modal + moved some stuff to a separate modal
This commit is contained in:
parent
9b0a231701
commit
3981190c7a
1 changed files with 52 additions and 21 deletions
|
@ -1,34 +1,38 @@
|
||||||
import { Link } from "react-router-dom";
|
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
import DeleteUser from "./DeleteUser";
|
import DeleteUser from "./DeleteUser";
|
||||||
import UserProjectListAdmin from "./UserProjectListAdmin";
|
import UserProjectListAdmin from "./UserProjectListAdmin";
|
||||||
|
import { useState } from "react";
|
||||||
|
import InputField from "./InputField";
|
||||||
|
import ChangeUsername from "./ChangeUsername";
|
||||||
|
import { StrNameChange } from "../Types/goTypes";
|
||||||
|
|
||||||
function UserInfoModal(props: {
|
function UserInfoModal(props: {
|
||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
manageMember: boolean;
|
|
||||||
username: string;
|
username: string;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onDelete: (username: string) => void;
|
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
if (!props.isVisible) return <></>;
|
const [showInput, setShowInput] = useState(false);
|
||||||
const ManageUserOrMember = (check: boolean): JSX.Element => {
|
const [newUsername, setNewUsername] = useState("");
|
||||||
if (check) {
|
if (!props.isVisible) {
|
||||||
return (
|
return <></>;
|
||||||
<Link to="/AdminChangeRole">
|
}
|
||||||
<p className="mb-[20px] hover:font-bold hover:cursor-pointer underline">
|
|
||||||
(Change Role)
|
const handleChangeNameView = (): void => {
|
||||||
</p>
|
if (showInput) {
|
||||||
</Link>
|
setShowInput(false);
|
||||||
);
|
} else {
|
||||||
|
setShowInput(true);
|
||||||
}
|
}
|
||||||
return (
|
|
||||||
<Link to="/AdminChangeUserName">
|
|
||||||
<p className="mb-[20px] hover:font-bold hover:cursor-pointer underline">
|
|
||||||
(Change Username)
|
|
||||||
</p>
|
|
||||||
</Link>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleClickChangeName = (): void => {
|
||||||
|
const nameChange: StrNameChange = {
|
||||||
|
prevName: props.username,
|
||||||
|
newName: newUsername,
|
||||||
|
};
|
||||||
|
ChangeUsername({ nameChange: nameChange });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="fixed inset-0 bg-black bg-opacity-30 backdrop-blur-sm
|
className="fixed inset-0 bg-black bg-opacity-30 backdrop-blur-sm
|
||||||
|
@ -36,7 +40,32 @@ function UserInfoModal(props: {
|
||||||
>
|
>
|
||||||
<div className="border-4 border-black bg-white p-2 rounded-lg text-center flex flex-col">
|
<div className="border-4 border-black bg-white p-2 rounded-lg text-center flex flex-col">
|
||||||
<p className="font-bold text-[30px]">{props.username}</p>
|
<p className="font-bold text-[30px]">{props.username}</p>
|
||||||
{ManageUserOrMember(props.manageMember)}
|
<p
|
||||||
|
className="mb-[20px] hover:font-bold hover:cursor-pointer underline"
|
||||||
|
onClick={handleChangeNameView}
|
||||||
|
>
|
||||||
|
(Change Username)
|
||||||
|
</p>
|
||||||
|
{showInput && (
|
||||||
|
<div className="border-2 border-black rounded-lg p-2">
|
||||||
|
<InputField
|
||||||
|
label={"New username"}
|
||||||
|
type={"text"}
|
||||||
|
value={newUsername}
|
||||||
|
onChange={function (e): void {
|
||||||
|
e.defaultPrevented;
|
||||||
|
setNewUsername(e.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
text={"Change"}
|
||||||
|
onClick={function (): void {
|
||||||
|
handleClickChangeName();
|
||||||
|
}}
|
||||||
|
type={"submit"}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div>
|
<div>
|
||||||
<h2 className="font-bold text-[22px] mb-[20px]">
|
<h2 className="font-bold text-[22px] mb-[20px]">
|
||||||
Member of these projects:
|
Member of these projects:
|
||||||
|
@ -62,6 +91,8 @@ function UserInfoModal(props: {
|
||||||
<Button
|
<Button
|
||||||
text={"Close"}
|
text={"Close"}
|
||||||
onClick={function (): void {
|
onClick={function (): void {
|
||||||
|
setNewUsername("");
|
||||||
|
setShowInput(false);
|
||||||
props.onClose();
|
props.onClose();
|
||||||
}}
|
}}
|
||||||
type="button"
|
type="button"
|
||||||
|
|
Loading…
Reference in a new issue