@@ -5,9 +5,10 @@ import Button from "../Button";
5
5
import { useUser } from "../../api/UserContext" ;
6
6
7
7
const Container = styled . div `
8
- width: 100% ;
8
+ width: 520px ;
9
9
height: 180px;
10
10
padding: 10px;
11
+ margin-top: 20px;
11
12
display: flex;
12
13
flex-direction: column;
13
14
align-items: center;
@@ -97,9 +98,9 @@ const BudgetInput = styled.input`
97
98
98
99
function ShoppingBudget ( { budget, present, hideButtons } ) {
99
100
const [ isEditing , setIsEditing ] = useState ( false ) ;
100
- const [ newBudget , setNewBudget ] = useState ( "" ) ;
101
- const state = budget - present ;
102
- const token = useUser ( ) ;
101
+ const [ newBudget , setNewBudget ] = useState ( ) ;
102
+ const state = budget === 0 ? 0 : budget - present ;
103
+ const { token } = useUser ( ) ;
103
104
104
105
const handleSetBudget = async ( ) => {
105
106
if ( ! newBudget || isNaN ( newBudget ) ) {
@@ -132,7 +133,7 @@ function ShoppingBudget({ budget, present, hideButtons }) {
132
133
}
133
134
} ;
134
135
135
- if ( budget == null && ! hideButtons ) {
136
+ if ( ! hideButtons ) {
136
137
return (
137
138
< >
138
139
{ isEditing ? (
@@ -151,14 +152,42 @@ function ShoppingBudget({ budget, present, hideButtons }) {
151
152
/>
152
153
</ BudgetInputContainer >
153
154
) : (
154
- < Button
155
- title = "예산 설정하기"
156
- className = "green"
157
- onClick = { ( ) => setIsEditing ( true ) }
158
- />
155
+ < >
156
+ < Button
157
+ title = "예산 설정하기"
158
+ className = "green"
159
+ onClick = { ( ) => setIsEditing ( true ) }
160
+ />
161
+ { budget === 0 && (
162
+ < >
163
+ < TextMain className = "title" > 등록된 예산이 없습니다</ TextMain >
164
+ < TextMain className = "sub" > 내 예산을 설정해보세요!</ TextMain >
165
+ </ >
166
+ ) }
167
+ { budget !== 0 && (
168
+ < Container >
169
+ < ContentContainer >
170
+ < FiDollarSign color = "#daa520" size = { 32 } />
171
+ < Text className = "budget" > 예산</ Text >
172
+ < Text className = "money" > { `${ budget } ` } ₩</ Text >
173
+ </ ContentContainer >
174
+ < ContentContainer >
175
+ < FiDollarSign color = "#47572f" size = { 32 } />
176
+ < Text className = "present" > 현재</ Text >
177
+ < Text className = "money" > { `${ present } ` } ₩</ Text >
178
+ </ ContentContainer >
179
+ < hr color = "#432a00" width = "520px" height = "1px" />
180
+ < ContentContainer >
181
+ < FiDollarSign color = "#432a00" size = { 32 } />
182
+ < Text className = { state >= 0 ? "stable" : "warning" } >
183
+ { state >= 0 ? "안정" : "초과" }
184
+ </ Text >
185
+ < Text className = "money" > { state } ₩</ Text >
186
+ </ ContentContainer >
187
+ </ Container >
188
+ ) }
189
+ </ >
159
190
) }
160
- < TextMain className = "title" > 등록된 예산이 없습니다</ TextMain >
161
- < TextMain className = "sub" > 내 예산을 설정해보세요!</ TextMain >
162
191
</ >
163
192
) ;
164
193
}
@@ -169,30 +198,7 @@ function ShoppingBudget({ budget, present, hideButtons }) {
169
198
< FiDollarSign color = "#daa520" size = { 32 } />
170
199
< Text className = "budget" > 예산</ Text >
171
200
< Text className = "money" > { `${ budget } ` } ₩</ Text >
172
- { ! hideButtons && (
173
- < Button
174
- title = "수정"
175
- className = "green"
176
- onClick = { ( ) => setIsEditing ( true ) }
177
- />
178
- ) }
179
201
</ ContentContainer >
180
- { isEditing && (
181
- < BudgetInputContainer >
182
- < BudgetInput
183
- type = "number"
184
- value = { newBudget }
185
- onChange = { ( e ) => setNewBudget ( e . target . value ) }
186
- placeholder = "새로운 예산을 입력하세요"
187
- />
188
- < Button title = "설정" className = "brown" onClick = { handleSetBudget } />
189
- < Button
190
- title = "취소"
191
- className = "yellow"
192
- onClick = { ( ) => setIsEditing ( false ) }
193
- />
194
- </ BudgetInputContainer >
195
- ) }
196
202
< ContentContainer >
197
203
< FiDollarSign color = "#47572f" size = { 32 } />
198
204
< Text className = "present" > 현재</ Text >
0 commit comments