Blame view

imports/ui/components/AddDocument.js 827 Bytes
d1f05315d   tmcdeveloper   wip adding API an...
1
  import React from 'react';
cac7cbc73   tmcdeveloper   4.1.0 release
2
3
  import { FormGroup, FormControl } from 'react-bootstrap';
  import { Bert } from 'meteor/themeteorchef:bert';
d1f05315d   tmcdeveloper   wip adding API an...
4
  import { insertDocument } from '../../api/documents/methods.js';
f0c912bf1   tmcdeveloper   add method tests ...
5
6
7
  const handleInsertDocument = (event) => {
    const target = event.target;
    const title = target.value.trim();
d1f05315d   tmcdeveloper   wip adding API an...
8

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