One edit user button per user

This commit is contained in:
Narek Amirbekian
2022-02-11 10:50:58 -08:00
parent 25ea559e0d
commit a5e3b66dee
2 changed files with 42 additions and 32 deletions

View File

@@ -10,6 +10,14 @@ import "./server-dashboard.css";
import { timeSince } from "../../util/timeSince";
import PaginationFooter from "../PaginationFooter/PaginationFooter";
const AccessServerButton = ({ userName, serverName }) => (
<a href={`/user/${userName}/${serverName || ""}`}>
<button className="btn btn-primary btn-xs" style={{ marginRight: 20 }}>
Access Server
</button>
</a>
);
const ServerDashboard = (props) => {
// sort methods
var usernameDesc = (e) => e.sort((a, b) => (a.name > b.name ? 1 : -1)),
@@ -145,6 +153,29 @@ const ServerDashboard = (props) => {
);
};
const EditUserCell = ({ user, numServers, serverName }) => {
if (serverName) return null;
return (
<td rowspan={numServers}>
<button
className="btn btn-primary btn-xs"
style={{ marginRight: 20 }}
onClick={() =>
history.push({
pathname: "/edit-user",
state: {
username: user.name,
has_admin: user.admin,
},
})
}
>
Edit User
</button>
</td>
);
};
return (
<div className="container" data-testid="container">
{errorAlert != null ? (
@@ -354,18 +385,10 @@ const ServerDashboard = (props) => {
serverName={server.name}
userName={e.name}
/>
<a
href={`/user/${e.name}${
server && server.name && "/" + server.name
}`}
>
<button
className="btn btn-primary btn-xs"
style={{ marginRight: 20 }}
>
Access Server
</button>
</a>
<AccessServerButton
serverName={server.name}
userName={e.name}
/>
</>
) : (
// Start Single-user server
@@ -383,30 +406,17 @@ const ServerDashboard = (props) => {
className="btn btn-secondary btn-xs"
style={{ marginRight: 20 }}
>
Spawn New
Spawn Page
</button>
</a>
</>
)}
</td>
<td>
{/* Edit User */}
<button
className="btn btn-primary btn-xs"
style={{ marginRight: 20 }}
onClick={() =>
history.push({
pathname: "/edit-user",
state: {
username: e.name,
has_admin: e.admin,
},
})
}
>
edit user
</button>
</td>
<EditUserCell
user={e}
numServers={userServers.length}
serverName={server.name}
/>
</tr>
);
});

File diff suppressed because one or more lines are too long