There is no need for a class component here

We should use function component as much as possible, because their are easier to read and less confusing.
This commit is contained in:
Sebastian Sdorra
2020-10-15 08:34:36 +02:00
parent e67ca28c5f
commit ffd1daba52

View File

@@ -22,34 +22,31 @@
* SOFTWARE.
*/
import React from "react";
import { WithTranslation, withTranslation } from "react-i18next";
import React, { FC } from "react";
import { useTranslation } from "react-i18next";
import Notification from "../Notification";
import { Me } from "@scm-manager/ui-types";
import { connect } from "react-redux";
import { compose } from "redux";
type Props = WithTranslation & {
type Props = {
// props from global state
me: Me;
};
class CommitAuthor extends React.Component<Props> {
render() {
const { me, t } = this.props;
const CommitAuthor: FC<Props> = ({ me }) => {
const [t] = useTranslation("repos");
const mail = me.mail ? me.mail : me.fallbackMail;
const mail = me.mail ? me.mail : me.fallbackMail;
return (
<>
{!me.mail && <Notification type="warning">{t("commit.commitAuthor.noMail")}</Notification>}
<span className="mb-2">
<strong>{t("commit.commitAuthor.author")}</strong> {`${me.displayName} <${mail}>`}
</span>
</>
);
}
}
return (
<>
{!me.mail && <Notification type="warning">{t("commit.commitAuthor.noMail")}</Notification>}
<span className="mb-2">
<strong>{t("commit.commitAuthor.author")}</strong> {`${me.displayName} <${mail}>`}
</span>
</>
);
};
const mapStateToProps = (state: any) => {
const { auth } = state;
@@ -60,4 +57,4 @@ const mapStateToProps = (state: any) => {
};
};
export default compose(connect(mapStateToProps), withTranslation("repos"))(CommitAuthor);
export default connect(mapStateToProps)(CommitAuthor);