-
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.
- Loading branch information
Showing
6 changed files
with
196 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { useState } from "react"; | ||
import { useDisclosure } from "@mantine/hooks"; | ||
import { Modal, Button, Select, Group, ActionIcon } from "@mantine/core"; | ||
import { useFetcher } from "react-router"; | ||
import { IconDots } from "@tabler/icons-react"; | ||
|
||
type SubCategory = { | ||
id: string; | ||
name: string; | ||
}; | ||
|
||
type Transaction = { | ||
id: string; | ||
account_id: string; | ||
amount: number; | ||
date: string; | ||
description: string; | ||
counterparty: string; | ||
subcategory_id: string; | ||
user_description: string; | ||
}; | ||
|
||
type EditTransactionModalProps = { | ||
subCategories: SubCategory[]; // List of available sub-categories | ||
transaction: Transaction; // ID of the transaction being edited | ||
}; | ||
|
||
export function EditTransactionModal({ | ||
subCategories, | ||
transaction, | ||
}: EditTransactionModalProps) { | ||
const [opened, { open, close }] = useDisclosure(false); | ||
const [selectedSubCategory, setSelectedSubCategory] = useState<string | null>( | ||
null | ||
); | ||
const fetcher = useFetcher(); | ||
|
||
const handleSubmit = () => { | ||
if (!selectedSubCategory) { | ||
return; | ||
} | ||
|
||
// Use fetcher.submit with JSON encoding | ||
fetcher.submit( | ||
{ | ||
account_id: transaction.account_id, | ||
transaction_id: transaction.id, | ||
subcategory_id: selectedSubCategory, | ||
action: "editTransaction", | ||
}, | ||
{ method: "post", encType: "application/json" } | ||
); | ||
|
||
// Close modal on success (optionally handle fetcher.state or errors) | ||
close(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Modal opened={opened} onClose={close} title="Edit Transaction" centered> | ||
<Select | ||
label="Select Sub-Category" | ||
placeholder="Choose a sub-category" | ||
data={subCategories.map((subCategory) => ({ | ||
value: subCategory.id, | ||
label: subCategory.name, | ||
}))} | ||
value={selectedSubCategory} | ||
onChange={setSelectedSubCategory} | ||
required | ||
mb="sm" | ||
/> | ||
<Group align="right" mt="md"> | ||
<Button variant="default" onClick={close}> | ||
Cancel | ||
</Button> | ||
<Button onClick={handleSubmit} loading={fetcher.state !== "idle"}> | ||
Save | ||
</Button> | ||
</Group> | ||
</Modal> | ||
|
||
<ActionIcon onClick={open} size="compact-xs" variant="subtle"> | ||
<IconDots size={16} stroke={1.5} /> | ||
</ActionIcon> | ||
</> | ||
); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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