Blame view

imports/ui/components/add-document.js 736 Bytes
d1f05315d   tmcdeveloper   wip adding API an...
1
2
3
  import React from 'react';
  import { Row, Col, ListGroup, ListGroupItem, Input, Alert } from 'react-bootstrap';
  import { insertDocument } from '../../api/documents/methods.js';
f0c912bf1   tmcdeveloper   add method tests ...
4
5
6
  const handleInsertDocument = (event) => {
    const target = event.target;
    const title = target.value.trim();
d1f05315d   tmcdeveloper   wip adding API an...
7

f0c912bf1   tmcdeveloper   add method tests ...
8
    if (title !== '' && event.keyCode === 13) {
d1f05315d   tmcdeveloper   wip adding API an...
9
      insertDocument.call({
f0c912bf1   tmcdeveloper   add method tests ...
10
11
12
13
        title,
      }, (error) => {
        if (error) {
          Bert.alert(error.reason, 'danger');
d1f05315d   tmcdeveloper   wip adding API an...
14
15
        } else {
          target.value = '';
f0c912bf1   tmcdeveloper   add method tests ...
16
          Bert.alert('Document added!', 'success');
d1f05315d   tmcdeveloper   wip adding API an...
17
18
19
20
21
22
23
24
25
26
27
        }
      });
    }
  };
  
  export const AddDocument = () => (
    <Input
      type="text"
      onKeyUp={ handleInsertDocument }
      placeholder="Type a document title and press enter..."
    />
f0c912bf1   tmcdeveloper   add method tests ...
28
  );