Ver código fonte

save button to FC

Ivan Galakhov 4 anos atrás
pai
commit
0ba976a570
1 arquivos alterados com 35 adições e 50 exclusões
  1. 35 50
      dashboard/src/components/SaveButton.tsx

+ 35 - 50
dashboard/src/components/SaveButton.tsx

@@ -2,7 +2,7 @@ import React, { Component } from "react";
 import styled from "styled-components";
 import styled from "styled-components";
 import loading from "assets/loading.gif";
 import loading from "assets/loading.gif";
 
 
-type PropsType = {
+type Props = {
   text?: string;
   text?: string;
   onClick: () => void;
   onClick: () => void;
   disabled?: boolean;
   disabled?: boolean;
@@ -18,84 +18,69 @@ type PropsType = {
   statusPosition?: "right" | "left";
   statusPosition?: "right" | "left";
 };
 };
 
 
-type StateType = {};
-
-export default class SaveButton extends Component<PropsType, StateType> {
-  renderStatus = () => {
-    if (this.props.status) {
-      if (this.props.status === "successful") {
+const SaveButton: React.FC<Props> = (props) => {
+  const renderStatus = () => {
+    if (props.status) {
+      if (props.status === "successful") {
         return (
         return (
-          <StatusWrapper position={this.props.statusPosition} successful={true}>
+          <StatusWrapper position={props.statusPosition} successful={true}>
             <i className="material-icons">done</i>
             <i className="material-icons">done</i>
             <StatusTextWrapper>Successfully updated</StatusTextWrapper>
             <StatusTextWrapper>Successfully updated</StatusTextWrapper>
           </StatusWrapper>
           </StatusWrapper>
         );
         );
-      } else if (this.props.status === "loading") {
+      } else if (props.status === "loading") {
         return (
         return (
-          <StatusWrapper
-            position={this.props.statusPosition}
-            successful={false}
-          >
+          <StatusWrapper position={props.statusPosition} successful={false}>
             <LoadingGif src={loading} />
             <LoadingGif src={loading} />
             <StatusTextWrapper>
             <StatusTextWrapper>
-              {this.props.saveText || "Updating . . ."}
+              {props.saveText || "Updating . . ."}
             </StatusTextWrapper>
             </StatusTextWrapper>
           </StatusWrapper>
           </StatusWrapper>
         );
         );
-      } else if (this.props.status === "error") {
+      } else if (props.status === "error") {
         return (
         return (
-          <StatusWrapper
-            position={this.props.statusPosition}
-            successful={false}
-          >
+          <StatusWrapper position={props.statusPosition} successful={false}>
             <i className="material-icons">error_outline</i>
             <i className="material-icons">error_outline</i>
             <StatusTextWrapper>Could not update</StatusTextWrapper>
             <StatusTextWrapper>Could not update</StatusTextWrapper>
           </StatusWrapper>
           </StatusWrapper>
         );
         );
       } else {
       } else {
         return (
         return (
-          <StatusWrapper
-            position={this.props.statusPosition}
-            successful={false}
-          >
+          <StatusWrapper position={props.statusPosition} successful={false}>
             <i className="material-icons">error_outline</i>
             <i className="material-icons">error_outline</i>
-            <StatusTextWrapper>{this.props.status}</StatusTextWrapper>
+            <StatusTextWrapper>{props.status}</StatusTextWrapper>
           </StatusWrapper>
           </StatusWrapper>
         );
         );
       }
       }
-    } else if (this.props.helper) {
+    } else if (props.helper) {
       return (
       return (
-        <StatusWrapper position={this.props.statusPosition} successful={true}>
-          {this.props.helper}
+        <StatusWrapper position={props.statusPosition} successful={true}>
+          {props.helper}
         </StatusWrapper>
         </StatusWrapper>
       );
       );
     }
     }
   };
   };
 
 
-  render() {
-    return (
-      <ButtonWrapper
-        makeFlush={this.props.makeFlush}
-        clearPosition={this.props.clearPosition}
+  return (
+    <ButtonWrapper
+      makeFlush={props.makeFlush}
+      clearPosition={props.clearPosition}
+    >
+      {props.statusPosition !== "right" && <div>{renderStatus()}</div>}
+      <Button
+        rounded={props.rounded}
+        disabled={props.disabled}
+        onClick={props.onClick}
+        color={props.color || "#616FEEcc"}
       >
       >
-        {this.props.statusPosition !== "right" && (
-          <div>{this.renderStatus()}</div>
-        )}
-        <Button
-          rounded={this.props.rounded}
-          disabled={this.props.disabled}
-          onClick={this.props.onClick}
-          color={this.props.color || "#616FEEcc"}
-        >
-          {this.props.children || this.props.text}
-        </Button>
-        {this.props.statusPosition === "right" && (
-          <div>{this.renderStatus()}</div>
-        )}
-      </ButtonWrapper>
-    );
-  }
-}
+        {props.children || props.text}
+      </Button>
+      {props.statusPosition === "right" && <div>{renderStatus()}</div>}
+    </ButtonWrapper>
+  );
+};
+
+export default SaveButton;
 
 
 const LoadingGif = styled.img`
 const LoadingGif = styled.img`
   width: 15px;
   width: 15px;