1
1
import { HelpText } from "components/HelpText" ;
2
2
import { Upload , Switch , Card , Input , message , Divider } from "antd" ;
3
- import { TacoButton , CustomSelect , messageInstance , Dropdown } from "lowcoder-design" ;
3
+ import { TacoButton , CustomSelect , messageInstance , Dropdown , ResetIcon } from "lowcoder-design" ;
4
4
import React , { useEffect , useMemo , useState } from "react" ;
5
5
import { useSelector } from "react-redux" ;
6
6
import styled from "styled-components" ;
@@ -20,6 +20,8 @@ import { buildMaterialPreviewURL } from "@lowcoder-ee/util/materialUtils";
20
20
import { getUser } from "@lowcoder-ee/redux/selectors/usersSelectors" ;
21
21
import { Org } from "@lowcoder-ee/constants/orgConstants" ;
22
22
import { BrandingConfig , BrandingSettings , createBranding , getBranding } from "@lowcoder-ee/api/enterpriseApi" ;
23
+ import Flex from "antd/es/flex" ;
24
+ import Button from "antd/es/button" ;
23
25
24
26
const { TextArea } = Input ;
25
27
@@ -169,6 +171,7 @@ export function BrandingSetting() {
169
171
const [ configOrgId , setConfigOrgId ] = useState < string > ( '' ) ;
170
172
const [ settings , setSettings ] = useState < BrandingSettings > ( defaultSettings ) ;
171
173
const [ brandingConfig , setBrandingConfig ] = useState < BrandingConfig > ( ) ;
174
+ const [ defaultBrandingConfig , setDefaultBrandingConfig ] = useState < BrandingConfig > ( ) ;
172
175
const [ loading , setLoading ] = useState ( {
173
176
[ SettingsEnum . LOGO ] : false ,
174
177
[ SettingsEnum . SQUARE_LOGO ] : false ,
@@ -197,14 +200,23 @@ export function BrandingSetting() {
197
200
try {
198
201
const branding = await getBranding ( configOrgId ) ;
199
202
setBrandingConfig ( branding ) ;
203
+ setDefaultBrandingConfig ( branding ) ;
200
204
} catch ( e ) {
201
205
setBrandingConfig ( undefined ) ;
206
+ setDefaultBrandingConfig ( undefined ) ;
202
207
}
203
208
}
204
209
205
210
fetchBrandingDetails ( ) ;
206
211
} , [ configOrgId ] ) ;
207
212
213
+ const isBrandingNotChange = ( ) => {
214
+ return (
215
+ JSON . stringify ( { ...brandingConfig } ) ===
216
+ JSON . stringify ( { ...defaultBrandingConfig } )
217
+ ) ;
218
+ }
219
+
208
220
const updateSettings = ( key : keyof BrandingSettings , value : any ) => {
209
221
setBrandingConfig ( ( branding ) => ( {
210
222
...branding ,
@@ -247,10 +259,16 @@ export function BrandingSetting() {
247
259
}
248
260
249
261
const handleSave = async ( ) => {
250
- const response = await createBranding ( {
251
- ...brandingConfig ,
252
- org_id : configOrgId ,
253
- } ) ;
262
+ try {
263
+ await createBranding ( {
264
+ ...brandingConfig ,
265
+ org_id : configOrgId ,
266
+ } ) ;
267
+ setDefaultBrandingConfig ( brandingConfig ) ;
268
+ messageInstance . success ( trans ( "theme.saveSuccessMsg" ) ) ;
269
+ } catch ( e ) {
270
+ console . error ( e )
271
+ }
254
272
}
255
273
256
274
const uploadButton = ( loading : boolean ) => (
@@ -719,13 +737,24 @@ export function BrandingSetting() {
719
737
) }
720
738
</ Card >
721
739
</ BrandingSettingContent >
722
-
723
- < TacoButton
724
- onClick = { handleSave }
725
- style = { { marginTop : 20 } }
726
- >
727
- { trans ( "branding.saveButton" ) }
728
- </ TacoButton >
740
+
741
+ < Flex gap = { 10 } style = { { marginTop : 20 } } >
742
+ < TacoButton
743
+ buttonType = "normal"
744
+ icon = { < ResetIcon /> }
745
+ disabled = { isBrandingNotChange ( ) }
746
+ onClick = { ( ) => setBrandingConfig ( defaultBrandingConfig ) }
747
+ >
748
+ { trans ( "reset" ) }
749
+ </ TacoButton >
750
+ < TacoButton
751
+ buttonType = "primary"
752
+ disabled = { isBrandingNotChange ( ) }
753
+ onClick = { handleSave }
754
+ >
755
+ { trans ( "branding.saveButton" ) }
756
+ </ TacoButton >
757
+ </ Flex >
729
758
</ DetailContent >
730
759
</ DetailContainer >
731
760
) ;
0 commit comments