Advertisement
danine1

Payroll Route(Entry point)

Mar 20th, 2018
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from "react";
  2. import PropTypes from "prop-types";
  3. import classnames from "classnames";
  4. import { translate, Trans } from "react-i18next";
  5.  
  6. import { withRouter } from "react-router-dom";
  7. import { graphql, environment } from "@graphql";
  8. import { QueryRenderer } from "react-relay";
  9. import {
  10.   ContentBlock,
  11.   Header,
  12.   Icon,
  13.   Content,
  14. } from "@ematix/tesseract-component-library";
  15.  
  16. import cls from "./styles.scss";
  17. import { ContractForm, SalaryForm, TaxForm, BankForm } from "./Forms";
  18.  
  19. const query = graphql`
  20.   query PayrollQuery($globalId: String!) {
  21.     getEmployee(globalId: $globalId) {
  22.       person {
  23.         ...Tax_taxInfo
  24.       }
  25.     }
  26.   }
  27. `;
  28.  
  29. class Payroll extends React.PureComponent {
  30.   static propTypes = {
  31.     className: PropTypes.string,
  32.     match: PropTypes.instanceOf(Object).isRequired,
  33.   };
  34.  
  35.   static defaultProps = {
  36.     className: null,
  37.   };
  38.  
  39.   state = {
  40.     contractForm: true,
  41.     salaryForm: true,
  42.     bankForm: true,
  43.     taxForm: true,
  44.   };
  45.  
  46.   formReadOnlyChange = formName => () => {
  47.     this.setState({
  48.       [formName]: !this.state[formName],
  49.     });
  50.   };
  51.  
  52.   render() {
  53.     const { className } = this.props;
  54.     const employeeId = this.props.match.params.id;
  55.     return (
  56.       <QueryRenderer
  57.         environment={environment}
  58.         variables={{ globalId: employeeId }}
  59.         query={query}
  60.         render={({ error, props: gqlProps }) => {
  61.           if (error) {
  62.             return null;
  63.           }
  64.           if (!gqlProps) {
  65.             return <div>Loading</div>;
  66.           }
  67.           return (
  68.             <div className={classnames(className)}>
  69.               <ContentBlock>
  70.                 <Header className={cls.header}>
  71.                   <h2 className={cls.title}>
  72.                     <Trans>Contract</Trans>
  73.                   </h2>
  74.                   <Icon
  75.                     className={classnames(cls.edit, {
  76.                       [cls.active]: this.state.contractForm,
  77.                     })}
  78.                     onClick={this.formReadOnlyChange("contractForm")}
  79.                   >
  80.                     edit
  81.                   </Icon>
  82.                 </Header>
  83.                 <Content>
  84.                   <ContractForm
  85.                     isReadOnly={this.state.contractForm}
  86.                     variables={{ id: employeeId }}
  87.                   />
  88.                 </Content>
  89.               </ContentBlock>
  90.               <ContentBlock>
  91.                 <Header className={cls.header}>
  92.                   <h2 className={cls.title}>
  93.                     <Trans>Salary</Trans>
  94.                   </h2>
  95.                   <Icon
  96.                     className={classnames(cls.edit, {
  97.                       [cls.active]: this.state.salaryForm,
  98.                     })}
  99.                     onClick={this.formReadOnlyChange("salaryForm")}
  100.                   >
  101.                     edit
  102.                   </Icon>
  103.                 </Header>
  104.                 <Content>
  105.                   <SalaryForm
  106.                     isReadOnly={this.state.salaryForm}
  107.                     variables={{ id: employeeId }}
  108.                   />
  109.                 </Content>
  110.               </ContentBlock>
  111.               <ContentBlock>
  112.                 <Header className={cls.header}>
  113.                   <h2 className={cls.title}>
  114.                     <Trans>Bank Information</Trans>
  115.                   </h2>
  116.                   <Icon
  117.                     className={classnames(cls.edit, {
  118.                       [cls.active]: this.state.bankForm,
  119.                     })}
  120.                     onClick={this.formReadOnlyChange("bankForm")}
  121.                   >
  122.                     edit
  123.                   </Icon>
  124.                 </Header>
  125.                 <Content>
  126.                   <BankForm
  127.                     isReadOnly={this.state.bankForm}
  128.                     variables={{ id: employeeId }}
  129.                   />
  130.                 </Content>
  131.               </ContentBlock>
  132.               <TaxForm taxInfo={gqlProps.getEmployee.person} />
  133.             </div>
  134.           );
  135.         }}
  136.       />
  137.     );
  138.   }
  139. }
  140. export default withRouter(translate("Payroll")(Payroll));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement