-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working dialog box and updating rows in db
- Loading branch information
1 parent
127c720
commit 5d54937
Showing
7 changed files
with
435 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Button } from "@/components/button"; | ||
import { | ||
Dialog, | ||
DialogActions, | ||
DialogBody, | ||
DialogDescription, | ||
DialogTitle, | ||
} from "@/components/dialog"; | ||
import { Field, Label } from "@/components/fieldset"; | ||
import { Input } from "@/components/input"; | ||
import { CategoryWithDetails } from "@/types"; | ||
import { useState } from "react"; | ||
|
||
export default function UpdateBox({ | ||
c, | ||
handler, | ||
}: { | ||
c: CategoryWithDetails; | ||
handler: (categoryId: number, amount: number) => void; | ||
}) { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const [assignedAmount, setAssignedAmount] = useState( | ||
c.monthly_category_details?.amount_assigned, | ||
); | ||
|
||
return ( | ||
<> | ||
<Button type="button" onClick={() => setIsOpen(true)}> | ||
{c.monthly_category_details && | ||
c.monthly_category_details.amount_assigned} | ||
</Button> | ||
<Dialog open={isOpen} onClose={setIsOpen}> | ||
<DialogTitle>Assign Dollars</DialogTitle> | ||
<DialogDescription> | ||
Assign your monthly available budget to {c.name} | ||
</DialogDescription> | ||
<DialogBody> | ||
<Field> | ||
<Label>Amount</Label> | ||
<Input | ||
name="amount" | ||
placeholder="$0.00" | ||
autoFocus | ||
value={assignedAmount ?? ""} | ||
onChange={(e) => { | ||
const value = e.target.value; | ||
if (!isNaN(Number(value))) { | ||
setAssignedAmount(Number(value)); | ||
} | ||
}} | ||
/> | ||
</Field> | ||
</DialogBody> | ||
<DialogActions> | ||
<Button plain onClick={() => setIsOpen(false)}> | ||
Cancel | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
setIsOpen(false); | ||
if (assignedAmount !== null && assignedAmount >= 0) { | ||
handler(c.id, assignedAmount); | ||
} | ||
}} | ||
> | ||
Set | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</> | ||
); | ||
} |
Oops, something went wrong.