import { Button } from "@/components/ui/button" import ErrorBanner from "@/components/ui/error-banner" import { Form } from "@/components/ui/form" import { useCurrentCompany } from "@/hooks/useCurrentCompany" import _ from "@/lib/translate" import { BankTransactionRule } from "@/types/Accounts/BankTransactionRule" import { useFrappeCreateDoc } from "frappe-react-sdk" import { toast } from "sonner" import { RuleForm } from "./RuleForm" import { useForm } from "react-hook-form" import { SettingsPanelHeader, SettingsPanelDescription, SettingsPanelTitle, SettingsPanelContent } from "@/components/ui/settings-dialog" import { useHotkeys } from "react-hotkeys-hook" type Props = { onCreate: VoidFunction } const CreateNewRule = ({ onCreate }: Props) => { const currentCompany = useCurrentCompany() const form = useForm({ defaultValues: { rule_name: "", company: currentCompany, rule_description: "", transaction_type: "Any", classify_as: 'Bank Entry', bank_entry_type: "Single Account", description_rules: [{ check: "Contains", }] } }) const { createDoc, loading, error } = useFrappeCreateDoc() const onSubmit = (data: BankTransactionRule) => { createDoc("Bank Transaction Rule", data) .then(() => { toast.success(_("Rule created successfully")) onCreate() }) } useHotkeys('meta+s', () => { form.handleSubmit(onSubmit)() }, { enabled: true, preventDefault: true, enableOnFormTags: true }) return ( <> } > {_("New Rule")} {_("Create a new rule to automatically classify transactions.")}
{error && }
) } export default CreateNewRule