Passed
Push — master ( cfe6bd...bdceca )
by Guangyu
04:33 queued 12s
created

src/components/MyEMS/FDD/CombinedEquipmentFault.js   A

Complexity

Total Complexity 15
Complexity/F 0

Size

Lines of Code 958
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 15
eloc 849
mnd 15
bc 15
fnc 0
dl 0
loc 958
rs 9.751
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React, { createRef, Fragment, useEffect, useState } from 'react';
2
import paginationFactory, { PaginationProvider } from 'react-bootstrap-table2-paginator';
3
import BootstrapTable from 'react-bootstrap-table-next';
4
import {
5
  Breadcrumb,
6
  BreadcrumbItem,
7
  Row,
8
  Col,
9
  Card,
10
  CardBody,
11
  Button,
12
  ButtonGroup,
13
  Form,
14
  FormGroup,
15
  Input,
16
  Label,
17
  CustomInput,
18
  DropdownItem,
19
  DropdownMenu,
20
  DropdownToggle,
21
  InputGroup,
22
  UncontrolledDropdown,
23
  Spinner,
24
} from 'reactstrap';
25
import Datetime from 'react-datetime';
26
import moment from 'moment';
27
import Cascader from 'rc-cascader';
28
import { Link } from 'react-router-dom';
29
import Badge from 'reactstrap/es/Badge';
30
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
31
import FalconCardHeader from '../../common/FalconCardHeader';
32
import uuid from 'uuid/v1';
33
import { getPaginationArray } from '../../../helpers/utils';
34
import { getCookieValue, createCookie } from '../../../helpers/utils';
35
import withRedirect from '../../../hoc/withRedirect';
36
import { withTranslation } from 'react-i18next';
37
import { toast } from 'react-toastify';
38
import ButtonIcon from '../../common/ButtonIcon';
39
import { APIBaseURL } from '../../../config';
40
41
42
const CombinedEquipmentFault = ({ setRedirect, setRedirectUrl, t }) => {
43
  let current_moment = moment();
44
  useEffect(() => {
45
    let is_logged_in = getCookieValue('is_logged_in');
46
    let user_name = getCookieValue('user_name');
47
    let user_display_name = getCookieValue('user_display_name');
48
    let user_uuid = getCookieValue('user_uuid');
49
    let token = getCookieValue('token');
50
    if (is_logged_in === null || !is_logged_in) {
51
      setRedirectUrl(`/authentication/basic/login`);
52
      setRedirect(true);
53
    } else {
54
      //update expires time of cookies
55
      createCookie('is_logged_in', true, 1000 * 60 * 60 * 8);
56
      createCookie('user_name', user_name, 1000 * 60 * 60 * 8);
57
      createCookie('user_display_name', user_display_name, 1000 * 60 * 60 * 8);
58
      createCookie('user_uuid', user_uuid, 1000 * 60 * 60 * 8);
59
      createCookie('token', token, 1000 * 60 * 60 * 8);
60
    }
61
  });
62
  // State
63
  // Query Parameters
64
  const [selectedSpaceName, setSelectedSpaceName] = useState(undefined);
65
  const [selectedSpaceID, setSelectedSpaceID] = useState(undefined);
66
  const [combinedEquipmentList, setCombinedEquipmentList] = useState([]);
67
  const [selectedCombinedEquipment, setSelectedCombinedEquipment] = useState(undefined);
68
  const [reportingPeriodBeginsDatetime, setReportingPeriodBeginsDatetime] = useState(current_moment.clone().startOf('month'));
69
  const [reportingPeriodEndsDatetime, setReportingPeriodEndsDatetime] = useState(current_moment);
70
  const [cascaderOptions, setCascaderOptions] = useState(undefined);
71
72
  // buttons
73
  const [submitButtonDisabled, setSubmitButtonDisabled] = useState(true);
74
  const [spinnerHidden, setSpinnerHidden] = useState(true);
75
  const [exportButtonHidden, setExportButtonHidden] = useState(true);
76
77
  //Results
78
  const [detailedDataTableData, setDetailedDataTableData] = useState([]);
79
  const [detailedDataTableColumns, setDetailedDataTableColumns] = useState([{dataField: 'startdatetime', text: t('Datetime'), sort: true}]);
80
  const [excelBytesBase64, setExcelBytesBase64] = useState(undefined);
81
  
82
  useEffect(() => {
83
    let isResponseOK = false;
84
    fetch(APIBaseURL + '/spaces/tree', {
85
      method: 'GET',
86
      headers: {
87
        "Content-type": "application/json",
88
        "User-UUID": getCookieValue('user_uuid'),
89
        "Token": getCookieValue('token')
90
      },
91
      body: null,
92
93
    }).then(response => {
94
      console.log(response);
95
      if (response.ok) {
96
        isResponseOK = true;
97
      }
98
      return response.json();
99
    }).then(json => {
100
      console.log(json)
101
      if (isResponseOK) {
102
        // rename keys 
103
        json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
104
        setCascaderOptions(json);
105
        setSelectedSpaceName([json[0]].map(o => o.label));
106
        setSelectedSpaceID([json[0]].map(o => o.value));
107
        // get Combined Equipments by root Space ID
108
        let isResponseOK = false;
109
        fetch(APIBaseURL + '/spaces/' + [json[0]].map(o => o.value) + '/combinedequipments', {
110
          method: 'GET',
111
          headers: {
112
            "Content-type": "application/json",
113
            "User-UUID": getCookieValue('user_uuid'),
114
            "Token": getCookieValue('token')
115
          },
116
          body: null,
117
118
        }).then(response => {
119
          if (response.ok) {
120
            isResponseOK = true;
121
          }
122
          return response.json();
123
        }).then(json => {
124
          if (isResponseOK) {
125
            json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
126
            console.log(json);
127
            setCombinedEquipmentList(json[0]);
128
            if (json[0].length > 0) {
129
              setSelectedCombinedEquipment(json[0][0].value);
130
              // enable submit button
131
              setSubmitButtonDisabled(false);
132
            } else {
133
              setSelectedCombinedEquipment(undefined);
134
              // disable submit button
135
              setSubmitButtonDisabled(true);
136
            }
137
          } else {
138
            toast.error(json.description)
139
          }
140
        }).catch(err => {
141
          console.log(err);
142
        });
143
        // end of get Combined Equipments by root Space ID
144
      } else {
145
        toast.error(json.description);
146
      }
147
    }).catch(err => {
148
      console.log(err);
149
    });
150
151
  }, []);
152
153
  const orderFormatter = (dataField, { id, name, email }) => (
154
    <Fragment>
155
      <Link to="/e-commerce/order-details">
156
        <strong>#{id}</strong>
157
      </Link>{' '}
158
      by <strong>{name}</strong>
159
      <br />
160
      <a href={`mailto:${email}`}>{email}</a>
161
    </Fragment>
162
  );
163
164
  const shippingFormatter = (address, { shippingType }) => (
165
    <Fragment>
166
      {address}
167
      <p className="mb-0 text-500">{shippingType}</p>
168
    </Fragment>
169
  );
170
171
  const badgeFormatter = status => {
172
    let color = '';
173
    let icon = '';
174
    let text = '';
175
    switch (status) {
176
      case 'success':
177
        color = 'success';
178
        icon = 'check';
179
        text = 'Completed';
180
        break;
181
      case 'hold':
182
        color = 'secondary';
183
        icon = 'ban';
184
        text = 'On hold';
185
        break;
186
      case 'processing':
187
        color = 'primary';
188
        icon = 'redo';
189
        text = 'Processing';
190
        break;
191
      case 'pending':
192
        color = 'warning';
193
        icon = 'stream';
194
        text = 'Pending';
195
        break;
196
      default:
197
        color = 'warning';
198
        icon = 'stream';
199
        text = 'Pending';
200
    }
201
202
    return (
203
      <Badge color={`soft-${color}`} className="rounded-capsule fs--1 d-block">
204
        {text}
205
        <FontAwesomeIcon icon={icon} transform="shrink-2" className="ml-1" />
206
      </Badge>
207
    );
208
  };
209
210
  const actionFormatter = (dataField, { id }) => (
211
    // Control your row with this id
212
    <UncontrolledDropdown>
213
      <DropdownToggle color="link" size="sm" className="text-600 btn-reveal mr-3">
214
        <FontAwesomeIcon icon="ellipsis-h" className="fs--1" />
215
      </DropdownToggle>
216
      <DropdownMenu right className="border py-2">
217
        <DropdownItem onClick={() => console.log('Completed: ', id)}>Completed</DropdownItem>
218
        <DropdownItem onClick={() => console.log('Processing: ', id)}>Processing</DropdownItem>
219
        <DropdownItem onClick={() => console.log('On hold: ', id)}>On hold</DropdownItem>
220
        <DropdownItem onClick={() => console.log('Pending: ', id)}>Pending</DropdownItem>
221
        <DropdownItem divider />
222
        <DropdownItem onClick={() => console.log('Delete: ', id)} className="text-danger">
223
          Delete
224
        </DropdownItem>
225
      </DropdownMenu>
226
    </UncontrolledDropdown>
227
  );
228
229
  const options = {
230
    custom: true,
231
    sizePerPage: 10,
232
    totalSize: detailedDataTableData.length
233
  };
234
235
  const SelectRowInput = ({ indeterminate, rowIndex, ...rest }) => (
236
    <div className="custom-control custom-checkbox">
237
      <input
238
        className="custom-control-input"
239
        {...rest}
240
        onChange={() => { }}
241
        ref={input => {
242
          if (input) input.indeterminate = indeterminate;
243
        }}
244
      />
245
      <label className="custom-control-label" />
246
    </div>
247
  );
248
249
  const selectRow = onSelect => ({
250
    mode: 'checkbox',
251
    classes: 'py-2 align-middle',
252
    clickToSelect: false,
253
    selectionHeaderRenderer: ({ mode, ...rest }) => <SelectRowInput type="checkbox" {...rest} />,
254
    selectionRenderer: ({ mode, ...rest }) => <SelectRowInput type={mode} {...rest} />,
255
    onSelect: onSelect,
256
    onSelectAll: onSelect
257
  });
258
259
  const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0';
260
261
  let table = createRef();
262
263
  const [isSelected, setIsSelected] = useState(false);
264
  const handleNextPage = ({ page, onPageChange }) => () => {
265
    onPageChange(page + 1);
266
  };
267
268
  const handlePrevPage = ({ page, onPageChange }) => () => {
269
    onPageChange(page - 1);
270
  };
271
272
  const onSelect = () => {
273
    setImmediate(() => {
274
      setIsSelected(!!table.current.selectionContext.selected.length);
275
    });
276
  };
277
278
  let onSpaceCascaderChange = (value, selectedOptions) => {
279
    setSelectedSpaceName(selectedOptions.map(o => o.label).join('/'));
280
    setSelectedSpaceID(value[value.length - 1]);
281
282
    let isResponseOK = false;
283
    fetch(APIBaseURL + '/spaces/' + value[value.length - 1] + '/combinedequipments', {
284
      method: 'GET',
285
      headers: {
286
        "Content-type": "application/json",
287
        "User-UUID": getCookieValue('user_uuid'),
288
        "Token": getCookieValue('token')
289
      },
290
      body: null,
291
292
    }).then(response => {
293
      if (response.ok) {
294
        isResponseOK = true;
295
      }
296
      return response.json();
297
    }).then(json => {
298
      if (isResponseOK) {
299
        json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
300
        console.log(json)
301
        setCombinedEquipmentList(json[0]);
302
        if (json[0].length > 0) {
303
          setSelectedCombinedEquipment(json[0][0].value);
304
          // enable submit button
305
          setSubmitButtonDisabled(false);
306
        } else {
307
          setSelectedCombinedEquipment(undefined);
308
          // disable submit button
309
          setSubmitButtonDisabled(true);
310
        }
311
      } else {
312
        toast.error(json.description)
313
      }
314
    }).catch(err => {
315
      console.log(err);
316
    });
317
  }
318
319
  let onReportingPeriodBeginsDatetimeChange = (newDateTime) => {
320
    setReportingPeriodBeginsDatetime(newDateTime);
321
  }
322
323
  let onReportingPeriodEndsDatetimeChange = (newDateTime) => {
324
    setReportingPeriodEndsDatetime(newDateTime);
325
  }
326
327
  var getValidReportingPeriodBeginsDatetimes = function (currentDate) {
328
    return currentDate.isBefore(moment(reportingPeriodEndsDatetime, 'MM/DD/YYYY, hh:mm:ss a'));
329
  }
330
331
  var getValidReportingPeriodEndsDatetimes = function (currentDate) {
332
    return currentDate.isAfter(moment(reportingPeriodBeginsDatetime, 'MM/DD/YYYY, hh:mm:ss a'));
333
  }
334
335
  // Handler
336
  const handleSubmit = e => {
337
    e.preventDefault();
338
    console.log('handleSubmit');
339
    console.log(selectedSpaceID);
340
    console.log(selectedCombinedEquipment);
341
    console.log(reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss'));
342
    console.log(reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'));
343
344
    // disable submit button
345
    setSubmitButtonDisabled(true);
346
    // show spinner
347
    setSpinnerHidden(false);
348
    // hide export buttion
349
    setExportButtonHidden(true)
350
351
    // Reinitialize tables
352
    setDetailedDataTableData([]);
353
    
354
    let isResponseOK = false;
355
    fetch(APIBaseURL + '/reports/fddcombinedequipmentfault?' +
356
      'combinedequipmentid' + selectedCombinedEquipment +
357
      '&reportingperiodstartdatetime=' + reportingPeriodBeginsDatetime.format('YYYY-MM-DDTHH:mm:ss') +
358
      '&reportingperiodenddatetime=' + reportingPeriodEndsDatetime.format('YYYY-MM-DDTHH:mm:ss'), {
359
      method: 'GET',
360
      headers: {
361
        "Content-type": "application/json",
362
        "User-UUID": getCookieValue('user_uuid'),
363
        "Token": getCookieValue('token')
364
      },
365
      body: null,
366
367
    }).then(response => {
368
      if (response.ok) {
369
        isResponseOK = true;
370
      }
371
372
      // enable submit button
373
      setSubmitButtonDisabled(false);
374
      // hide spinner
375
      setSpinnerHidden(true);
376
      // show export buttion
377
      setExportButtonHidden(false)
378
379
      return response.json();
380
    }).then(json => {
381
      if (isResponseOK) {
382
        console.log(json)
383
              
384
        setDetailedDataTableData([
385
          {
386
            id: uuid().split('-')[0],
387
            // id: 181,
388
            name: 'Ricky Antony',
389
            email: '[email protected]',
390
            date: '20/04/2019',
391
            address: 'Ricky Antony, 2392 Main Avenue, Penasauka, New Jersey 02149',
392
            shippingType: 'Via Flat Rate',
393
            status: 'success',
394
            amount: 99
395
          },
396
          {
397
            id: uuid().split('-')[0],
398
            // id: 182,
399
            name: 'Kin Rossow',
400
            email: '[email protected]',
401
            date: '20/04/2019',
402
            address: 'Kin Rossow, 1 Hollywood Blvd,Beverly Hills, California 90210',
403
            shippingType: 'Via Free Shipping',
404
            status: 'success',
405
            amount: 120
406
          },
407
          {
408
            id: uuid().split('-')[0],
409
            // id: 183,
410
            name: 'Merry Diana',
411
            email: '[email protected]',
412
            date: '30/04/2019',
413
            address: 'Merry Diana, 1 Infinite Loop, Cupertino, California 90210',
414
            shippingType: 'Via Link Road',
415
            status: 'hold',
416
            amount: 70
417
          },
418
          {
419
            id: uuid().split('-')[0],
420
            // id: 184,
421
            name: 'Bucky Robert',
422
            email: '[email protected]',
423
            date: '30/04/2019',
424
            address: 'Bucky Robert, 1 Infinite Loop, Cupertino, California 90210',
425
            shippingType: 'Via Free Shipping',
426
            status: 'pending',
427
            amount: 92
428
          },
429
          {
430
            id: uuid().split('-')[0],
431
            // id: 185,
432
            name: 'Rocky Zampa',
433
            email: '[email protected]',
434
            date: '30/04/2019',
435
            address: 'Rocky Zampa, 1 Infinite Loop, Cupertino, California 90210',
436
            shippingType: 'Via Free Road',
437
            status: 'hold',
438
            amount: 120
439
          },
440
          {
441
            id: uuid().split('-')[0],
442
            // id: 186,
443
            name: 'Ricky John',
444
            email: '[email protected]',
445
            date: '30/04/2019',
446
            address: 'Ricky John, 1 Infinite Loop, Cupertino, California 90210',
447
            shippingType: 'Via Free Shipping',
448
            status: 'processing',
449
            amount: 145
450
          },
451
          {
452
            id: uuid().split('-')[0],
453
            // id: 187,
454
            name: 'Cristofer Henric',
455
            email: '[email protected]',
456
            date: '30/04/2019',
457
            address: 'Cristofer Henric, 1 Infinite Loop, Cupertino, California 90210',
458
            shippingType: 'Via Flat Rate',
459
            status: 'success',
460
            amount: 55
461
          },
462
          {
463
            id: uuid().split('-')[0],
464
            // id: 188,
465
            name: 'Brate Lee',
466
            email: '[email protected]',
467
            date: '29/04/2019',
468
            address: 'Brate Lee, 1 Infinite Loop, Cupertino, California 90210',
469
            shippingType: 'Via Link Road',
470
            status: 'hold',
471
            amount: 90
472
          },
473
          {
474
            id: uuid().split('-')[0],
475
            // id: 189,
476
            name: 'Thomas Stephenson',
477
            email: '[email protected]',
478
            date: '29/04/2019',
479
            address: 'Thomas Stephenson, 116 Ballifeary Road, Bamff',
480
            shippingType: 'Via Flat Rate',
481
            status: 'processing',
482
            amount: 52
483
          },
484
          {
485
            id: uuid().split('-')[0],
486
            // id: 190,
487
            name: 'Evie Singh',
488
            email: '[email protected]',
489
            date: '29/04/2019',
490
            address: 'Evie Singh, 54 Castledore Road, Tunstead',
491
            shippingType: 'Via Flat Rate',
492
            status: 'success',
493
            amount: 90
494
          },
495
          {
496
            id: uuid().split('-')[0],
497
            // id: 191,
498
            name: 'David Peters',
499
            email: '[email protected]',
500
            date: '29/04/2019',
501
            address: 'David Peters, Rhyd Y Groes, Rhosgoch, LL66 0AT',
502
            shippingType: 'Via Link Road',
503
            status: 'success',
504
            amount: 69
505
          },
506
          {
507
            id: uuid().split('-')[0],
508
            // id: 192,
509
            name: 'Jennifer Johnson',
510
            email: '[email protected]',
511
            date: '28/04/2019',
512
            address: 'Jennifer Johnson, Rhyd Y Groes, Rhosgoch, LL66 0AT',
513
            shippingType: 'Via Flat Rate',
514
            status: 'processing',
515
            amount: 112
516
          },
517
          {
518
            id: uuid().split('-')[0],
519
            // id: 193,
520
            name: ' Demarcus Okuneva',
521
            email: '[email protected]',
522
            date: '28/04/2019',
523
            address: ' Demarcus Okuneva, 90555 Upton Drive Jeffreyview, UT 08771',
524
            shippingType: 'Via Flat Rate',
525
            status: 'success',
526
            amount: 99
527
          },
528
          {
529
            id: uuid().split('-')[0],
530
            // id: 194,
531
            name: 'Simeon Harber',
532
            email: '[email protected]',
533
            date: '27/04/2019',
534
            address: 'Simeon Harber, 702 Kunde Plain Apt. 634 East Bridgetview, HI 13134-1862',
535
            shippingType: 'Via Free Shipping',
536
            status: 'hold',
537
            amount: 129
538
          },
539
          {
540
            id: uuid().split('-')[0],
541
            // id: 195,
542
            name: 'Lavon Haley',
543
            email: '[email protected]',
544
            date: '27/04/2019',
545
            address: 'Lavon Haley, 30998 Adonis Locks McGlynnside, ID 27241',
546
            shippingType: 'Via Free Shipping',
547
            status: 'pending',
548
            amount: 70
549
          },
550
          {
551
            id: uuid().split('-')[0],
552
            // id: 196,
553
            name: 'Ashley Kirlin',
554
            email: '[email protected]',
555
            date: '26/04/2019',
556
            address: 'Ashley Kirlin, 43304 Prosacco Shore South Dejuanfurt, MO 18623-0505',
557
            shippingType: 'Via Link Road',
558
            status: 'processing',
559
            amount: 39
560
          },
561
          {
562
            id: uuid().split('-')[0],
563
            // id: 197,
564
            name: 'Johnnie Considine',
565
            email: '[email protected]',
566
            date: '26/04/2019',
567
            address: 'Johnnie Considine, 6008 Hermann Points Suite 294 Hansenville, TN 14210',
568
            shippingType: 'Via Flat Rate',
569
            status: 'pending',
570
            amount: 70
571
          },
572
          {
573
            id: uuid().split('-')[0],
574
            // id: 198,
575
            name: 'Trace Farrell',
576
            email: '[email protected]',
577
            date: '26/04/2019',
578
            address: 'Trace Farrell, 431 Steuber Mews Apt. 252 Germanland, AK 25882',
579
            shippingType: 'Via Free Shipping',
580
            status: 'success',
581
            amount: 70
582
          },
583
          {
584
            id: uuid().split('-')[0],
585
            // id: 199,
586
            name: 'Estell Nienow',
587
            email: '[email protected]',
588
            date: '26/04/2019',
589
            address: 'Estell Nienow, 4167 Laverna Manor Marysemouth, NV 74590',
590
            shippingType: 'Via Free Shipping',
591
            status: 'success',
592
            amount: 59
593
          },
594
          {
595
            id: uuid().split('-')[0],
596
            // id: 200,
597
            name: 'Daisha Howe',
598
            email: '[email protected]',
599
            date: '25/04/2019',
600
            address: 'Daisha Howe, 829 Lavonne Valley Apt. 074 Stehrfort, RI 77914-0379',
601
            shippingType: 'Via Free Shipping',
602
            status: 'success',
603
            amount: 39
604
          },
605
          {
606
            id: uuid().split('-')[0],
607
            // id: 201,
608
            name: 'Miles Haley',
609
            email: '[email protected]',
610
            date: '24/04/2019',
611
            address: 'Miles Haley, 53150 Thad Squares Apt. 263 Archibaldfort, MO 00837',
612
            shippingType: 'Via Flat Rate',
613
            status: 'success',
614
            amount: 55
615
          },
616
          {
617
            id: uuid().split('-')[0],
618
            // id: 202,
619
            name: 'Brenda Watsica',
620
            email: '[email protected]',
621
            date: '24/04/2019',
622
            address: "Brenda Watsica, 9198 O'Kon Harbors Morarborough, IA 75409-7383",
623
            shippingType: 'Via Free Shipping',
624
            status: 'success',
625
            amount: 89
626
          },
627
          {
628
            id: uuid().split('-')[0],
629
            // id: 203,
630
            name: "Ellie O'Reilly",
631
            email: '[email protected]',
632
            date: '24/04/2019',
633
            address: "Ellie O'Reilly, 1478 Kaitlin Haven Apt. 061 Lake Muhammadmouth, SC 35848",
634
            shippingType: 'Via Free Shipping',
635
            status: 'success',
636
            amount: 47
637
          },
638
          {
639
            id: uuid().split('-')[0],
640
            // id: 204,
641
            name: 'Garry Brainstrow',
642
            email: '[email protected]',
643
            date: '23/04/2019',
644
            address: 'Garry Brainstrow, 13572 Kurt Mews South Merritt, IA 52491',
645
            shippingType: 'Via Free Shipping',
646
            status: 'success',
647
            amount: 139
648
          },
649
          {
650
            id: uuid().split('-')[0],
651
            // id: 205,
652
            name: 'Estell Pollich',
653
            email: '[email protected]',
654
            date: '23/04/2019',
655
            address: 'Estell Pollich, 13572 Kurt Mews South Merritt, IA 52491',
656
            shippingType: 'Via Free Shipping',
657
            status: 'hold',
658
            amount: 49
659
          },
660
          {
661
            id: uuid().split('-')[0],
662
            // id: 206,
663
            name: 'Ara Mueller',
664
            email: '[email protected]',
665
            date: '23/04/2019',
666
            address: 'Ara Mueller, 91979 Kohler Place Waelchiborough, CT 41291',
667
            shippingType: 'Via Flat Rate',
668
            status: 'hold',
669
            amount: 19
670
          },
671
          {
672
            id: uuid().split('-')[0],
673
            // id: 207,
674
            name: 'Lucienne Blick',
675
            email: '[email protected]',
676
            date: '23/04/2019',
677
            address: 'Lucienne Blick, 6757 Giuseppe Meadows Geraldinemouth, MO 48819-4970',
678
            shippingType: 'Via Flat Rate',
679
            status: 'hold',
680
            amount: 59
681
          },
682
          {
683
            id: uuid().split('-')[0],
684
            // id: 208,
685
            name: 'Laverne Haag',
686
            email: '[email protected]',
687
            date: '22/04/2019',
688
            address: 'Laverne Haag, 2327 Kaylee Mill East Citlalli, AZ 89582-3143',
689
            shippingType: 'Via Flat Rate',
690
            status: 'hold',
691
            amount: 49
692
          },
693
          {
694
            id: uuid().split('-')[0],
695
            // id: 209,
696
            name: 'Brandon Bednar',
697
            email: '[email protected]',
698
            date: '22/04/2019',
699
            address: 'Brandon Bednar, 25156 Isaac Crossing Apt. 810 Lonborough, CO 83774-5999',
700
            shippingType: 'Via Flat Rate',
701
            status: 'hold',
702
            amount: 39
703
          },
704
          {
705
            id: uuid().split('-')[0],
706
            // id: 210,
707
            name: 'Dimitri Boehm',
708
            email: '[email protected]',
709
            date: '23/04/2019',
710
            address: 'Dimitri Boehm, 71603 Wolff Plains Apt. 885 Johnstonton, MI 01581',
711
            shippingType: 'Via Flat Rate',
712
            status: 'hold',
713
            amount: 111
714
          }
715
        ]);
716
717
        setDetailedDataTableColumns([
718
          {
719
            dataField: 'id',
720
            text: 'Space',
721
            classes: 'py-2 align-middle',
722
            formatter: orderFormatter,
723
            sort: true
724
          },
725
          {
726
            dataField: 'date',
727
            text: 'Date',
728
            classes: 'py-2 align-middle',
729
            sort: true
730
          },
731
          {
732
            dataField: 'address',
733
            text: 'Description',
734
            classes: 'py-2 align-middle',
735
            formatter: shippingFormatter,
736
            sort: true
737
          },
738
          {
739
            dataField: 'status',
740
            text: 'Status',
741
            classes: 'py-2 align-middle',
742
            formatter: badgeFormatter,
743
            sort: true
744
          },
745
          {
746
            dataField: '',
747
            text: '',
748
            classes: 'py-2 align-middle',
749
            formatter: actionFormatter,
750
            align: 'right'
751
          }
752
        ]);
753
        
754
        setExcelBytesBase64(json['excel_bytes_base64']);
755
      } else {
756
        toast.error(json.description)
757
      }
758
    }).catch(err => {
759
      console.log(err);
760
    });
761
  };
762
  
763
  const handleExport = e => {
764
    e.preventDefault();
765
    const mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
766
    const fileName = 'combinedequipmentfault.xlsx'
767
    var fileUrl = "data:" + mimeType + ";base64," + excelBytesBase64;
768
    fetch(fileUrl)
769
        .then(response => response.blob())
770
        .then(blob => {
771
            var link = window.document.createElement("a");
772
            link.href = window.URL.createObjectURL(blob, { type: mimeType });
773
            link.download = fileName;
774
            document.body.appendChild(link);
775
            link.click();
776
            document.body.removeChild(link);
777
        });
778
  };
779
  
780
781
782
  return (
783
    <Fragment>
784
      <div>
785
        <Breadcrumb>
786
          <BreadcrumbItem>{t('Fault Detection & Diagnostics')}</BreadcrumbItem><BreadcrumbItem active>{t('Combined Equipment Faults Data')}</BreadcrumbItem>
787
        </Breadcrumb>
788
      </div>
789
      <Card className="bg-light mb-3">
790
        <CardBody className="p-3">
791
          <Form onSubmit={handleSubmit}>
792
            <Row form>
793
              <Col xs="auto">
794
                <FormGroup className="form-group">
795
                  <Label className={labelClasses} for="space">
796
                    {t('Space')}
797
                  </Label>
798
                  <br />
799
                  <Cascader options={cascaderOptions}
800
                    onChange={onSpaceCascaderChange}
801
                    changeOnSelect
802
                    expandTrigger="hover">
803
                    <Input value={selectedSpaceName || ''} readOnly />
804
                  </Cascader>
805
                </FormGroup>
806
              </Col>
807
              <Col xs="auto">
808
                <FormGroup>
809
                  <Label className={labelClasses} for="combinedEquipmentSelect">
810
                    {t('Combined Equipment')}
811
                  </Label>
812
                  <CustomInput type="select" id="combinedEquipmentSelect" name="combinedEquipmentSelect" onChange={({ target }) => setSelectedCombinedEquipment(target.value)}
813
                  >
814
                    {combinedEquipmentList.map((combinedEquipment, index) => (
815
                      <option value={combinedEquipment.value} key={combinedEquipment.value}>
816
                        {combinedEquipment.label}
817
                      </option>
818
                    ))}
819
                  </CustomInput>
820
                </FormGroup>
821
              </Col>
822
              <Col xs="auto">
823
                <FormGroup className="form-group">
824
                  <Label className={labelClasses} for="reportingPeriodBeginsDatetime">
825
                    {t('Reporting Period Begins')}
826
                  </Label>
827
                  <Datetime id='reportingPeriodBeginsDatetime'
828
                    value={reportingPeriodBeginsDatetime}
829
                    onChange={onReportingPeriodBeginsDatetimeChange}
830
                    isValidDate={getValidReportingPeriodBeginsDatetimes}
831
                    closeOnSelect={true} />
832
                </FormGroup>
833
              </Col>
834
              <Col xs="auto">
835
                <FormGroup className="form-group">
836
                  <Label className={labelClasses} for="reportingPeriodEndsDatetime">
837
                    {t('Reporting Period Ends')}
838
                  </Label>
839
                  <Datetime id='reportingPeriodEndsDatetime'
840
                    value={reportingPeriodEndsDatetime}
841
                    onChange={onReportingPeriodEndsDatetimeChange}
842
                    isValidDate={getValidReportingPeriodEndsDatetimes}
843
                    closeOnSelect={true} />
844
                </FormGroup>
845
              </Col>
846
              <Col xs="auto">
847
                <FormGroup>
848
                  <br></br>
849
                  <ButtonGroup id="submit">
850
                    <Button color="success" disabled={submitButtonDisabled} >{t('Submit')}</Button>
851
                  </ButtonGroup>
852
                </FormGroup>
853
              </Col>
854
              <Col xs="auto">
855
                <FormGroup>
856
                  <br></br>
857
                  <Spinner color="primary" hidden={spinnerHidden}  />
858
                </FormGroup>
859
              </Col>
860
              <Col xs="auto">
861
                  <br></br>
862
                  <ButtonIcon icon="external-link-alt" transform="shrink-3 down-2" color="falcon-default" 
863
                  hidden={exportButtonHidden}
864
                  onClick={handleExport} >
865
                    {t('Export')}
866
                  </ButtonIcon>
867
              </Col>
868
            </Row>
869
          </Form>
870
        </CardBody>
871
      </Card>
872
      <Card className="mb-3">
873
        <FalconCardHeader title={t('Fault List')} light={false}>
874
          {isSelected ? (
875
            <InputGroup size="sm" className="input-group input-group-sm">
876
              <CustomInput type="select" id="bulk-select">
877
                <option>Bulk actions</option>
878
                <option value="Refund">Refund</option>
879
                <option value="Delete">Delete</option>
880
                <option value="Archive">Archive</option>
881
              </CustomInput>
882
              <Button color="falcon-default" size="sm" className="ml-2">
883
                Apply
884
                </Button>
885
            </InputGroup>
886
          ) : (
887
              <Fragment>
888
               
889
              </Fragment>
890
            )}
891
        </FalconCardHeader>
892
        <CardBody className="p-0">
893
          <PaginationProvider pagination={paginationFactory(options)}>
894
            {({ paginationProps, paginationTableProps }) => {
895
              const lastIndex = paginationProps.page * paginationProps.sizePerPage;
896
897
              return (
898
                <Fragment>
899
                  <div className="table-responsive">
900
                    <BootstrapTable
901
                      ref={table}
902
                      bootstrap4
903
                      keyField="id"
904
                      data={detailedDataTableData}
905
                      columns={detailedDataTableColumns}
906
                      selectRow={selectRow(onSelect)}
907
                      bordered={false}
908
                      classes="table-dashboard table-striped table-sm fs--1 border-bottom mb-0 table-dashboard-th-nowrap"
909
                      rowClasses="btn-reveal-trigger"
910
                      headerClasses="bg-200 text-900"
911
                      {...paginationTableProps}
912
                    />
913
                  </div>
914
                  <Row noGutters className="px-1 py-3 flex-center">
915
                    <Col xs="auto">
916
                      <Button
917
                        color="falcon-default"
918
                        size="sm"
919
                        onClick={handlePrevPage(paginationProps)}
920
                        disabled={paginationProps.page === 1}
921
                      >
922
                        <FontAwesomeIcon icon="chevron-left" />
923
                      </Button>
924
                      {getPaginationArray(paginationProps.totalSize, paginationProps.sizePerPage).map(pageNo => (
925
                        <Button
926
                          color={paginationProps.page === pageNo ? 'falcon-primary' : 'falcon-default'}
927
                          size="sm"
928
                          className="ml-2"
929
                          onClick={() => paginationProps.onPageChange(pageNo)}
930
                          key={pageNo}
931
                        >
932
                          {pageNo}
933
                        </Button>
934
                      ))}
935
                      <Button
936
                        color="falcon-default"
937
                        size="sm"
938
                        className="ml-2"
939
                        onClick={handleNextPage(paginationProps)}
940
                        disabled={lastIndex >= paginationProps.totalSize}
941
                      >
942
                        <FontAwesomeIcon icon="chevron-right" />
943
                      </Button>
944
                    </Col>
945
                  </Row>
946
                </Fragment>
947
              );
948
            }}
949
          </PaginationProvider>
950
        </CardBody>
951
      </Card>
952
953
    </Fragment>
954
  );
955
};
956
957
export default withTranslation()(withRedirect(CombinedEquipmentFault));
958