@@ -9,11 +9,31 @@ import useSWR from "swr";
9
9
import { Group } from "@prisma/client" ;
10
10
import { CATEGORIES } from "constants/categories" ;
11
11
import { enqueueSnackbar } from "notistack" ;
12
+ import Datepicker from "react-tailwindcss-datepicker" ;
12
13
13
14
type Expense = any ;
14
15
15
16
type CreateExpenseFormProps = { } ;
16
17
18
+ const DatePickerField = ( {
19
+ value,
20
+ onChange,
21
+ } : {
22
+ value : any ;
23
+ onChange : any ;
24
+ } ) => {
25
+ return (
26
+ < Datepicker
27
+ useRange = { false }
28
+ asSingle
29
+ value = { value }
30
+ onChange = { ( val ) => {
31
+ onChange ( "date" , val ) ;
32
+ } }
33
+ />
34
+ ) ;
35
+ } ;
36
+
17
37
const CreateExpenseForm : React . FC < CreateExpenseFormProps > = ( ) => {
18
38
const { data : session } = useSession ( ) ;
19
39
@@ -25,6 +45,7 @@ const CreateExpenseForm: React.FC<CreateExpenseFormProps> = () => {
25
45
title : "" ,
26
46
amount : "" ,
27
47
type : "expense" ,
48
+ date : { startDate : new Date ( ) , endDate : new Date ( ) } ,
28
49
group : groups ?. [ 0 ] ?. id ?? "" ,
29
50
category : "" ,
30
51
repeat : false ,
@@ -49,12 +70,15 @@ const CreateExpenseForm: React.FC<CreateExpenseFormProps> = () => {
49
70
...values ,
50
71
userId : session ?. user . id ,
51
72
groupId : values . group ,
73
+ date : values . date . startDate ,
52
74
categoryId : values . category ,
53
75
isSplit : values . split ,
54
76
type : values . type ,
55
77
isRepeating : values . repeat ,
56
78
} ) ;
57
79
80
+ console . log ( values ) ;
81
+
58
82
enqueueSnackbar ( `${ values . type } added sucessfully` ) ;
59
83
resetForm ( ) ;
60
84
} catch ( error ) {
@@ -69,7 +93,7 @@ const CreateExpenseForm: React.FC<CreateExpenseFormProps> = () => {
69
93
onSubmit = { handleSubmit }
70
94
enableReinitialize
71
95
>
72
- { ( { isSubmitting, values } ) => (
96
+ { ( { isSubmitting, values, setFieldValue } ) => (
73
97
< Form className = "flex flex-col gap-4" >
74
98
< div >
75
99
< Label htmlFor = "title" > Title</ Label >
@@ -102,6 +126,14 @@ const CreateExpenseForm: React.FC<CreateExpenseFormProps> = () => {
102
126
</ StyledField >
103
127
</ div >
104
128
129
+ < div >
130
+ < Label htmlFor = "group" > Date</ Label >
131
+ < DatePickerField
132
+ value = { values . date }
133
+ onChange = { setFieldValue }
134
+ />
135
+ </ div >
136
+
105
137
< div >
106
138
< Label htmlFor = "type" > Type</ Label >
107
139
< StyledField as = "select" id = "type" name = "type" >
0 commit comments