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

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

Complexity

Total Complexity 15
Complexity/F 0

Size

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