1 |
c46ffe2f
|
plundrichov
|
import React, { useState, useEffect } from 'react';
|
2 |
|
|
import './App.css';
|
3 |
|
|
import { Link } from 'react-router-dom';
|
4 |
9f045397
|
plundrichov
|
import * as api_fetch from './api'
|
5 |
c46ffe2f
|
plundrichov
|
|
6 |
|
|
|
7 |
|
|
function Setting() {
|
8 |
|
|
|
9 |
5bedee9e
|
plundrichov
|
const [sickdays, setSickdays] = useState();
|
10 |
c46ffe2f
|
plundrichov
|
|
11 |
|
|
useEffect( () => {
|
12 |
9f045397
|
plundrichov
|
api_fetch.getSettingData().then(settingData => {
|
13 |
|
|
setSetting(settingData);
|
14 |
|
|
}).catch(reason => {
|
15 |
|
|
alert(reason)
|
16 |
|
|
})
|
17 |
c46ffe2f
|
plundrichov
|
}, []);
|
18 |
|
|
|
19 |
|
|
const submitSetting = async (e) => {
|
20 |
|
|
e.preventDefault();
|
21 |
9f045397
|
plundrichov
|
|
22 |
|
|
const dataSettingObject = {
|
23 |
|
|
"sickDayCount": Number(setting.sickday),
|
24 |
|
|
"notification": "2019/12/01 12:00:00"
|
25 |
|
|
}
|
26 |
c46ffe2f
|
plundrichov
|
|
27 |
9f045397
|
plundrichov
|
api_fetch.saveDataSetting(dataSettingObject).catch(reason => {
|
28 |
|
|
alert(reason)
|
29 |
|
|
})
|
30 |
c46ffe2f
|
plundrichov
|
}
|
31 |
9f045397
|
plundrichov
|
// states
|
32 |
c46ffe2f
|
plundrichov
|
const [setting, setSetting] = useState(
|
33 |
|
|
{sickday: 5,
|
34 |
|
|
holiday: 0
|
35 |
|
|
}
|
36 |
|
|
)
|
37 |
|
|
|
38 |
9f045397
|
plundrichov
|
//functions
|
39 |
c46ffe2f
|
plundrichov
|
function changeSickday(newValue) {
|
40 |
|
|
setSetting(
|
41 |
|
|
{sickday: newValue,
|
42 |
5bedee9e
|
plundrichov
|
holiday: 0
|
43 |
9f045397
|
plundrichov
|
})
|
44 |
c46ffe2f
|
plundrichov
|
}
|
45 |
|
|
|
46 |
|
|
return (
|
47 |
|
|
<div className="container">
|
48 |
|
|
<div className="setting-container column">
|
49 |
5bedee9e
|
plundrichov
|
<h2>Setting</h2>
|
50 |
c46ffe2f
|
plundrichov
|
<div className="underline-2"></div>
|
51 |
|
|
<form onSubmit={(e) => submitSetting(e)} className="setting-form column">
|
52 |
|
|
<label><h3>Sick days</h3></label>
|
53 |
|
|
<input onChange={(e) => changeSickday(e.target.value)} value={setting.sickday} type="number" min="0" />
|
54 |
|
|
<div className="buttons row">
|
55 |
|
|
<Link to="/"><button className="btn btn-cancel" type="submit" value="Cancel">Cancel</button></Link>
|
56 |
5bedee9e
|
plundrichov
|
<button className="btn btn-submit" type="submit" value="Submit">Save</button>
|
57 |
c46ffe2f
|
plundrichov
|
</div>
|
58 |
|
|
</form>
|
59 |
|
|
</div>
|
60 |
|
|
</div>
|
61 |
|
|
);
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
export default Setting;
|