Added tests, fixed edit/add users

This commit is contained in:
Philipp Czora
2018-07-19 12:05:50 +02:00
parent 3c0ea782aa
commit f4c1403f71
11 changed files with 168 additions and 109 deletions

View File

@@ -0,0 +1,11 @@
//@flow
import React from "react";
import Button, { type ButtonProps } from "./Button";
class AddButton extends React.Component<ButtonProps> {
render() {
return <Button type="default" {...this.props} />;
}
}
export default AddButton;

View File

@@ -1,12 +1,15 @@
//@flow
import React from "react";
import classNames from "classnames";
import { Link } from "react-router-dom";
export type ButtonProps = {
label: string,
loading?: boolean,
disabled?: boolean,
action: () => void
action?: () => void,
link?: string,
fullWidth?: boolean
};
type Props = ButtonProps & {
@@ -14,18 +17,33 @@ type Props = ButtonProps & {
};
class Button extends React.Component<Props> {
render() {
const { label, loading, disabled, type, action } = this.props;
renderButton = () => {
const { label, loading, disabled, type, action, fullWidth } = this.props;
const loadingClass = loading ? "is-loading" : "";
const fullWidthClass = fullWidth ? "is-fullwidth" : "";
return (
<button
disabled={disabled}
onClick={action}
className={classNames("button", "is-" + type, loadingClass)}
onClick={action ? action : () => {}}
className={classNames(
"button",
"is-" + type,
loadingClass,
fullWidthClass
)}
>
{label}
</button>
);
};
render() {
const { link } = this.props;
if (link) {
return <Link to={link}>{this.renderButton()}</Link>;
} else {
return this.renderButton();
}
}
}

View File

@@ -1,41 +1,10 @@
//@flow
import React from "react";
import classNames from "classnames";
import Button, { type ButtonProps } from "./Button";
type Props = {
value: string,
disabled?: boolean,
isLoading?: boolean,
large?: boolean,
fullWidth?: boolean
};
class SubmitButton extends React.Component<Props> {
class SubmitButton extends React.Component<ButtonProps> {
render() {
const { value, large, fullWidth, isLoading, disabled } = this.props;
const largeClass = large ? "is-large" : "";
const fullWidthClass = fullWidth ? "is-fullwidth" : "";
const loadingClass = isLoading ? "is-loading" : "";
return (
<div className="field">
<div className="control">
<button
disabled={disabled}
className={classNames(
"button",
"is-link",
largeClass,
fullWidthClass,
loadingClass
)}
>
{value}
</button>
</div>
</div>
);
return <Button type="primary" {...this.props} />;
}
}