1- import { Banknote } from 'lucide-react' ;
2- import { useMemo } from 'react' ;
1+ import { CATEGORIES , type CategoryItem } from '~/lib/category' ;
32
43import { Button } from '../ui/button' ;
5- import { CategoryIcons } from '../ui/categoryIcons' ;
4+ import { CategoryIcon } from '../ui/categoryIcons' ;
65import { AppDrawer , DrawerClose } from '../ui/drawer' ;
76
87export const CategoryPicker : React . FC < {
98 category : string ;
109 onCategoryPick : ( category : string ) => void ;
1110} > = ( { category, onCategoryPick } ) => {
12- const CategoryIcon = useMemo ( ( ) => CategoryIcons [ category ] ?? Banknote , [ category ] ) ;
13-
1411 return (
1512 < AppDrawer
1613 trigger = {
1714 < div className = "flex w-[70px] justify-center rounded-lg border py-2" >
18- < CategoryIcon size = { 20 } />
15+ < CategoryIcon category = { category } size = { 20 } />
1916 </ div >
2017 }
2118 title = "Categories"
@@ -27,117 +24,28 @@ export const CategoryPicker: React.FC<{
2724 < div key = { categoryName } className = "mb-8" >
2825 < h3 className = "mb-4 text-lg font-semibold" > { categoryDetails . name } </ h3 >
2926 < div className = "flex flex-wrap justify-between gap-2" >
30- { categoryDetails . items . map ( ( item ) =>
31- Object . entries ( item ) . map ( ( [ key , value ] ) => {
32- const Icon = CategoryIcons [ key ] ?? CategoryIcons [ categoryName ] ?? Banknote ;
33- return (
34- < DrawerClose key = { key } >
35- < Button
36- variant = "ghost"
37- className = "flex w-[75px] flex-col gap-1 py-8 text-center"
38- onClick = { ( ) => {
39- onCategoryPick ( key === 'other' ? categoryName : key ) ;
40- } }
41- >
42- < span className = "block text-2xl" >
43- < Icon />
44- </ span >
45- < span className = "block text-xs capitalize" > { value } </ span >
46- </ Button >
47- </ DrawerClose >
48- ) ;
49- } ) ,
50- ) }
27+ { Object . entries ( categoryDetails . items ) . map ( ( [ key , value ] ) => (
28+ < DrawerClose key = { key } >
29+ < Button
30+ variant = "ghost"
31+ className = "flex w-[75px] flex-col gap-1 py-8 text-center"
32+ onClick = { ( ) => {
33+ onCategoryPick ( key === 'other' ? categoryName : key ) ;
34+ } }
35+ >
36+ < span className = "block text-2xl" >
37+ < CategoryIcon
38+ category = { ( key === 'other' ? categoryName : key ) as CategoryItem }
39+ />
40+ </ span >
41+ < span className = "block text-xs capitalize" > { value } </ span >
42+ </ Button >
43+ </ DrawerClose >
44+ ) ) }
5145 </ div >
5246 </ div >
5347 ) ;
5448 } ) }
5549 </ AppDrawer >
5650 ) ;
5751} ;
58-
59- const CATEGORIES = {
60- entertainment : {
61- name : 'Entertainment' ,
62- items : [
63- {
64- games : 'Games' ,
65- movies : 'Movies' ,
66- music : 'Music' ,
67- sports : 'Sports' ,
68- other : 'Entertainment' ,
69- } ,
70- ] ,
71- } ,
72- food : {
73- name : 'Food & Drinks' ,
74- items : [
75- {
76- diningOut : 'Dining Out' ,
77- groceries : 'Groceries' ,
78- liquor : 'Liquor' ,
79- other : 'Food & Drinks' ,
80- } ,
81- ] ,
82- } ,
83- home : {
84- name : 'Home' ,
85- items : [
86- {
87- electronics : 'Electronics' ,
88- furniture : 'Furniture' ,
89- supplies : 'Supplies' ,
90- maintenance : 'Maintenance' ,
91- mortgage : 'Mortgage' ,
92- pets : 'Pets' ,
93- rent : 'Rent' ,
94- services : 'Services' ,
95- other : 'Home' ,
96- } ,
97- ] ,
98- } ,
99- life : {
100- name : 'Life' ,
101- items : [
102- {
103- childcare : 'Childcare' ,
104- clothing : 'Clothing' ,
105- education : 'Education' ,
106- gifts : 'Gifts' ,
107- medical : 'Medical' ,
108- taxes : 'Taxes' ,
109- other : 'Life' ,
110- } ,
111- ] ,
112- } ,
113- travel : {
114- name : 'Travel' ,
115- items : [
116- {
117- bus : 'Bus' ,
118- train : 'Train' ,
119- car : 'Car' ,
120- fuel : 'Fuel' ,
121- parking : 'Parking' ,
122- plane : 'Plane' ,
123- taxi : 'Taxi' ,
124- other : 'Travel' ,
125- } ,
126- ] ,
127- } ,
128- utilities : {
129- name : 'Utilities' ,
130- items : [
131- {
132- cleaning : 'Cleaning' ,
133- electricity : 'Electricity' ,
134- gas : 'Gas' ,
135- internet : 'Internet' ,
136- trash : 'Trash' ,
137- phone : 'Phone' ,
138- water : 'Water' ,
139- other : 'Utilities' ,
140- } ,
141- ] ,
142- } ,
143- } ;
0 commit comments