Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/components/invoice-creator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function InvoiceCreator({
}: InvoiceCreatorProps) {
const router = useRouter();
const isInvoiceMe = !!recipientDetails?.userId;

const utils = api.useUtils();
const { mutate: createInvoice, isLoading } = isInvoiceMe
? api.invoice.createFromInvoiceMe.useMutation({
onSuccess: () => {
Expand All @@ -46,11 +46,10 @@ export function InvoiceCreator({
},
})
: api.invoice.create.useMutation({
onSuccess: () => {
onSuccess: async () => {
toast.success("Invoice created successfully");
setTimeout(() => {
router.push("/dashboard");
}, 3000);
await utils.invoice.getAll.invalidate();
router.push("/dashboard");
},
});

Expand Down
11 changes: 1 addition & 10 deletions src/components/invoice-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import type {
} from "@/server/db/schema";
import { api } from "@/trpc/react";
import { Plus, Terminal, Trash2 } from "lucide-react";
import { useRouter } from "next/navigation";
import { useCallback, useEffect, useState } from "react";
import type { UseFormReturn } from "react-hook-form";
import { useFieldArray } from "react-hook-form";
Expand Down Expand Up @@ -268,7 +267,6 @@ export function InvoiceForm({
isLoading,
recipientDetails,
}: InvoiceFormProps) {
const router = useRouter();
const [showBankAccountModal, setShowBankAccountModal] = useState(false);
const [showPendingApprovalModal, setShowPendingApprovalModal] =
useState(false);
Expand Down Expand Up @@ -415,9 +413,6 @@ export function InvoiceForm({
await onSubmit(data);
setInvoiceCreated(true);
setWaitingForPaymentApproval(false);

// Redirect to Dashboard
router.push("/dashboard");
} catch (error) {
toast.error(
error instanceof Error
Expand All @@ -433,7 +428,6 @@ export function InvoiceForm({
linkedPaymentDetails,
onSubmit,
form.setError,
router,
isSubmitting,
handleBankAccountSuccess,
],
Expand Down Expand Up @@ -508,9 +502,6 @@ export function InvoiceForm({
await onSubmit(formData);
setInvoiceCreated(true);
setWaitingForPaymentApproval(false);

// Redirect to Dashboard
router.push("/dashboard");
} catch (error) {
toast.error(
error instanceof Error
Expand All @@ -521,7 +512,7 @@ export function InvoiceForm({
setWaitingForPaymentApproval(false);
setIsSubmitting(false);
}
}, [form, onSubmit, router]);
}, [form, onSubmit]);

// Separate effect for handling payment approval and form submission
useEffect(() => {
Expand Down