Advertisement
danine1

(NameofForm)object fragment query in fragments folder

Mar 16th, 2018
268
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.  
  4. import { graphql, createFragmentContainer } from "react-relay";
  5.  
  6. import AdditionalEdit from "../edit";
  7.  
  8. class AdditionalFormContainer extends React.PureComponent {
  9.   static propTypes = {
  10.     additionalInfo: PropTypes.instanceOf(Object).isRequired,
  11.   };
  12.  
  13.   flattenData = (additionalInfo) => {
  14.     const {
  15.       insurance_company,
  16.       insurance_number,
  17.       date_last_medical_check,
  18.       blood_type: { value: blood_type },
  19.       health_issues,
  20.     } = additionalInfo.medical_information;
  21.     return {
  22.       insurance_company,
  23.       insurance_number,
  24.       date_last_medical_check,
  25.       blood_type,
  26.       health_issues,
  27.     };
  28.   };
  29.  
  30.   render() {
  31.     const { additionalInfo, ...rest } = this.props;
  32.     const flatAdditionalInfo = this.flattenData(this.props.additionalInfo);
  33.     return <AdditionalEdit additionalInfo={flatAdditionalInfo} {...rest} />;
  34.   }
  35. }
  36.  
  37. // TODO: find/add missing fields in query - driving license type/number
  38. // other/previous employment and safety training
  39.  
  40. export default createFragmentContainer(
  41.   AdditionalFormContainer,
  42.   graphql`
  43.     fragment AdditionalInformation_additionalInfo on Person {
  44.       medical_information {
  45.         blood_type {
  46.           value
  47.         }
  48.         health_issues
  49.         date_last_medical_check
  50.         insurance_company
  51.         insurance_number
  52.       }
  53.     }
  54.   `,
  55. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement