Advertisement
danine1

staging_root

Mar 16th, 2018
283
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.       }
  32.     }
  33.   }
  34. `;
  35.  
  36. class BasicInformation extends React.PureComponent {
  37.   static propTypes = {
  38.     className: PropTypes.string,
  39.     match: PropTypes.instanceOf(Object).isRequired,
  40.   };
  41.  
  42.   static defaultProps = {
  43.     className: null,
  44.   };
  45.  
  46.   state = {
  47.     basicForm: true,
  48.     contactForm: true,
  49.     jobForm: true,
  50.     familyForm: true,
  51.     additionalForm: true,
  52.   };
  53.  
  54.   formReadOnlyChange = formName => () => {
  55.     this.setState({
  56.       [formName]: !this.state[formName],
  57.     });
  58.   };
  59.  
  60.   render() {
  61.     const { className } = this.props;
  62.     const employeeId = this.props.match.params.id;
  63.     return (
  64.       <QueryRenderer
  65.         environment={environment}
  66.         variables={{ globalId: employeeId }}
  67.         query={query}
  68.         render={({ error, props: gqlProps }) => {
  69.           if (error) {
  70.             return null;
  71.           }
  72.           if (!gqlProps) {
  73.             return <div>Loading</div>;
  74.           }
  75.           return (
  76.             <div className={classnames(className)}>
  77.               <BasicForm basicInfo={gqlProps.getEmployee.person} />
  78.               <ContactForm contactInfo={gqlProps.getEmployee.person} />
  79.               <ContentBlock>
  80.                 <Header className={cls.header}>
  81.                   <h2 className={cls.title}>
  82.                     <Trans>Job Info</Trans>
  83.                   </h2>
  84.                   <Icon
  85.                     className={classnames(cls.edit, {
  86.                       [cls.active]: this.state.jobForm,
  87.                     })}
  88.                     onClick={this.formReadOnlyChange("jobForm")}
  89.                   >
  90.                     edit
  91.                   </Icon>
  92.                 </Header>
  93.                 <Content>
  94.                   <JobForm readOnly={this.state.jobForm} />
  95.                 </Content>
  96.               </ContentBlock>
  97.               <ContentBlock>
  98.                 <Header className={cls.header}>
  99.                   <h2 className={cls.title}>
  100.                     <Trans>Family</Trans>
  101.                   </h2>
  102.                   <Icon
  103.                     className={classnames(cls.edit, {
  104.                       [cls.active]: this.state.familyForm,
  105.                     })}
  106.                     onClick={this.formReadOnlyChange("familyForm")}
  107.                   >
  108.                     edit
  109.                   </Icon>
  110.                 </Header>
  111.                 <Content>
  112.                   <FamilyForm isReadOnly={this.state.familyForm} />
  113.                 </Content>
  114.               </ContentBlock>
  115.               <AdditionalForm additionalInfo={gqlProps.getEmployee.person} />
  116.             </div>
  117.           );
  118.         }}
  119.       />
  120.     );
  121.   }
  122. }
  123.  
  124. export default withRouter(translate("BasicInformation")(BasicInformation));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement