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,21 @@ 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+
2435export const TierEditor : React . FC < TierEditorProps > = ( {
2536 tier,
2637 onTierChange,
2738 disabled = false ,
2839 showName = true ,
29- showPrice = true
40+ showPrice = true ,
3041} ) => {
3142 // Convert backend format to display format for editing
3243 const [ displayFormat , setDisplayFormat ] = useState < TierDisplayFormat > ( ( ) => {
@@ -49,34 +60,39 @@ export const TierEditor: React.FC<TierEditorProps> = ({
4960 const updatedTier : AllowedUsersTier = {
5061 name,
5162 price_sats : priceSats ,
52- monthly_limit_bytes : displayFormat . unlimited ? 0 :
53- Math . round ( displayFormat . value * getUnitMultiplier ( displayFormat . unit ) ) ,
54- unlimited : displayFormat . unlimited
63+ monthly_limit_bytes : displayFormat . unlimited
64+ ? 0
65+ : Math . round ( displayFormat . value * getUnitMultiplier ( displayFormat . unit ) ) ,
66+ unlimited : displayFormat . unlimited ,
5567 } ;
5668 onTierChange ( updatedTier ) ;
5769 }
5870 } , [ displayFormat , name , priceSats , isValid , onTierChange ] ) ;
5971
6072 const getUnitMultiplier = ( unit : DataUnit ) : number => {
6173 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 ;
74+ case 'MB' :
75+ return 1048576 ; // 1024 * 1024
76+ case 'GB' :
77+ return 1073741824 ; // 1024 * 1024 * 1024
78+ case 'TB' :
79+ return 1099511627776 ; // 1024 * 1024 * 1024 * 1024
80+ default :
81+ return 1048576 ;
6682 }
6783 } ;
6884
6985 const handleValueChange = ( value : string ) => {
7086 const numericValue = parseFloat ( value ) || 0 ;
71- setDisplayFormat ( prev => ( { ...prev , value : numericValue } ) ) ;
87+ setDisplayFormat ( ( prev ) => ( { ...prev , value : numericValue } ) ) ;
7288 } ;
7389
7490 const handleUnitChange = ( unit : DataUnit ) => {
75- setDisplayFormat ( prev => ( { ...prev , unit } ) ) ;
91+ setDisplayFormat ( ( prev ) => ( { ...prev , unit } ) ) ;
7692 } ;
7793
7894 const handleUnlimitedChange = ( unlimited : boolean ) => {
79- setDisplayFormat ( prev => ( { ...prev , unlimited } ) ) ;
95+ setDisplayFormat ( ( prev ) => ( { ...prev , unlimited } ) ) ;
8096 } ;
8197
8298 const handleNameChange = ( value : string ) => {
@@ -94,7 +110,7 @@ export const TierEditor: React.FC<TierEditorProps> = ({
94110 { showName && (
95111 < div >
96112 < Text strong > Tier Name</ Text >
97- < Input
113+ < StyledInput
98114 value = { name }
99115 onChange = { ( e ) => handleNameChange ( e . target . value ) }
100116 placeholder = "Enter tier name"
@@ -108,7 +124,7 @@ export const TierEditor: React.FC<TierEditorProps> = ({
108124 { showPrice && (
109125 < div >
110126 < Text strong > Price (sats)</ Text >
111- < Input
127+ < StyledInput
112128 type = "number"
113129 value = { priceSats }
114130 onChange = { ( e ) => handlePriceChange ( e . target . value ) }
@@ -123,7 +139,7 @@ export const TierEditor: React.FC<TierEditorProps> = ({
123139 { /* Data Limit */ }
124140 < div >
125141 < Text strong > Monthly Data Limit</ Text >
126-
142+
127143 { /* Unlimited Checkbox */ }
128144 < div style = { { marginTop : 8 , marginBottom : 8 } } >
129145 < Checkbox
@@ -138,7 +154,7 @@ export const TierEditor: React.FC<TierEditorProps> = ({
138154 { /* Value and Unit Inputs */ }
139155 { ! displayFormat . unlimited && (
140156 < Space . Compact style = { { width : '100%' } } >
141- < Input
157+ < StyledInput
142158 type = "number"
143159 value = { displayFormat . value || '' }
144160 onChange = { ( e ) => handleValueChange ( e . target . value ) }
@@ -147,12 +163,7 @@ export const TierEditor: React.FC<TierEditorProps> = ({
147163 min = { TIER_VALIDATION . MIN_VALUE }
148164 style = { { flex : 1 } }
149165 />
150- < Select
151- value = { displayFormat . unit }
152- onChange = { handleUnitChange }
153- disabled = { disabled }
154- style = { { width : 80 } }
155- >
166+ < Select value = { displayFormat . unit } onChange = { handleUnitChange } disabled = { disabled } style = { { width : 80 } } >
156167 < Option value = "MB" > MB</ Option >
157168 < Option value = "GB" > GB</ Option >
158169 < Option value = "TB" > TB</ Option >
@@ -161,29 +172,28 @@ export const TierEditor: React.FC<TierEditorProps> = ({
161172 ) }
162173
163174 { /* Preview */ }
164- < div style = { { marginTop : 8 } } >
165- < Text type = "secondary" >
166- Preview: { displayToFriendlyString ( displayFormat ) }
167- </ Text >
168- </ div >
175+ < PreviewTextWrapper >
176+ < div style = { { marginTop : 8 } } >
177+ < Text color = "" type = "secondary" >
178+ Preview: { displayToFriendlyString ( displayFormat ) }
179+ </ Text >
180+ </ div >
181+ </ PreviewTextWrapper >
169182
170183 { /* Validation Error */ }
171184 { ! isValid && validation . error && (
172- < Alert
173- message = { validation . error }
174- type = "error"
175- style = { { marginTop : 8 } }
176- showIcon
177- />
185+ < Alert message = { validation . error } type = "error" style = { { marginTop : 8 } } showIcon />
178186 ) }
179187 </ div >
180188
181189 { /* 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 >
190+ < PreviewTextWrapper >
191+ < div style = { { marginTop : 8 } } >
192+ < Text type = "secondary" style = { { fontSize : '12px' } } >
193+ Valid range: 1 MB to 1 TB
194+ </ Text >
195+ </ div >
196+ </ PreviewTextWrapper >
187197 </ Space >
188198 ) ;
189199} ;
0 commit comments