Passed
Push — master ( c5d2bd...711ecf )
by Guangyu
04:54 queued 11s
created

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

Complexity

Total Complexity 15
Complexity/F 0

Size

Lines of Code 899
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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