11import React , { useState , useEffect } from 'react' ;
2- import { Input , Select , Checkbox , Space , Typography , Alert } from 'antd' ;
3- import {
4- TierDisplayFormat ,
5- DataUnit ,
6- validateTierFormat ,
2+ import { Select , Checkbox , Space , Typography , Alert } from 'antd' ;
3+ import {
4+ TierDisplayFormat ,
5+ DataUnit ,
6+ validateTierFormat ,
77 displayToFriendlyString ,
88 bytesToDisplayFormat ,
9- TIER_VALIDATION
9+ TIER_VALIDATION ,
1010} from '@app/utils/tierConversion.utils' ;
1111import { AllowedUsersTier } from '@app/types/allowedUsers.types' ;
12+ import { StyledInput } from '@app/styles/themes/reusableComponentStyles' ;
13+ import styled from 'styled-components' ;
1214
1315const { Text } = Typography ;
1416const { Option } = Select ;
@@ -21,12 +23,25 @@ interface TierEditorProps {
2123 showPrice ?: boolean ;
2224}
2325
26+ const PreviewTextWrapper = styled . div `
27+ display: flex;
28+ flex-direction: column;
29+ gap: 1rem;
30+ .ant-typography {
31+ color: var(--text-main-color);
32+ }
33+ ` ;
34+ const SelectWrapper = styled . div `
35+ .ant-select-arrow {
36+ color: var(--text-main-color);
37+ }
38+ `
2439export const TierEditor : React . FC < TierEditorProps > = ( {
2540 tier,
2641 onTierChange,
2742 disabled = false ,
2843 showName = true ,
29- showPrice = true
44+ showPrice = true ,
3045} ) => {
3146 // Convert backend format to display format for editing
3247 const [ displayFormat , setDisplayFormat ] = useState < TierDisplayFormat > ( ( ) => {
@@ -49,34 +64,39 @@ export const TierEditor: React.FC<TierEditorProps> = ({
4964 const updatedTier : AllowedUsersTier = {
5065 name,
5166 price_sats : priceSats ,
52- monthly_limit_bytes : displayFormat . unlimited ? 0 :
53- Math . round ( displayFormat . value * getUnitMultiplier ( displayFormat . unit ) ) ,
54- unlimited : displayFormat . unlimited
67+ monthly_limit_bytes : displayFormat . unlimited
68+ ? 0
69+ : Math . round ( displayFormat . value * getUnitMultiplier ( displayFormat . unit ) ) ,
70+ unlimited : displayFormat . unlimited ,
5571 } ;
5672 onTierChange ( updatedTier ) ;
5773 }
5874 } , [ displayFormat , name , priceSats , isValid , onTierChange ] ) ;
5975
6076 const getUnitMultiplier = ( unit : DataUnit ) : number => {
6177 switch ( unit ) {
62- case 'MB' : return 1048576 ; // 1024 * 1024
63- case 'GB' : return 1073741824 ; // 1024 * 1024 * 1024
64- case 'TB' : return 1099511627776 ; // 1024 * 1024 * 1024 * 1024
65- default : return 1048576 ;
78+ case 'MB' :
79+ return 1048576 ; // 1024 * 1024
80+ case 'GB' :
81+ return 1073741824 ; // 1024 * 1024 * 1024
82+ case 'TB' :
83+ return 1099511627776 ; // 1024 * 1024 * 1024 * 1024
84+ default :
85+ return 1048576 ;
6686 }
6787 } ;
6888
6989 const handleValueChange = ( value : string ) => {
7090 const numericValue = parseFloat ( value ) || 0 ;
71- setDisplayFormat ( prev => ( { ...prev , value : numericValue } ) ) ;
91+ setDisplayFormat ( ( prev ) => ( { ...prev , value : numericValue } ) ) ;
7292 } ;
7393
7494 const handleUnitChange = ( unit : DataUnit ) => {
75- setDisplayFormat ( prev => ( { ...prev , unit } ) ) ;
95+ setDisplayFormat ( ( prev ) => ( { ...prev , unit } ) ) ;
7696 } ;
7797
7898 const handleUnlimitedChange = ( unlimited : boolean ) => {
79- setDisplayFormat ( prev => ( { ...prev , unlimited } ) ) ;
99+ setDisplayFormat ( ( prev ) => ( { ...prev , unlimited } ) ) ;
80100 } ;
81101
82102 const handleNameChange = ( value : string ) => {
@@ -94,7 +114,7 @@ export const TierEditor: React.FC<TierEditorProps> = ({
94114 { showName && (
95115 < div >
96116 < Text strong > Tier Name</ Text >
97- < Input
117+ < StyledInput
98118 value = { name }
99119 onChange = { ( e ) => handleNameChange ( e . target . value ) }
100120 placeholder = "Enter tier name"
@@ -108,7 +128,7 @@ export const TierEditor: React.FC<TierEditorProps> = ({
108128 { showPrice && (
109129 < div >
110130 < Text strong > Price (sats)</ Text >
111- < Input
131+ < StyledInput
112132 type = "number"
113133 value = { priceSats }
114134 onChange = { ( e ) => handlePriceChange ( e . target . value ) }
@@ -123,7 +143,7 @@ export const TierEditor: React.FC<TierEditorProps> = ({
123143 { /* Data Limit */ }
124144 < div >
125145 < Text strong > Monthly Data Limit</ Text >
126-
146+
127147 { /* Unlimited Checkbox */ }
128148 < div style = { { marginTop : 8 , marginBottom : 8 } } >
129149 < Checkbox
@@ -138,7 +158,7 @@ export const TierEditor: React.FC<TierEditorProps> = ({
138158 { /* Value and Unit Inputs */ }
139159 { ! displayFormat . unlimited && (
140160 < Space . Compact style = { { width : '100%' } } >
141- < Input
161+ < StyledInput
142162 type = "number"
143163 value = { displayFormat . value || '' }
144164 onChange = { ( e ) => handleValueChange ( e . target . value ) }
@@ -147,43 +167,39 @@ export const TierEditor: React.FC<TierEditorProps> = ({
147167 min = { TIER_VALIDATION . MIN_VALUE }
148168 style = { { flex : 1 } }
149169 />
150- < Select
151- value = { displayFormat . unit }
152- onChange = { handleUnitChange }
153- disabled = { disabled }
154- style = { { width : 80 } }
155- >
156- < Option value = "MB" > MB</ Option >
157- < Option value = "GB" > GB</ Option >
158- < Option value = "TB" > TB</ Option >
159- </ Select >
170+ < SelectWrapper >
171+ < Select value = { displayFormat . unit } onChange = { handleUnitChange } disabled = { disabled } style = { { width : 80 } } >
172+ < Option value = "MB" > MB</ Option >
173+ < Option value = "GB" > GB</ Option >
174+ < Option value = "TB" > TB</ Option >
175+ </ Select >
176+ </ SelectWrapper >
160177 </ Space . Compact >
161178 ) }
162179
163180 { /* Preview */ }
164- < div style = { { marginTop : 8 } } >
165- < Text type = "secondary" >
166- Preview: { displayToFriendlyString ( displayFormat ) }
167- </ Text >
168- </ div >
181+ < PreviewTextWrapper >
182+ < div style = { { marginTop : 8 } } >
183+ < Text color = "" type = "secondary" >
184+ Preview: { displayToFriendlyString ( displayFormat ) }
185+ </ Text >
186+ </ div >
187+ </ PreviewTextWrapper >
169188
170189 { /* Validation Error */ }
171190 { ! isValid && validation . error && (
172- < Alert
173- message = { validation . error }
174- type = "error"
175- style = { { marginTop : 8 } }
176- showIcon
177- />
191+ < Alert message = { validation . error } type = "error" style = { { marginTop : 8 } } showIcon />
178192 ) }
179193 </ div >
180194
181195 { /* Helpful Information */ }
182- < div style = { { marginTop : 8 } } >
183- < Text type = "secondary" style = { { fontSize : '12px' } } >
184- Valid range: 1 MB to 1 TB
185- </ Text >
186- </ div >
196+ < PreviewTextWrapper >
197+ < div style = { { marginTop : 8 } } >
198+ < Text type = "secondary" style = { { fontSize : '12px' } } >
199+ Valid range: 1 MB to 1 TB
200+ </ Text >
201+ </ div >
202+ </ PreviewTextWrapper >
187203 </ Space >
188204 ) ;
189205} ;
0 commit comments