Skip to content

Commit

Permalink
Delete user (#576)
Browse files Browse the repository at this point in the history
* Connect UserManagement in frontend to delete(userId) in the backend.
* Consolidate general purpose button text translations.
  • Loading branch information
imnasnainaec authored Aug 5, 2020
1 parent 5985272 commit 62666a7
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 92 deletions.
7 changes: 7 additions & 0 deletions src/backend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ export async function updateUser(user: User): Promise<User> {
return { ...user, id: resp.data };
}

export async function deleteUser(userId: string): Promise<string> {
let resp = await backendServer.delete(`users/${userId}`, {
headers: authHeader(),
});
return resp.data;
}

export async function createProject(project: Project): Promise<Project> {
let resp = await backendServer.post(`projects/`, project, {
headers: authHeader(),
Expand Down
2 changes: 1 addition & 1 deletion src/components/DataEntry/DataEntryTable/DataEntryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export class DataEntryTable extends React.Component<
this.props.displaySemanticDomainView(true);
}}
>
<Translate id="addWords.done" />
<Translate id="buttons.complete" />
</Button>
</Grid>
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProjectSettings/ProjectName/ProjectName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ProjectName extends React.Component<
}
onClick={() => this.updateName(this.state.projectName)}
>
<Translate id="projectSettings.language.save" />
<Translate id="buttons.save" />
</Button>
</Grid>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class EmailInvite extends React.Component<InviteProps, InviteState> {
onClick={this.onSubmit}
disabled={!this.state.isValid}
>
<Translate id="projectSettings.invite.inviteButton" />
<Translate id="buttons.invite" />
</Button>
</Grid>
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProjectSettings/ProjectUsers/UserList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class UserList extends React.Component<
this.handleChange("");
}}
>
<Translate id="projectSettings.invite.addButton" />
<Translate id="buttons.add" />
</Button>
)}
</ListItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function ArchiveProjectButton(
return (
<React.Fragment>
<Button variant="contained" color="primary" onClick={handleClickOpen}>
<Translate id="siteSettings.archiveProject.button" />
<Translate id="buttons.archive" />
</Button>
<Dialog
open={open}
Expand All @@ -56,16 +56,16 @@ export default function ArchiveProjectButton(
aria-describedby="alert-dialog-description"
>
<DialogTitle id="alert-dialog-title">
<Translate id="siteSettings.archiveProject.warnTitle" />
<Translate id="siteSettings.proceedWithCaution" />
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
<Translate id="siteSettings.archiveProject.warnText" />
<Translate id="siteSettings.archiveProjectText" />
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleClose} variant="outlined" color="primary">
<Translate id="siteSettings.archiveProject.cancel" />
<Translate id="buttons.cancel" />
</Button>
<LoadingButton
onClick={archiveProj}
Expand All @@ -74,7 +74,7 @@ export default function ArchiveProjectButton(
loading={loading}
{...props}
>
<Translate id="siteSettings.archiveProject.confirm" />
<Translate id="buttons.confirm" />
</LoadingButton>
</DialogActions>
</Dialog>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function RestoreProjectButton(
return (
<React.Fragment>
<Button variant="contained" color="primary" onClick={handleClickOpen}>
<Translate id="siteSettings.restoreProject.button" />
<Translate id="buttons.restore" />
</Button>
<Dialog
open={open}
Expand All @@ -56,16 +56,16 @@ export default function RestoreProjectButton(
aria-describedby="alert-dialog-description"
>
<DialogTitle id="alert-dialog-title">
<Translate id="siteSettings.restoreProject.warnTitle" />
<Translate id="siteSettings.proceedWithCaution" />
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
<Translate id="siteSettings.restoreProject.warnText" />
<Translate id="siteSettings.restoreProjectText" />
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleClose} variant="outlined" color="primary">
<Translate id="siteSettings.restoreProject.cancel" />
<Translate id="buttons.cancel" />
</Button>
<LoadingButton
onClick={restoreProj}
Expand All @@ -74,7 +74,7 @@ export default function RestoreProjectButton(
loading={loading}
{...props}
>
<Translate id="siteSettings.restoreProject.confirm" />
<Translate id="buttons.confirm" />
</LoadingButton>
</DialogActions>
</Dialog>
Expand Down
10 changes: 5 additions & 5 deletions src/components/SiteSettings/UserManagment/ConfirmDeletion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { User } from "../../../types/user";

interface ConfirmDeletionProps {
user?: User;
deleteUser: (user: User) => void;
deleteUser: (userId: string) => void;
handleCloseModal: () => void;
}

Expand All @@ -33,7 +33,7 @@ export default function ConfirmDeletion(props: ConfirmDeletionProps) {
{props.user.username}
</Typography>
<Typography align="center" variant="h6">
<Translate id="siteSettings.confirmDelete.title" />
<Translate id="siteSettings.deleteUser.confirm" />
</Typography>
</CardContent>
<CardActions>
Expand All @@ -42,7 +42,7 @@ export default function ConfirmDeletion(props: ConfirmDeletionProps) {
<Button
variant="contained"
onClick={() => {
if (props.user) props.deleteUser(props.user);
if (props.user) props.deleteUser(props.user.id);
}}
color="secondary"
>
Expand All @@ -51,7 +51,7 @@ export default function ConfirmDeletion(props: ConfirmDeletionProps) {
variant="h6"
style={{ color: "red" }}
>
<Translate id="siteSettings.confirmDelete.delete" />
<Translate id="buttons.delete" />
</Typography>
</Button>
</Grid>
Expand All @@ -66,7 +66,7 @@ export default function ConfirmDeletion(props: ConfirmDeletionProps) {
variant="h6"
style={{ color: "inherit" }}
>
<Translate id="siteSettings.confirmDelete.cancel" />
<Translate id="buttons.cancel" />
</Typography>
</Button>
</Grid>
Expand Down
1 change: 0 additions & 1 deletion src/components/SiteSettings/UserManagment/UserList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { getCurrentUser } from "../../../backend/localStorage";
interface UserListProps {
allUsers: User[];
userAvatar: { [key: string]: string };
deleteUser: (user: User) => void;
handleOpenModal: (user: User) => void;
}

Expand Down
24 changes: 17 additions & 7 deletions src/components/SiteSettings/UserManagment/UserManagment.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Grid } from "@material-ui/core";
import React from "react";
import { Translate } from "react-localize-redux";
import Modal from "react-modal";
import { ToastContainer } from "react-toastify";
import { toast, ToastContainer } from "react-toastify";
//styles the ToastContainer so that it appears on the upper right corner with the message.
import "react-toastify/dist/ReactToastify.min.css";
import { avatarSrc, getAllUsers } from "../../../backend";
import { avatarSrc, deleteUser, getAllUsers } from "../../../backend";
import { User } from "../../../types/user";
import UserList from "./UserList";
import ConfirmDeletion from "./ConfirmDeletion";
Expand Down Expand Up @@ -82,9 +83,19 @@ class UserManagment extends React.Component<UserProps, UserState> {
})
.catch((err) => console.log(err));
}
/* deleteUser will be the function called to delete a User
from the Entire Combine once the backend for this is created */
private deleteUser(user: User) {}

deleteUser(userId: string) {
deleteUser(userId)
.then(() => {
toast(<Translate id="siteSettings.deleteUser.toastSuccess" />);
this.populateUsers();
})
.catch((err: string) => {
console.log(err);
toast(<Translate id="siteSettings.deleteUser.toastFailure" />);
});
this.handleCloseModal();
}

render() {
return (
Expand All @@ -93,7 +104,6 @@ class UserManagment extends React.Component<UserProps, UserState> {
<UserList
allUsers={this.state.allUsers}
userAvatar={this.state.userAvatar}
deleteUser={(user: User) => this.deleteUser(user)}
handleOpenModal={(user: User) => this.handleOpenModal(user)}
/>
<ToastContainer
Expand All @@ -117,7 +127,7 @@ class UserManagment extends React.Component<UserProps, UserState> {
>
<ConfirmDeletion
user={this.state.userToEdit}
deleteUser={this.deleteUser}
deleteUser={(userId: string) => this.deleteUser(userId)}
handleCloseModal={this.handleCloseModal}
/>
</Modal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class CharacterInventory extends React.Component<
}}
style={{ margin: theme.spacing(1) }}
>
<Save /> <Translate id="charInventory.save" />
<Save /> <Translate id="buttons.save" />
</Button>
<Button
id={CANCEL}
Expand All @@ -126,7 +126,7 @@ export class CharacterInventory extends React.Component<
style={{ margin: theme.spacing(1) }}
>
{" "}
<Translate id="charInventory.cancel" />
<Translate id="buttons.cancel" />
</Button>
</Grid>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export default function CharacterStatusControl(
aria-label="small outlined secondary button group"
>
<Button onClick={() => props.accept(props.character)}>
<Translate id="charInventory.characterSet.accept" />
<Translate id="buttons.accept" />
</Button>
<Button onClick={() => props.unset(props.character)}>
<Translate id="charInventory.characterSet.undecided" />
<Translate id="buttons.undecided" />
</Button>
<Button onClick={() => props.reject(props.character)}>
<Translate id="charInventory.characterSet.reject" />
<Translate id="buttons.reject" />
</Button>
</ButtonGroup>
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ exports[`Testing Character Inventory Component Renders properly (snapshot test)
/>
</svg>
Missing translationId: charInventory.save for language: \${ languageCode }
Missing translationId: buttons.save for language: \${ languageCode }
</span>
<span
className="MuiTouchRipple-root"
Expand Down Expand Up @@ -394,7 +394,7 @@ exports[`Testing Character Inventory Component Renders properly (snapshot test)
className="MuiButton-label"
>
Missing translationId: charInventory.cancel for language: \${ languageCode }
Missing translationId: buttons.cancel for language: \${ languageCode }
</span>
<span
className="MuiTouchRipple-root"
Expand Down
Loading

0 comments on commit 62666a7

Please sign in to comment.