Passed
Push — development ( 2f9cbb...cdc56b )
by Peter
09:24 queued 15s
created

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

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 58
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 58
ccs 8
cts 10
cp 0.8
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  
B AllBikes.tsx ➔ AllBikes 0 47 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,  Zone } 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
11
12
export default function AllBikes() {
13 1
    const [scooterData, setScooterData] = useState<Scooter[]>([]);
14 2
    const { token } = useSelector((state: RootState) =>  state.auth);
15
16 1
    useEffect(() => {
17 1
        const fetchScooters = async() => {
18 1
        try {
19 1
                const response = await axios.get(`${API_URL}/bike`, getHeader(token));
20
                setScooterData(response.data);
21
            }
22
            catch(error)
23
            {
24
            }
25
      }
26 1
      fetchScooters();
27
      },[])
28
    
29
  
30 1
  return (
31
            <div data-testid="all-scooter-list" className="mt-4 bg-gray-600 rounded">
32
                <AdminGate/>
33
                <h2 className="text-xl font-bold mb-2">Alla cyklar</h2>
34
                {scooterData.length > 0 ? (
35
                    <div>
36
                    <h2>Antal cyklar: {scooterData.length} </h2>
37
                    <ul className="list-disc pl-6 list-none">
38
                        {scooterData.map((scooter) => (
39
                            <li key={scooter.id} className="mb-2">
40
                                <div className="mt-4 p-6 mx-auto w-1/2 hover:opacity-5 bg-gray-400 rounded text-center">
41
                                <h2><span className="font-semibold">ID:</span> {scooter.id} -{" "}</h2>
42
                                <span className="font-semibold">City:</span> {scooter.city} -{" "}
43
                                <span className="font-semibold">createdAt:</span> {scooter.createdAt} -{" "}
44
                                <span className="font-semibold">updatedAt:</span> {scooter.updatedAt} -{" "}
45
                                <span className="font-semibold">Batteri:</span> {scooter.batteryLevel}% -{" "}
46
                                <span className="font-semibold">Status:</span> {scooter.status} -{" "}
47
                                <span className="font-semibold">Longitud:</span> {scooter.longitude} -{" "}
48
                                <span className="font-semibold">Latitud:</span> {scooter.latitude}
49
                                </div>
50
                            </li>
51
                        ))}
52
                        </ul>
53
                    </div>) : (
54
                    <p>Inga cyklar tillgängliga</p>
55
                )}
56
            </div>
57
  )
58
};
59