@@ -14,6 +14,12 @@ import {
1414
1515import { useSelect } from '@wordpress/data' ;
1616
17+ import { Icon , chevronDown , chevronUp } from '@wordpress/icons' ;
18+
19+ import {
20+ useState
21+ } from '@wordpress/element' ;
22+
1723/**
1824 * Internal dependencies.
1925 */
@@ -38,11 +44,19 @@ const General = ({
3844 const isReportEnabled = 'disabled' !== settings [ 'report_script' ] ;
3945 const isAssetsEnabled = 'disabled' !== settings . cdn ;
4046 const isBannerEnabled = 'disabled' !== settings [ 'banner_frontend' ] ;
47+ const isShowBadgeIcon = 'disabled' !== settings [ 'show_badge_icon' ] ;
48+ const activeBadgePosition = settings [ 'badge_position' ] || 'right' ;
49+
50+ const [ showBadgeSettings , setBadgeSettings ] = useState ( isBannerEnabled ) ;
4151
4252 const updateOption = ( option , value ) => {
4353 setCanSave ( true ) ;
4454 const data = { ...settings } ;
45- data [ option ] = value ? 'enabled' : 'disabled' ;
55+ if ( 'badge_position' === option ) {
56+ data [ option ] = value ;
57+ } else {
58+ data [ option ] = value ? 'enabled' : 'disabled' ;
59+ }
4660 setSettings ( data ) ;
4761 } ;
4862
@@ -103,9 +117,77 @@ const General = ({
103117 'is-disabled' : isLoading
104118 }
105119 ) }
106- onChange = { value => updateOption ( 'banner_frontend' , value ) }
120+ onChange = { ( value ) => {
121+ updateOption ( 'banner_frontend' , value ) ;
122+ setBadgeSettings ( value ) ;
123+ } }
107124 />
108125
126+ { isBannerEnabled && (
127+ < div className = "mt-4 badge-settings" >
128+ < Button
129+ className = { classnames (
130+ 'border border-none bg-transparent text-blue-500 px-2 py-1 rounded-sm flex items-center cursor-pointer' ,
131+ {
132+ 'is-disabled' : isLoading
133+ }
134+ ) }
135+ onClick = { ( ) => setBadgeSettings ( ! showBadgeSettings ) }
136+ >
137+ < span > { optimoleDashboardApp . strings . options_strings . enable_badge_settings } </ span >
138+ < Icon
139+ icon = { showBadgeSettings ? chevronUp : chevronDown }
140+ className = "h-5 w-5"
141+ style = { { fill : '#3b82f6' } }
142+ />
143+ </ Button >
144+ { showBadgeSettings && (
145+ < div class = "mt-4 space-y-4 pl-4 pt-2" >
146+ < div class = "flex items-center justify-between mb-4" >
147+ < label class = "text-gray-600 font-medium" > { optimoleDashboardApp . strings . options_strings . enable_badge_show_icon } </ label >
148+ < ToggleControl
149+ label = ""
150+ checked = { isShowBadgeIcon }
151+ disabled = { isLoading }
152+ className = { classnames (
153+ 'flex items-center justify-between mb-4' ,
154+ {
155+ 'is-disabled' : isLoading
156+ }
157+ ) }
158+ onChange = { value => updateOption ( 'show_badge_icon' , value ) }
159+ />
160+ </ div >
161+ < div class = "flex items-center justify-between" >
162+ < label class = "text-gray-600 font-medium" > { optimoleDashboardApp . strings . options_strings . enable_badge_position } </ label >
163+ < div class = "flex space-x-2" >
164+ < Button
165+ className = { classnames (
166+ 'px-4 py-2 border rounded border-[1px]' ,
167+ 'left' === activeBadgePosition ? 'border-blue-500 text-blue-500 bg-blue-100' : 'border-gray-300 text-gray-500 bg-gray-100' ,
168+ {
169+ 'is-disabled' : isLoading
170+ }
171+ ) }
172+ onClick = { ( ) => updateOption ( 'badge_position' , 'left' ) }
173+ > { optimoleDashboardApp . strings . options_strings . badge_position_text_1 } </ Button >
174+ < Button
175+ className = { classnames (
176+ 'px-4 py-2 border rounded' ,
177+ 'right' === activeBadgePosition ? 'border-blue-500 text-blue-500 bg-blue-100' : 'border-gray-300 text-gray-500 bg-gray-100' ,
178+ {
179+ 'is-disabled' : isLoading
180+ }
181+ ) }
182+ onClick = { ( ) => updateOption ( 'badge_position' , 'right' ) }
183+ > { optimoleDashboardApp . strings . options_strings . badge_position_text_2 } </ Button >
184+ </ div >
185+ </ div >
186+ </ div >
187+ ) }
188+ </ div >
189+ ) }
190+
109191 < hr className = "my-8 border-grayish-blue" />
110192
111193 < BaseControl
0 commit comments