Passed
Push — master ( 669be3...4762c7 )
by Guangyu
19:25 queued 10s
created

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

Complexity

Total Complexity 15
Complexity/F 0

Size

Lines of Code 956
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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