Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 7495b9eb

Přidáno uživatelem plundrichov před více než 4 roky(ů)

re #58 refactoring (api - app, calendar)

Zobrazit rozdíly:

client/src/App.js
12 12
// import Komponenta1 from './Komponenta1';
13 13
// import Komponenta2 from './Komponenta2';
14 14
import { BrowserRouter, Route, Switch } from "react-router-dom";
15
import * as api_fetch from './api'
15 16

  
16 17
function App() {
17 18

  
18
  useEffect( () => {
19
    getData();
19
  useEffect(() => {
20
    api_fetch.getCurrentProfile().then(currentProfile => {
21
    setUserName(currentProfile);
22
    });
20 23
  }, []);
21 24

  
22
  const getData = async () => {
23
    try {
24
    const response = await fetch(
25
      'http://devcz.yoso.fi:8090/ymanager/users/current/profile', {
26
        headers: {
27
          Authorization: 1
28
        }
29
      }
30
    );
31

  
32
    if (response.ok) {
33
    const data = await response.json();
34
    setUserName({
35
      name: data.firstName + ' ' + data.lastName,
36
      role: data.role,
37
      id: data.id,
38
      holiday: data.vacationCount,
39
      sickday: data.sickDayCount
40
    })
41
  } else {
42
    if(response.status === 400) {
43
      alert('error 400 GET DATA APP')
44
   }
45
      else if (response.status === 500) {
46
         alert ('error 500 GET DATA APP')
47
      }
48
      else {
49
         alert('error GET DATA APP')
50
      }
51
  }
52
} catch (e) {
53
  console.log(e)
54
  alert('error catch GET DATA APP')
55
  }
56
}
57 25

  
58 26
  const [userName, setUserName] = useState([
59 27
    {

Také k dispozici: Unified diff