Passed
Push — development ( 8e8ffd...1af938 )
by Peter
18:46 queued 06:25
created

AllBikes.tsx ➔ AllBikes   A

Complexity

Conditions 3

Size

Total Lines 38
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.0123

Importance

Changes 0
Metric Value
cc 3
eloc 32
dl 0
loc 38
ccs 8
cts 9
cp 0.8889
crap 3.0123
rs 9.112
c 0
b 0
f 0
1
2
import { useEffect, useState } from 'react';
3
4
import { API_URL, getHeader} from '../../helpers/config';
5
import axios from 'axios';
6
import { Scooter } from '../../helpers/map/leaflet-types'
7
import { RootState } from '../../redux/store/store';
8
import { useSelector } from 'react-redux';
9
import AdminGate from '../../components/AdminGate';
10
import { Badge } from 'flowbite-react';
11
import BikeList from '../../components/BikeList';
12
13
14
export default function AllBikes() {
15 1
    const [scooterData, setScooterData] = useState<Scooter[]>([]);
16 2
    const { token } = useSelector((state: RootState) =>  state.auth);
17
18 1
    useEffect(() => {
19 1
        const fetchScooters = async() => {
20 1
        try {
21 1
                const response = await axios.get(`${API_URL}/bike`, getHeader(token));
22
                setScooterData(response.data);
23
            }
24
            catch(error)
25
            {
26
            }
27
      }
28 1
      fetchScooters();
29
      },[])
30
    
31
  
32 1
  return (
33
            <div data-testid="all-scooter-list" className="p-4 flex flex-col justify-center w-full">
34
                <AdminGate/>
35
                <div className="mx-auto">
36
                <h2 className="text-4xl font-bold text-gray-900"> Alla cyklar </h2>
37
                </div>
38
                {scooterData.length > 0 ? (
39
                    <>
40
                        <div className="mx-auto mb-5">
41
                            <h2>Antal cyklar: <b>{scooterData.length}</b> </h2>
42
                        </div>
43
                        <BikeList scooterData={scooterData} isCityList={true}/>
44
                    </>) : (
45
                        <div className="mx-auto mb-5">
46
                            <p>Inga cyklar tillgängliga</p>
47
                        </div>
48
                )}
49
            </div>
50
  )
51
};
52