{"size": 1290, "ext": "js", "max_stars_repo_path": "ui/src/components/users/delete.js", "max_stars_repo_name": "reecerussell/monzo-plus-plus", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ui/src/components/users/delete.js", "max_issues_repo_name": "reecerussell/monzo-plus-plus", "max_issues_repo_issues_event_min_datetime": "2020-08-19T15:49:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-18T20:47:10.000Z", "max_forks_repo_path": "ui/src/components/users/delete.js", "max_forks_repo_name": "reecerussell/monzo-plus-plus", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 20.15625, "max_line_length": 64, "alphanum_fraction": 0.6744186047}
import React from "react";
import PropTypes from "prop-types";
import { Button, Modal, Header, Icon } from "semantic-ui-react";
import { Redirect } from "react-router-dom";

const propTypes = {
	handleSubmit: PropTypes.func.isRequired,
	isModalOpen: PropTypes.bool,
	toggleModal: PropTypes.func.isRequired,
	loading: PropTypes.bool,
	redirect: PropTypes.string,
};
const defaultProps = {
	isModalOpen: false,
	loading: false,
	redirect: null,
};

const Delete = ({
	handleSubmit,
	isModalOpen,
	toggleModal,
	loading,
	redirect,
}) => {
	if (redirect) {
		return <Redirect to={redirect} />;
	}

	const button = (
		<Button color="red" loading={loading} onClick={toggleModal}>
			Delete
		</Button>
	);

	return (
		<Modal
			trigger={button}
			open={isModalOpen}
			onClose={toggleModal}
			size="small"
			basic
		>
			<Header icon="trash" content="Delete" />
			<Modal.Content>
				<h3>Are you sure you'd like to delete this user?</h3>
			</Modal.Content>
			<Modal.Actions>
				<Button onClick={toggleModal}>
					<Icon name="close" /> Cancel
				</Button>
				<Button color="red" onClick={handleSubmit}>
					<Icon name="checkmark" /> Delete
				</Button>
			</Modal.Actions>
		</Modal>
	);
};

Delete.propTypes = propTypes;
Delete.defaultProps = defaultProps;

export default Delete;
