Skip to content

Commit

Permalink
refactor: assign correct serverparks based on role, before sending to…
Browse files Browse the repository at this point in the history
… server
  • Loading branch information
kristian4res committed Nov 4, 2024
1 parent 54e8685 commit b72e261
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/ClientConfig.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export interface ClientConfig {
DefaultServerPark: string;
RoleToServerParksMap: { [key: string]: string[] } ;
}
import role_to_serverparks_map_json from "./role-to-serverparks-map.json";

export function loadConfigFromEnv(): ClientConfig {
const roleToServerParksMap: { [key: string]: string[] } = role_to_serverparks_map_json;
return {
DefaultServerPark: "gusty",
RoleToServerParksMap: roleToServerParksMap
};
}
6 changes: 4 additions & 2 deletions src/pages/users/UserUpload/NewUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ function NewUserComponent(): ReactElement {
const [message, setMessage] = useState<string>("");
const [redirect, setRedirect] = useState<boolean>(false);
const [roleList, setRoleList] = useState<UserRole[]>([]);
const cconfig = loadConfigFromEnv();
const config = loadConfigFromEnv();

async function createNewUser(formData: UserForm) {
setUsername(formData.username);
if (formData.username && formData.password) {
const newUser: NewUser = {
name: formData.username.trim(),
password: formData.password.trim(),
role: role
role: role,
defaultServerPark: config.DefaultServerPark,
serverParks: config.RoleToServerParksMap[role]
};
setButtonLoading(true);
const created = await addNewUser(newUser);
Expand Down

0 comments on commit b72e261

Please sign in to comment.