Blame view

imports/ui/components/add-document.js 764 Bytes
d1f05315d   tmcdeveloper   wip adding API an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  import React from 'react';
  import { Row, Col, ListGroup, ListGroupItem, Input, Alert } from 'react-bootstrap';
  import { insertDocument } from '../../api/documents/methods.js';
  
  const handleInsertDocument = ( event ) => {
    const target = event.target,
          title  = target.value.trim();
  
    if ( title !== '' && event.keyCode === 13 ) {
      insertDocument.call({
        title: title
      }, ( error, response ) => {
        if ( error ) {
          Bert.alert( error.reason, 'danger' );
        } else {
          target.value = '';
          Bert.alert( 'Document added!', 'success' );
        }
      });
    }
  };
  
  export const AddDocument = () => (
    <Input
      type="text"
      onKeyUp={ handleInsertDocument }
      placeholder="Type a document title and press enter..."
    />
  )