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

Complexity

Total Complexity 8
Complexity/F 8

Size

Lines of Code 52
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
eloc 44
dl 0
loc 52
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0
wmc 8
mnd 7
bc 7
fnc 1
bpm 7
cpm 8
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B AllBikes.tsx ➔ AllBikes 0 40 8
1
2
import { useEffect, useState } from 'react';
3
4
import { API_URL, getHeader} from '../../helpers/config';
5
import axios, {AxiosError} from 'axios';
6
import { Scooter } from '../../helpers/bike-functions';
7
import { RootState } from '../../redux/store/store';
8
import { useSelector } from 'react-redux';
9
import AdminGate from '../../components/AdminGate';
10
import BikeList from '../../components/BikeList';
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 4
                if (error instanceof AxiosError && error.response?.data?.message) {
25
                    console.log(error.response?.data?.messag)
26
                }
27
            }
28
      }
29 1
      fetchScooters();
30
      },[token])
31
    
32
  
33 1
  return (
34
            <div data-testid="all-scooter-list" className="p-4 flex flex-col justify-center w-full">
35
                <AdminGate/>
36
                <div className="mx-auto">
37
                <h2 className="text-4xl font-bold text-gray-900"> Alla cyklar </h2>
38
                </div>
39
                {scooterData.length > 0 ? (
40
                    <>
41
                        <div className="mx-auto mb-5">
42
                            <h2>Antal cyklar: <b>{scooterData.length}</b> </h2>
43
                        </div>
44
                        <BikeList scooterData={scooterData} isCityList={true}/>
45
                    </>) : (
46
                        <div className="mx-auto mb-5">
47
                            <p>Inga cyklar tillgängliga</p>
48
                        </div>
49
                )}
50
            </div>
51
  )
52
};
53