@@ -3,26 +3,28 @@ import { ValidateFieldsError } from 'async-validator';
3
3
4
4
import { Button , Checkbox , MenuItem } from '@mui/material' ;
5
5
import SaveIcon from '@mui/icons-material/Save' ;
6
+ import CancelIcon from '@mui/icons-material/Cancel' ;
6
7
7
8
import { validate } from '../../validators' ;
8
9
import { BlockFormControlLabel , ButtonRow , FormLoader , SectionContent , ValidatedTextField } from '../../components' ;
9
10
import { NTPSettings } from '../../types' ;
10
- import { updateValue , useRest } from '../../utils' ;
11
+ import { updateValueDirty , useRest } from '../../utils' ;
11
12
import * as NTPApi from '../../api/ntp' ;
12
13
import { selectedTimeZone , timeZoneSelectItems , TIME_ZONES } from './TZ' ;
13
14
import { NTP_SETTINGS_VALIDATOR } from '../../validators/ntp' ;
14
15
15
16
import { useI18nContext } from '../../i18n/i18n-react' ;
16
17
17
18
const NTPSettingsForm : FC = ( ) => {
18
- const { loadData, saving, data, setData, saveData, errorMessage } = useRest < NTPSettings > ( {
19
- read : NTPApi . readNTPSettings ,
20
- update : NTPApi . updateNTPSettings
21
- } ) ;
19
+ const { loadData, saving, data, setData, origData, dirtyFlags, setDirtyFlags, saveData, errorMessage } =
20
+ useRest < NTPSettings > ( {
21
+ read : NTPApi . readNTPSettings ,
22
+ update : NTPApi . updateNTPSettings
23
+ } ) ;
22
24
23
25
const { LL } = useI18nContext ( ) ;
24
26
25
- const updateFormValue = updateValue ( setData ) ;
27
+ const updateFormValue = updateValueDirty ( origData , dirtyFlags , setDirtyFlags , setData ) ;
26
28
27
29
const [ fieldErrors , setFieldErrors ] = useState < ValidateFieldsError > ( ) ;
28
30
@@ -79,18 +81,30 @@ const NTPSettingsForm: FC = () => {
79
81
< MenuItem disabled > { LL . TIME_ZONE ( ) } ...</ MenuItem >
80
82
{ timeZoneSelectItems ( ) }
81
83
</ ValidatedTextField >
82
- < ButtonRow >
83
- < Button
84
- startIcon = { < SaveIcon /> }
85
- disabled = { saving }
86
- variant = "outlined"
87
- color = "primary"
88
- type = "submit"
89
- onClick = { validateAndSubmit }
90
- >
91
- { LL . SAVE ( ) }
92
- </ Button >
93
- </ ButtonRow >
84
+ { dirtyFlags && dirtyFlags . length !== 0 && (
85
+ < ButtonRow >
86
+ < Button
87
+ startIcon = { < CancelIcon /> }
88
+ disabled = { saving }
89
+ variant = "outlined"
90
+ color = "primary"
91
+ type = "submit"
92
+ onClick = { ( ) => loadData ( ) }
93
+ >
94
+ { LL . CANCEL ( ) }
95
+ </ Button >
96
+ < Button
97
+ startIcon = { < SaveIcon /> }
98
+ disabled = { saving }
99
+ variant = "outlined"
100
+ color = "primary"
101
+ type = "submit"
102
+ onClick = { validateAndSubmit }
103
+ >
104
+ { LL . APPLY_CHANGES ( dirtyFlags . length ) }
105
+ </ Button >
106
+ </ ButtonRow >
107
+ ) }
94
108
</ >
95
109
) ;
96
110
} ;
0 commit comments