Skip to content

Commit c518204

Browse files
committed
feat: add date to activities, add datepicker to form
1 parent 414fc7b commit c518204

File tree

7 files changed

+51
-2
lines changed

7 files changed

+51
-2
lines changed

components/common/StyledField/StyledField.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type StyledFieldProps = FieldAttributes<any>;
66
export const StyledField: FunctionComponent<StyledFieldProps> = (props) => {
77
return (
88
<Field
9-
className="focus:ring-primary-600 focus:border-primary-600 block w-full rounded-lg border border-black bg-gray-50 p-2.5 text-gray-900 sm:text-sm"
9+
className="focus:ring-primary-600 focus:border-primary-600 block w-full rounded-lg border border-0 bg-gray-50 p-2.5 text-gray-900 dark:text-white/80 dark:bg-slate-800 sm:text-sm"
1010
{...props}
1111
/>
1212
);

components/forms/ExpenseForm.tsx

+33-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,31 @@ import useSWR from "swr";
99
import { Group } from "@prisma/client";
1010
import { CATEGORIES } from "constants/categories";
1111
import { enqueueSnackbar } from "notistack";
12+
import Datepicker from "react-tailwindcss-datepicker";
1213

1314
type Expense = any;
1415

1516
type CreateExpenseFormProps = {};
1617

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+
1737
const CreateExpenseForm: React.FC<CreateExpenseFormProps> = () => {
1838
const { data: session } = useSession();
1939

@@ -25,6 +45,7 @@ const CreateExpenseForm: React.FC<CreateExpenseFormProps> = () => {
2545
title: "",
2646
amount: "",
2747
type: "expense",
48+
date: { startDate: new Date(), endDate: new Date() },
2849
group: groups?.[0]?.id ?? "",
2950
category: "",
3051
repeat: false,
@@ -49,12 +70,15 @@ const CreateExpenseForm: React.FC<CreateExpenseFormProps> = () => {
4970
...values,
5071
userId: session?.user.id,
5172
groupId: values.group,
73+
date: values.date.startDate,
5274
categoryId: values.category,
5375
isSplit: values.split,
5476
type: values.type,
5577
isRepeating: values.repeat,
5678
});
5779

80+
console.log(values);
81+
5882
enqueueSnackbar(`${values.type} added sucessfully`);
5983
resetForm();
6084
} catch (error) {
@@ -69,7 +93,7 @@ const CreateExpenseForm: React.FC<CreateExpenseFormProps> = () => {
6993
onSubmit={handleSubmit}
7094
enableReinitialize
7195
>
72-
{({ isSubmitting, values }) => (
96+
{({ isSubmitting, values, setFieldValue }) => (
7397
<Form className="flex flex-col gap-4">
7498
<div>
7599
<Label htmlFor="title">Title</Label>
@@ -102,6 +126,14 @@ const CreateExpenseForm: React.FC<CreateExpenseFormProps> = () => {
102126
</StyledField>
103127
</div>
104128

129+
<div>
130+
<Label htmlFor="group">Date</Label>
131+
<DatePickerField
132+
value={values.date}
133+
onChange={setFieldValue}
134+
/>
135+
</div>
136+
105137
<div>
106138
<Label htmlFor="type">Type</Label>
107139
<StyledField as="select" id="type" name="type">

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@types/react": "18.0.26",
1919
"@types/react-dom": "18.0.10",
2020
"axios": "^1.3.4",
21+
"dayjs": "^1.11.7",
2122
"eslint": "8.31.0",
2223
"eslint-config-next": "13.1.1",
2324
"formik": "^2.2.9",
@@ -28,6 +29,7 @@
2829
"react": "18.2.0",
2930
"react-dom": "18.2.0",
3031
"react-range": "^1.8.14",
32+
"react-tailwindcss-datepicker": "^1.5.1",
3133
"swr": "^2.0.0",
3234
"typescript": "4.9.4",
3335
"yup": "^1.0.2"

pages/api/expenses.ts

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type CreateExpenseRequest = {
55
title: string;
66
amount: number;
77
userId: string;
8+
date: string;
89
groupId: string;
910
categoryId: string;
1011
isSplit: boolean;
@@ -21,6 +22,7 @@ export default async function handler(
2122
amount,
2223
userId,
2324
groupId,
25+
date,
2426
categoryId,
2527
isSplit,
2628
type,
@@ -33,6 +35,7 @@ export default async function handler(
3335
title,
3436
amount: +amount,
3537
type,
38+
date,
3639
isRepeating,
3740
categoryId,
3841
isSplit: isSplit,

prisma/schema.prisma

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ model Activity {
9494
amount Float
9595
type ActivityType
9696
97+
date DateTime @default(now())
9798
userId String
9899
createdAt DateTime @default(now())
99100
groupId String

tailwind.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44
content: [
55
"./pages/**/*.{js,ts,jsx,tsx}",
66
"./components/**/*.{js,ts,jsx,tsx}",
7+
"./node_modules/react-tailwindcss-datepicker/dist/index.esm.js",
78
],
89
theme: {
910
extend: {},

yarn.lock

+10
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,11 @@ damerau-levenshtein@^1.0.8:
618618
resolved "https://registry.yarnpkg.com/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz#b43d286ccbd36bc5b2f7ed41caf2d0aba1f8a6e7"
619619
integrity sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==
620620

621+
dayjs@^1.11.7:
622+
version "1.11.7"
623+
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.7.tgz#4b296922642f70999544d1144a2c25730fce63e2"
624+
integrity sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==
625+
621626
debug@^3.2.7:
622627
version "3.2.7"
623628
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a"
@@ -2167,6 +2172,11 @@ react-range@^1.8.14:
21672172
resolved "https://registry.yarnpkg.com/react-range/-/react-range-1.8.14.tgz#11047f69b365ac6c75c3d715771ebe76b93982ec"
21682173
integrity sha512-v2nyD5106rHf9dwHzq+WRlhCes83h1wJRHIMFjbZsYYsO6LF4mG/mR3cH7Cf+dkeHq65DItuqIbLn/3jjYjsHg==
21692174

2175+
react-tailwindcss-datepicker@^1.5.1:
2176+
version "1.5.1"
2177+
resolved "https://registry.yarnpkg.com/react-tailwindcss-datepicker/-/react-tailwindcss-datepicker-1.5.1.tgz#442fbda87e0e686cf338ce7427ca9c3165f26cd6"
2178+
integrity sha512-IbNw3Lu2dwkRYOlYr3ffOwEbLiVz+QufaYbwiy0ToeLmx7ZUt0CPh3HfwVQGNS1/o4D/+8Rl4WHNsLd+wVb5Mg==
2179+
21702180
21712181
version "18.2.0"
21722182
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"

0 commit comments

Comments
 (0)