Advertisement
danine1

dynamic input fields structure

Feb 21st, 2018
263
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 } from "react-i18next";
  5. import {
  6.   Form,
  7.   Input,
  8.   Select,
  9.   DynamicInputField,
  10. } from "@ematix/tesseract-component-library";
  11. import cls from "./styles.scss";
  12.  
  13. class FormIdentification extends React.PureComponent {
  14.   render() {
  15.     const { className, t, ...rest } = this.props;
  16.  
  17.     const type = [];
  18.  
  19.     const Type = ({ rowKey, name }) => (
  20.       <Select
  21.         className={cls.selectType}
  22.         label={t("Document Type")}
  23.         name={`${name}[${rowKey}][type]`}
  24.         options={type}
  25.         searchable={false}
  26.       />
  27.     );
  28.  
  29.     const DocumentId = ({ rowKey, name }) => (
  30.       <Input
  31.         className={cls.inputDocumentId}
  32.         name={`${name}[${rowKey}][documentid]`}
  33.         label={t("Document ID")}
  34.       />
  35.     );
  36.  
  37.     const IssueDate = ({ rowKey, name }) => (
  38.       <Input
  39.         className={cls.inputIssueDate}
  40.         name={`${name}[${rowKey}][issueDate]`}
  41.         label={t("Issue Date")}
  42.       />
  43.     );
  44.  
  45.     const ExpiryDate = ({ rowKey, name }) => (
  46.       <Input
  47.         className={cls.inputExpiryDate}
  48.         name={`${name}[${rowKey}][expiryDate]`}
  49.         label={t("Expiry Date")}
  50.       />
  51.     );
  52.  
  53.     const Authority = ({ rowKey, name }) => (
  54.       <Input
  55.         className={cls.inputAuthority}
  56.         name={`${name}[${rowKey}][authority]`}
  57.         label={t("Authority/Issuer")}
  58.       />
  59.     );
  60.  
  61.     const TypeAndDocumentId = props => (
  62.       <div className={cls.TypeAndDocument}>
  63.         <Type {...props} />
  64.         <DocumentId {...props} />
  65.       </div>
  66.     );
  67.  
  68.     return (
  69.       <Form
  70.         className={classnames(className, cls.form)}
  71.         {...rest}
  72.         onSubmit={() => {}}
  73.       >
  74.         <div className={cls.university}>
  75.           <DynamicInputField
  76.             name="fields"
  77.             className={cls.inputFields}
  78.             fields={[TypeAndDocumentId, IssueDate, ExpiryDate, Authority]}
  79.           />
  80.         </div>
  81.       </Form>
  82.     );
  83.   }
  84. }
  85.  
  86. FormIdentification.propTypes = {
  87.   className: PropTypes.string,
  88. };
  89.  
  90. FormIdentification.defaultProps = {
  91.   className: null,
  92. };
  93.  
  94. FormIdentification.propTypes = { t: PropTypes.func.isRequired };
  95.  
  96. export default translate("FormIdentification")(FormIdentification);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement