diff options
Diffstat (limited to 'fe/src/lib/forms/AddForm.svelte')
-rw-r--r-- | fe/src/lib/forms/AddForm.svelte | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/fe/src/lib/forms/AddForm.svelte b/fe/src/lib/forms/AddForm.svelte index f85cce6..bbc8356 100644 --- a/fe/src/lib/forms/AddForm.svelte +++ b/fe/src/lib/forms/AddForm.svelte | |||
@@ -11,21 +11,10 @@ | |||
11 | const statistic: Statistic = newStatistic(); | 11 | const statistic: Statistic = newStatistic(); |
12 | 12 | ||
13 | function newStatistic(): Statistic { | 13 | function newStatistic(): Statistic { |
14 | let now = new Date(), | 14 | let date = new Date().toString(); |
15 | month, | ||
16 | day, | ||
17 | year; | ||
18 | |||
19 | month = `${now.getMonth() + 1}`; | ||
20 | day = `${now.getDate()}`; | ||
21 | year = now.getFullYear(); | ||
22 | if (month.length < 2) month = "0" + month; | ||
23 | if (day.length < 2) day = "0" + day; | ||
24 | |||
25 | const date = [year, month, day].join("-"); | ||
26 | 15 | ||
27 | return { | 16 | return { |
28 | user_id: $user!.uuid, | 17 | user_id: $user!.id, |
29 | date, | 18 | date, |
30 | quantity: 1 | 19 | quantity: 1 |
31 | }; | 20 | }; |
@@ -37,7 +26,7 @@ | |||
37 | 26 | ||
38 | async function handleSubmitStat() | 27 | async function handleSubmitStat() |
39 | { | 28 | { |
40 | const { date, quantity } = statistic; | 29 | const { user_id, date, quantity } = statistic; |
41 | await fetch(apiURL("stats"), { | 30 | await fetch(apiURL("stats"), { |
42 | method: "POST", | 31 | method: "POST", |
43 | headers: { | 32 | headers: { |
@@ -45,7 +34,7 @@ | |||
45 | }, | 34 | }, |
46 | body: JSON.stringify({ | 35 | body: JSON.stringify({ |
47 | date: new Date(date), | 36 | date: new Date(date), |
48 | user_id: 2, | 37 | user_id, |
49 | quantity | 38 | quantity |
50 | }) | 39 | }) |
51 | }); | 40 | }); |
@@ -54,12 +43,12 @@ | |||
54 | 43 | ||
55 | </script> | 44 | </script> |
56 | 45 | ||
57 | <dialog {open} on:submit={handleSubmitStat}> | 46 | <dialog id="addForm" {open} on:submit={handleSubmitStat}> |
58 | <h2>Add Water</h2> | 47 | <h2>Add Water</h2> |
59 | <form method="dialog"> | 48 | <form method="dialog"> |
60 | <div class="form input group"> | 49 | <div class="form input group"> |
61 | <label for="date">Date:</label> | 50 | <label for="date">Date:</label> |
62 | <input bind:value={statistic.date} id="date" name="date" type="date" /> | 51 | <input bind:value={statistic.date} id="date" name="date" type="datetime-local" /> |
63 | </div> | 52 | </div> |
64 | <div class="form input group"> | 53 | <div class="form input group"> |
65 | <label for="quantity">Quantity:</label> | 54 | <label for="quantity">Quantity:</label> |
@@ -75,4 +64,4 @@ | |||
75 | <button on:click={closeDialog}>Cancel</button> | 64 | <button on:click={closeDialog}>Cancel</button> |
76 | <button type="submit">Submit</button> | 65 | <button type="submit">Submit</button> |
77 | </form> | 66 | </form> |
78 | </dialog> \ No newline at end of file | 67 | </dialog> |