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

frontend/src/pages/admin/AllBikes.tsx   A

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 51
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 51
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0
wmc 3
mnd 2
bc 2
fnc 1
bpm 2
cpm 3
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A AllBikes.tsx ➔ AllBikes 0 38 3
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