Advertisement
danine1

family_root

Mar 16th, 2018
292
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. import { withRouter } from "react-router-dom";
  6. import { graphql, environment } from "@graphql";
  7. import { QueryRenderer } from "react-relay";
  8. import {
  9.   ContentBlock,
  10.   Header,
  11.   Content,
  12.   Icon,
  13. } from "@ematix/tesseract-component-library";
  14. import {
  15.   AdditionalForm,
  16.   FamilyForm,
  17.   JobForm,
  18.   ContactForm,
  19.   BasicForm,
  20. } from "./Forms";
  21.  
  22. import cls from "./styles.scss";
  23.  
  24. const query = graphql`
  25.   query BasicInformationQuery($globalId: String!) {
  26.     getEmployee(globalId: $globalId) {
  27.       person {
  28.         ...BasicInformation_basicInfo
  29.         ...AdditionalInformation_additionalInfo
  30.         ...Contact_contactInfo
  31.         ...FamilyInformation_familyInfo
  32.       }
  33.     }
  34.   }
  35. `;
  36.  
  37. class BasicInformation extends React.PureComponent {
  38.   static propTypes = {
  39.     className: PropTypes.string,
  40.     match: PropTypes.instanceOf(Object).isRequired,
  41.   };
  42.  
  43.   static defaultProps = {
  44.     className: null,
  45.   };
  46.  
  47.   state = {
  48.     basicForm: true,
  49.     contactForm: true,
  50.     jobForm: true,
  51.     familyForm: true,
  52.     additionalForm: true,
  53.   };
  54.  
  55.   formReadOnlyChange = formName => () => {
  56.     this.setState({
  57.       [formName]: !this.state[formName],
  58.     });
  59.   };
  60.  
  61.   render() {
  62.     const { className } = this.props;
  63.     const employeeId = this.props.match.params.id;
  64.     return (
  65.       <QueryRenderer
  66.         environment={environment}
  67.         variables={{ globalId: employeeId }}
  68.         query={query}
  69.         render={({ error, props: gqlProps }) => {
  70.           if (error) {
  71.             return null;
  72.           }
  73.           if (!gqlProps) {
  74.             return <div>Loading</div>;
  75.           }
  76.           return (
  77.             <div className={classnames(className)}>
  78.               <BasicForm basicInfo={gqlProps.getEmployee.person} />
  79.               <ContactForm contactInfo={gqlProps.getEmployee.person} />
  80.               <ContentBlock>
  81.                 <Header className={cls.header}>
  82.                   <h2 className={cls.title}>
  83.                     <Trans>Job Info</Trans>
  84.                   </h2>
  85.                   <Icon
  86.                     className={classnames(cls.edit, {
  87.                       [cls.active]: this.state.jobForm,
  88.                     })}
  89.                     onClick={this.formReadOnlyChange("jobForm")}
  90.                   >
  91.                     edit
  92.                   </Icon>
  93.                 </Header>
  94.                 <Content>
  95.                   <JobForm readOnly={this.state.jobForm} />
  96.                 </Content>
  97.               </ContentBlock>
  98.               <FamilyForm familyInfo={gqlProps.getEmployee.person} />
  99.               <ContentBlock>
  100.                 <Header className={cls.header}>
  101.                   <h2 className={cls.title}>
  102.                     <Trans>Additional Information</Trans>
  103.                   </h2>
  104.                   <Icon
  105.                     className={classnames(cls.edit, {
  106.                       [cls.active]: this.state.additionalForm,
  107.                     })}
  108.                     onClick={this.formReadOnlyChange("additionalForm")}
  109.                   >
  110.                     edit
  111.                   </Icon>
  112.                 </Header>
  113.                 <Content>
  114.                   <AdditionalForm
  115.                     isReadOnly={this.state.additionalForm}
  116.                     variables={{ id: employeeId }}
  117.                   />
  118.                 </Content>
  119.               </ContentBlock>
  120.             </div>
  121.           );
  122.         }}
  123.       />
  124.     );
  125.   }
  126. }
  127.  
  128. export default withRouter(translate("BasicInformation")(BasicInformation));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement