-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move change user password modal (#806)
- Loading branch information
1 parent
8bea9ab
commit 11d0080
Showing
5 changed files
with
232 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
portal-ui/src/screens/Console/Users/DeleteUserString.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// This file is part of MinIO Console Server | ||
// Copyright (c) 2021 MinIO, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import React, { useState } from "react"; | ||
import { connect } from "react-redux"; | ||
import { | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogContentText, | ||
DialogTitle, | ||
LinearProgress, | ||
} from "@material-ui/core"; | ||
import api from "../../../common/api"; | ||
import { User, UsersList } from "./types"; | ||
import { setErrorSnackMessage } from "../../../actions"; | ||
import history from "../../../history"; | ||
|
||
interface IDeleteUserProps { | ||
closeDeleteModalAndRefresh: (refresh: boolean) => void; | ||
deleteOpen: boolean; | ||
userName: string; | ||
setErrorSnackMessage: typeof setErrorSnackMessage; | ||
} | ||
|
||
const DeleteUserString = ({ | ||
closeDeleteModalAndRefresh, | ||
deleteOpen, | ||
userName, | ||
setErrorSnackMessage, | ||
}: IDeleteUserProps) => { | ||
const [deleteLoading, setDeleteLoading] = useState<boolean>(false); | ||
|
||
const removeRecord = () => { | ||
if (deleteLoading) { | ||
return; | ||
} | ||
if (userName == null) { | ||
return; | ||
} | ||
setDeleteLoading(true); | ||
api | ||
.invoke("DELETE", `/api/v1/users/${userName}`, { | ||
id: userName, | ||
}) | ||
.then((res: UsersList) => { | ||
setDeleteLoading(false); | ||
closeDeleteModalAndRefresh(true); | ||
}) | ||
.catch((err) => { | ||
setDeleteLoading(false); | ||
setErrorSnackMessage(err); | ||
}); | ||
}; | ||
|
||
if (userName === null) { | ||
return <div />; | ||
} | ||
|
||
return ( | ||
<Dialog | ||
open={deleteOpen} | ||
onClose={() => { | ||
closeDeleteModalAndRefresh(false); | ||
}} | ||
aria-labelledby="alert-dialog-title" | ||
aria-describedby="alert-dialog-description" | ||
> | ||
<DialogTitle id="alert-dialog-title">Delete User</DialogTitle> | ||
<DialogContent> | ||
{deleteLoading && <LinearProgress />} | ||
<DialogContentText id="alert-dialog-description"> | ||
Are you sure you want to delete user <b>{userName}</b>? | ||
</DialogContentText> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button | ||
onClick={() => { | ||
closeDeleteModalAndRefresh(false); | ||
}} | ||
color="primary" | ||
disabled={deleteLoading} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
removeRecord(); | ||
closeDeleteModalAndRefresh(true); | ||
history.push(`/users/`); | ||
}} | ||
color="secondary" | ||
autoFocus | ||
> | ||
Delete | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
const mapDispatchToProps = { | ||
setErrorSnackMessage, | ||
}; | ||
|
||
const connector = connect(null, mapDispatchToProps); | ||
|
||
export default connector(DeleteUserString); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters