1
1
import type React from 'react' ;
2
- import { Fragment , useState } from 'react' ;
2
+ import { Fragment } from 'react' ;
3
3
import styled from '@emotion/styled' ;
4
4
import Color from 'color' ;
5
5
6
- import { Button } from 'sentry/components/core/button' ;
7
- import { ButtonBar } from 'sentry/components/core/button/buttonBar' ;
8
6
import { Input } from 'sentry/components/core/input' ;
9
7
import { Flex , Grid } from 'sentry/components/core/layout' ;
10
8
import { Radio } from 'sentry/components/core/radio' ;
@@ -27,8 +25,6 @@ import type {SelectableProduct} from 'getsentry/views/amCheckout/types';
27
25
import { displayPrice , displayPriceWithCents } from 'getsentry/views/amCheckout/utils' ;
28
26
import { convertOnDemandBudget } from 'getsentry/views/onDemandBudgets/utils' ;
29
27
30
- const SUGGESTED_SPENDING_CAPS = [ 300_00 , 500_00 , 1_000_00 , 10_000_00 ] ;
31
-
32
28
type PartialSpendCapUpdate = Partial < Record < DataCategory , number > > & {
33
29
sharedMaxBudget ?: number ;
34
30
} ;
@@ -45,13 +41,7 @@ interface SpendCapSettingsProps {
45
41
currentReserved : Partial < Record < DataCategory , number > > ;
46
42
header : React . ReactNode ;
47
43
onDemandBudgets : OnDemandBudgets ;
48
- onUpdate : ( {
49
- onDemandBudgets,
50
- fromButton,
51
- } : {
52
- onDemandBudgets : OnDemandBudgets ;
53
- fromButton ?: boolean ;
54
- } ) => void ;
44
+ onUpdate : ( { onDemandBudgets} : { onDemandBudgets : OnDemandBudgets } ) => void ;
55
45
isOpen ?: boolean ;
56
46
}
57
47
@@ -72,13 +62,7 @@ interface SpendCapInputProps extends Pick<SpendCapSettingsProps, 'activePlan'> {
72
62
budgetMode : OnDemandBudgetMode ;
73
63
category : DataCategory | null ;
74
64
currentSpendingCap : number ;
75
- onUpdate : ( {
76
- newData,
77
- fromButton,
78
- } : {
79
- newData : PartialSpendCapUpdate ;
80
- fromButton ?: boolean ;
81
- } ) => void ;
65
+ onUpdate : ( { newData} : { newData : PartialSpendCapUpdate } ) => void ;
82
66
reserved : number | null ;
83
67
}
84
68
@@ -129,9 +113,6 @@ function SpendCapInput({
129
113
category,
130
114
reserved,
131
115
} : SpendCapInputProps ) {
132
- const [ selectedButton , setSelectedButton ] = useState < string | null > (
133
- `button-${ currentSpendingCap } `
134
- ) ;
135
116
// category and reserved should never be null for per category but this makes TS happy
136
117
const isPerCategory =
137
118
budgetMode === OnDemandBudgetMode . PER_CATEGORY &&
@@ -158,50 +139,23 @@ function SpendCapInput({
158
139
} ;
159
140
160
141
return (
161
- < Flex align = "center" justify = "start" gap = "md" >
162
- < ButtonBar merged gap = "0" >
163
- { SUGGESTED_SPENDING_CAPS . map ( cap => {
164
- const isSelected = selectedButton === `button-${ cap } ` ;
165
- const formattedCap = displayPrice ( { cents : cap } ) ;
166
- return (
167
- < StyledButton
168
- key = { cap }
169
- onClick = { ( ) => {
170
- setSelectedButton ( `button-${ cap } ` ) ;
171
- onUpdate ( {
172
- newData : { [ inputName ] : cap } ,
173
- fromButton : true ,
174
- } ) ;
175
- } }
176
- aria-checked = { isSelected }
177
- isSelected = { isSelected }
178
- aria-label = { t ( '%s suggested %s spending cap' , formattedCap , displayName ) }
179
- >
180
- { formattedCap }
181
- </ StyledButton >
182
- ) ;
183
- } ) }
184
- </ ButtonBar >
185
- < Currency >
186
- < StyledInput
187
- aria-label = { t ( 'Custom %s spending cap' , displayName ) }
188
- name = { `spending-cap-${ inputName } ` }
189
- type = "text"
190
- inputMode = "numeric"
191
- pattern = "[0-9]*"
192
- placeholder = "300"
193
- value = { coerceValue ( currentSpendingCap ) }
194
- onChange = { ( e : React . ChangeEvent < HTMLInputElement > ) => {
195
- const parsedBudget = parseInputValue ( e ) ;
196
- onUpdate ( {
197
- newData : { [ inputName ] : parsedBudget } ,
198
- fromButton : false ,
199
- } ) ;
200
- setSelectedButton ( `button-${ parsedBudget } ` ) ;
201
- } }
202
- />
203
- </ Currency >
204
- </ Flex >
142
+ < Currency >
143
+ < StyledInput
144
+ aria-label = { t ( 'Custom %s spending cap' , displayName ) }
145
+ name = { `spending-cap-${ inputName } ` }
146
+ type = "text"
147
+ inputMode = "numeric"
148
+ pattern = "[0-9]*"
149
+ placeholder = "300"
150
+ value = { coerceValue ( currentSpendingCap ) }
151
+ onChange = { ( e : React . ChangeEvent < HTMLInputElement > ) => {
152
+ const parsedBudget = parseInputValue ( e ) ;
153
+ onUpdate ( {
154
+ newData : { [ inputName ] : parsedBudget } ,
155
+ } ) ;
156
+ } }
157
+ />
158
+ </ Currency >
205
159
) ;
206
160
}
207
161
@@ -328,13 +282,7 @@ function InnerSpendCapSettings({
328
282
currentReserved,
329
283
additionalProducts,
330
284
} : InnerSpendCapSettingsProps ) {
331
- const handleUpdate = ( {
332
- newData,
333
- fromButton,
334
- } : {
335
- newData : PartialSpendCapUpdate ;
336
- fromButton ?: boolean ;
337
- } ) => {
285
+ const handleUpdate = ( { newData} : { newData : PartialSpendCapUpdate } ) => {
338
286
if ( onDemandBudgets . budgetMode === OnDemandBudgetMode . PER_CATEGORY ) {
339
287
onUpdate ( {
340
288
onDemandBudgets : {
@@ -344,15 +292,13 @@ function InnerSpendCapSettings({
344
292
...newData ,
345
293
} ,
346
294
} ,
347
- fromButton,
348
295
} ) ;
349
296
} else {
350
297
onUpdate ( {
351
298
onDemandBudgets : {
352
299
...onDemandBudgets ,
353
300
...newData ,
354
301
} ,
355
- fromButton,
356
302
} ) ;
357
303
}
358
304
} ;
@@ -673,14 +619,6 @@ const ExampleContainer = styled('div')`
673
619
}
674
620
` ;
675
621
676
- // TODO(isabella): fix text color
677
- const StyledButton = styled ( Button ) < { isSelected : boolean } > `
678
- color: ${ p => ( p . isSelected ? p . theme . activeText : p . theme . gray500 ) } ;
679
- &:hover {
680
- color: ${ p => p . theme . activeText } ;
681
- }
682
- ` ;
683
-
684
622
const StyledInput = styled ( Input ) `
685
623
width: 124px;
686
624
text-align: right;
0 commit comments