src/components/MyEMS/FDD/ShopfloorFault.js   A
last analyzed

Complexity

Total Complexity 15
Complexity/F 0

Size

Lines of Code 959
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 15
eloc 847
mnd 15
bc 15
fnc 0
dl 0
loc 959
rs 9.753
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 { 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 ButtonIcon from '../../common/ButtonIcon';
39
import { APIBaseURL } from '../../../config';
40
41
42
const ShopfloorFault = ({ 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 [shopfloorList, setShopfloorList] = useState([]);
67
  const [selectedShopfloor, setSelectedShopfloor] = 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 Shopfloors by root Space ID
108
        let isResponseOK = false;
109
        fetch(APIBaseURL + '/spaces/' + [json[0]].map(o => o.value) + '/shopfloors', {
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
            setShopfloorList(json[0]);
128
            if (json[0].length > 0) {
129
              setSelectedShopfloor(json[0][0].value);
130
              // enable submit button
131
              setSubmitButtonDisabled(false);
132
            } else {
133
              setSelectedShopfloor(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 Shopfloors by root Space ID
144
      } else {
145
        toast.error(json.description);
146
      }
147
    }).catch(err => {
148
      console.log(err);
149
    });
150
151
  }, []);
152
  const orderFormatter = (dataField, { id, name, email }) => (
153
    <Fragment>
154
      <Link to="/e-commerce/order-details">
155
        <strong>#{id}</strong>
156
      </Link>{' '}
157
      by <strong>{name}</strong>
158
      <br />
159
      <a href={`mailto:${email}`}>{email}</a>
160
    </Fragment>
161
  );
162
163
  const shippingFormatter = (address, { shippingType }) => (
164
    <Fragment>
165
      {address}
166
      <p className="mb-0 text-500">{shippingType}</p>
167
    </Fragment>
168
  );
169
170
  const badgeFormatter = status => {
171
    let color = '';
172
    let icon = '';
173
    let text = '';
174
    switch (status) {
175
      case 'success':
176
        color = 'success';
177
        icon = 'check';
178
        text = 'Completed';
179
        break;
180
      case 'hold':
181
        color = 'secondary';
182
        icon = 'ban';
183
        text = 'On hold';
184
        break;
185
      case 'processing':
186
        color = 'primary';
187
        icon = 'redo';
188
        text = 'Processing';
189
        break;
190
      case 'pending':
191
        color = 'warning';
192
        icon = 'stream';
193
        text = 'Pending';
194
        break;
195
      default:
196
        color = 'warning';
197
        icon = 'stream';
198
        text = 'Pending';
199
    }
200
201
    return (
202
      <Badge color={`soft-${color}`} className="rounded-capsule fs--1 d-block">
203
        {text}
204
        <FontAwesomeIcon icon={icon} transform="shrink-2" className="ml-1" />
205
      </Badge>
206
    );
207
  };
208
209
  const actionFormatter = (dataField, { id }) => (
210
    // Control your row with this id
211
    <UncontrolledDropdown>
212
      <DropdownToggle color="link" size="sm" className="text-600 btn-reveal mr-3">
213
        <FontAwesomeIcon icon="ellipsis-h" className="fs--1" />
214
      </DropdownToggle>
215
      <DropdownMenu right className="border py-2">
216
        <DropdownItem onClick={() => console.log('Completed: ', id)}>Completed</DropdownItem>
217
        <DropdownItem onClick={() => console.log('Processing: ', id)}>Processing</DropdownItem>
218
        <DropdownItem onClick={() => console.log('On hold: ', id)}>On hold</DropdownItem>
219
        <DropdownItem onClick={() => console.log('Pending: ', id)}>Pending</DropdownItem>
220
        <DropdownItem divider />
221
        <DropdownItem onClick={() => console.log('Delete: ', id)} className="text-danger">
222
          Delete
223
        </DropdownItem>
224
      </DropdownMenu>
225
    </UncontrolledDropdown>
226
  );
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
  // State
262
  let table = createRef();
263
264
  const [isSelected, setIsSelected] = useState(false);
265
  const handleNextPage = ({ page, onPageChange }) => () => {
266
    onPageChange(page + 1);
267
  };
268
269
  const handlePrevPage = ({ page, onPageChange }) => () => {
270
    onPageChange(page - 1);
271
  };
272
273
  const onSelect = () => {
274
    setImmediate(() => {
275
      setIsSelected(!!table.current.selectionContext.selected.length);
276
    });
277
  };
278
279
  let onSpaceCascaderChange = (value, selectedOptions) => {
280
    setSelectedSpaceName(selectedOptions.map(o => o.label).join('/'));
281
    setSelectedSpaceID(value[value.length - 1]);
282
283
    let isResponseOK = false;
284
    fetch(APIBaseURL + '/spaces/' + value[value.length - 1] + '/shopfloors', {
285
      method: 'GET',
286
      headers: {
287
        "Content-type": "application/json",
288
        "User-UUID": getCookieValue('user_uuid'),
289
        "Token": getCookieValue('token')
290
      },
291
      body: null,
292
293
    }).then(response => {
294
      if (response.ok) {
295
        isResponseOK = true;
296
      }
297
      return response.json();
298
    }).then(json => {
299
      if (isResponseOK) {
300
        json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
301
        console.log(json)
302
        setShopfloorList(json[0]);
303
        if (json[0].length > 0) {
304
          setSelectedShopfloor(json[0][0].value);
305
          // enable submit button
306
          setSubmitButtonDisabled(false);
307
        } else {
308
          setSelectedShopfloor(undefined);
309
          // disable submit button
310
          setSubmitButtonDisabled(true);
311
        }
312
      } else {
313
        toast.error(json.description)
314
      }
315
    }).catch(err => {
316
      console.log(err);
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(selectedShopfloor);
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/fddshopfloorfault?' +
356
      'shopfloorid' + selectedShopfloor +
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
  
764
  const handleExport = e => {
765
    e.preventDefault();
766
    const mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
767
    const fileName = 'shopfloorfault.xlsx'
768
    var fileUrl = "data:" + mimeType + ";base64," + excelBytesBase64;
769
    fetch(fileUrl)
770
        .then(response => response.blob())
771
        .then(blob => {
772
            var link = window.document.createElement("a");
773
            link.href = window.URL.createObjectURL(blob, { type: mimeType });
774
            link.download = fileName;
775
            document.body.appendChild(link);
776
            link.click();
777
            document.body.removeChild(link);
778
        });
779
  };
780
  
781
782
783
  return (
784
    <Fragment>
785
      <div>
786
        <Breadcrumb>
787
          <BreadcrumbItem>{t('Fault Detection & Diagnostics')}</BreadcrumbItem><BreadcrumbItem active>{t('Shopfloor Faults Data')}</BreadcrumbItem>
788
        </Breadcrumb>
789
      </div>
790
      <Card className="bg-light mb-3">
791
        <CardBody className="p-3">
792
          <Form onSubmit={handleSubmit}>
793
            <Row form>
794
              <Col xs="auto">
795
                <FormGroup className="form-group">
796
                  <Label className={labelClasses} for="space">
797
                    {t('Space')}
798
                  </Label>
799
                  <br />
800
                  <Cascader options={cascaderOptions}
801
                    onChange={onSpaceCascaderChange}
802
                    changeOnSelect
803
                    expandTrigger="hover">
804
                    <Input value={selectedSpaceName || ''} readOnly />
805
                  </Cascader>
806
                </FormGroup>
807
              </Col>
808
              <Col xs="auto">
809
                <FormGroup>
810
                  <Label className={labelClasses} for="shopfloorSelect">
811
                    {t('Shopfloor')}
812
                  </Label>
813
                  <CustomInput type="select" id="shopfloorSelect" name="shopfloorSelect" onChange={({ target }) => setSelectedShopfloor(target.value)}
814
                  >
815
                    {shopfloorList.map((shopfloor, index) => (
816
                      <option value={shopfloor.value} key={shopfloor.value}>
817
                        {shopfloor.label}
818
                      </option>
819
                    ))}
820
                  </CustomInput>
821
                </FormGroup>
822
              </Col>
823
              <Col xs="auto">
824
                <FormGroup className="form-group">
825
                  <Label className={labelClasses} for="reportingPeriodBeginsDatetime">
826
                    {t('Reporting Period Begins')}
827
                  </Label>
828
                  <Datetime id='reportingPeriodBeginsDatetime'
829
                    value={reportingPeriodBeginsDatetime}
830
                    onChange={onReportingPeriodBeginsDatetimeChange}
831
                    isValidDate={getValidReportingPeriodBeginsDatetimes}
832
                    closeOnSelect={true} />
833
                </FormGroup>
834
              </Col>
835
              <Col xs="auto">
836
                <FormGroup className="form-group">
837
                  <Label className={labelClasses} for="reportingPeriodEndsDatetime">
838
                    {t('Reporting Period Ends')}
839
                  </Label>
840
                  <Datetime id='reportingPeriodEndsDatetime'
841
                    value={reportingPeriodEndsDatetime}
842
                    onChange={onReportingPeriodEndsDatetimeChange}
843
                    isValidDate={getValidReportingPeriodEndsDatetimes}
844
                    closeOnSelect={true} />
845
                </FormGroup>
846
              </Col>
847
              <Col xs="auto">
848
                <FormGroup>
849
                  <br></br>
850
                  <ButtonGroup id="submit">
851
                    <Button color="success" disabled={submitButtonDisabled} >{t('Submit')}</Button>
852
                  </ButtonGroup>
853
                </FormGroup>
854
              </Col>
855
              <Col xs="auto">
856
                <FormGroup>
857
                  <br></br>
858
                  <Spinner color="primary" hidden={spinnerHidden}  />
859
                </FormGroup>
860
              </Col>
861
              <Col xs="auto">
862
                  <br></br>
863
                  <ButtonIcon icon="external-link-alt" transform="shrink-3 down-2" color="falcon-default" 
864
                  hidden={exportButtonHidden}
865
                  onClick={handleExport} >
866
                    {t('Export')}
867
                  </ButtonIcon>
868
              </Col>
869
            </Row>
870
          </Form>
871
        </CardBody>
872
      </Card>
873
      <Card className="mb-3">
874
        <FalconCardHeader title={t('Fault List')} light={false}>
875
          {isSelected ? (
876
            <InputGroup size="sm" className="input-group input-group-sm">
877
              <CustomInput type="select" id="bulk-select">
878
                <option>Bulk actions</option>
879
                <option value="Refund">Refund</option>
880
                <option value="Delete">Delete</option>
881
                <option value="Archive">Archive</option>
882
              </CustomInput>
883
              <Button color="falcon-default" size="sm" className="ml-2">
884
                Apply
885
                </Button>
886
            </InputGroup>
887
          ) : (
888
              <Fragment>
889
                
890
              </Fragment>
891
            )}
892
        </FalconCardHeader>
893
        <CardBody className="p-0">
894
          <PaginationProvider pagination={paginationFactory(options)}>
895
            {({ paginationProps, paginationTableProps }) => {
896
              const lastIndex = paginationProps.page * paginationProps.sizePerPage;
897
898
              return (
899
                <Fragment>
900
                  <div className="table-responsive">
901
                    <BootstrapTable
902
                      ref={table}
903
                      bootstrap4
904
                      keyField="id"
905
                      data={detailedDataTableData}
906
                      columns={detailedDataTableColumns}
907
                      selectRow={selectRow(onSelect)}
908
                      bordered={false}
909
                      classes="table-dashboard table-striped table-sm fs--1 border-bottom mb-0 table-dashboard-th-nowrap"
910
                      rowClasses="btn-reveal-trigger"
911
                      headerClasses="bg-200 text-900"
912
                      {...paginationTableProps}
913
                    />
914
                  </div>
915
                  <Row noGutters className="px-1 py-3 flex-center">
916
                    <Col xs="auto">
917
                      <Button
918
                        color="falcon-default"
919
                        size="sm"
920
                        onClick={handlePrevPage(paginationProps)}
921
                        disabled={paginationProps.page === 1}
922
                      >
923
                        <FontAwesomeIcon icon="chevron-left" />
924
                      </Button>
925
                      {getPaginationArray(paginationProps.totalSize, paginationProps.sizePerPage).map(pageNo => (
926
                        <Button
927
                          color={paginationProps.page === pageNo ? 'falcon-primary' : 'falcon-default'}
928
                          size="sm"
929
                          className="ml-2"
930
                          onClick={() => paginationProps.onPageChange(pageNo)}
931
                          key={pageNo}
932
                        >
933
                          {pageNo}
934
                        </Button>
935
                      ))}
936
                      <Button
937
                        color="falcon-default"
938
                        size="sm"
939
                        className="ml-2"
940
                        onClick={handleNextPage(paginationProps)}
941
                        disabled={lastIndex >= paginationProps.totalSize}
942
                      >
943
                        <FontAwesomeIcon icon="chevron-right" />
944
                      </Button>
945
                    </Col>
946
                  </Row>
947
                </Fragment>
948
              );
949
            }}
950
          </PaginationProvider>
951
        </CardBody>
952
      </Card>
953
954
    </Fragment>
955
  );
956
};
957
958
export default withTranslation()(withRedirect(ShopfloorFault));
959