Skip to content

Free & Open-Source Invoice Generator - No Sign-Up, No Ads, Instant PDF Export, 100% In-Browser, and Fully Customizable Templates.

refactor: rename item removal handler and enhance user feedback in invoice form (#182)

Vlad Sazonauffeab9880a36
diff --git a/e2e/invoice-form.test.ts b/e2e/invoice-form.test.ts
index 56b0053..5d524d0 100644
--- a/e2e/invoice-form.test.ts
+++ b/e2e/invoice-form.test.ts
@@ -21,19 +21,6 @@ test.describe("Invoice Generator Page", () => {
await page.goto("/");
});
- test("should redirect from /:locale/app to /", async ({ page }) => {
- await page.goto("/en/app");
- await page.waitForURL("**/?template=default");
-
- // wait for the app page to load
- const downloadPDFButton = page.getByRole("link", {
- name: "Download PDF in English",
- });
-
- await expect(downloadPDFButton).toBeVisible();
- await expect(downloadPDFButton).toBeEnabled();
- });
-
test("returns permanent redirect from /:locale/app to /", async ({
request,
}) => {
@@ -625,6 +612,11 @@ test.describe("Invoice Generator Page", () => {
// Confirm deletion
await page.getByRole("button", { name: "Delete" }).click();
+ // Verify success message
+ await expect(
+ page.getByText("Invoice item removed successfully", { exact: true }),
+ ).toBeVisible();
+
// Verify item is removed
await expect(
invoiceItemsSection.getByText("Item 2", { exact: true }),
diff --git a/src/app/(app)/components/invoice-form/index.tsx b/src/app/(app)/components/invoice-form/index.tsx
index bf5be70..127ec6c 100644
--- a/src/app/(app)/components/invoice-form/index.tsx
+++ b/src/app/(app)/components/invoice-form/index.tsx
@@ -258,11 +258,8 @@ export const InvoiceForm = memo(function InvoiceForm({
*
* @param index - The index of the invoice item to remove
*/
- const handleRemoveItem = useCallback(
+ const handleRemoveInvoiceItem = useCallback(
(index: number) => {
- // analytics track event
- umamiTrackEvent("remove_invoice_item");
-
setValue(
"items",
invoiceItems.filter((_, i) => i !== index),
@@ -272,8 +269,18 @@ export const InvoiceForm = memo(function InvoiceForm({
shouldDirty: true,
},
);
+
+ toast.success("Invoice item removed successfully", {
+ id: "invoice-item-removed-success",
+ closeButton: true,
+ richColors: true,
+ position: isMobile ? "top-center" : "bottom-right",
+ });
+
+ // analytics track event
+ umamiTrackEvent("remove_invoice_item");
},
- [invoiceItems, setValue],
+ [invoiceItems, setValue, isMobile],
);
const onSubmit = (data: InvoiceData) => {
@@ -431,7 +438,7 @@ export const InvoiceForm = memo(function InvoiceForm({
<InvoiceItems
control={control}
fields={fields}
- handleRemoveItem={handleRemoveItem}
+ handleRemoveInvoiceItem={handleRemoveInvoiceItem}
errors={errors}
currency={currency}
language={language}
diff --git a/src/app/(app)/components/invoice-form/sections/invoice-items.tsx b/src/app/(app)/components/invoice-form/sections/invoice-items.tsx
index 01b99bf..3710857 100644
--- a/src/app/(app)/components/invoice-form/sections/invoice-items.tsx
+++ b/src/app/(app)/components/invoice-form/sections/invoice-items.tsx
@@ -46,7 +46,7 @@ const ErrorMessage = ({ children }: { children: React.ReactNode }) => {
interface InvoiceItemsSettingsProps {
control: Control<InvoiceData>;
fields: FieldArrayWithId<InvoiceData, "items", "id">[];
- handleRemoveItem: (index: number) => void;
+ handleRemoveInvoiceItem: (index: number) => void;
append: UseFieldArrayAppend<InvoiceData, "items">;
errors: FieldErrors<InvoiceData>;
currency: SupportedCurrencies;
@@ -59,7 +59,7 @@ interface InvoiceItemsSettingsProps {
export const InvoiceItems = memo(function InvoiceItems({
control,
fields,
- handleRemoveItem,
+ handleRemoveInvoiceItem,
errors,
currency,
language,
@@ -824,7 +824,7 @@ export const InvoiceItems = memo(function InvoiceItems({
<DeleteInvoiceItemConfirmationDialog
deleteItemIndex={deleteItemIndex}
setDeleteItemIndex={setDeleteItemIndex}
- handleRemoveItem={handleRemoveItem}
+ handleRemoveInvoiceItem={handleRemoveInvoiceItem}
invoiceData={invoiceData}
/>
</>
@@ -834,7 +834,7 @@ export const InvoiceItems = memo(function InvoiceItems({
interface DeleteInvoiceItemConfirmationDialogProps {
deleteItemIndex: number | null;
setDeleteItemIndex: (index: number | null) => void;
- handleRemoveItem: (index: number) => void;
+ handleRemoveInvoiceItem: (index: number) => void;
invoiceData: InvoiceData;
}
@@ -844,7 +844,7 @@ interface DeleteInvoiceItemConfirmationDialogProps {
function DeleteInvoiceItemConfirmationDialog({
deleteItemIndex = 0,
setDeleteItemIndex,
- handleRemoveItem,
+ handleRemoveInvoiceItem,
invoiceData,
}: DeleteInvoiceItemConfirmationDialogProps) {
const itemNumber = deleteItemIndex ?? 0;
@@ -873,7 +873,7 @@ function DeleteInvoiceItemConfirmationDialog({
<AlertDialogAction
onClick={() => {
if (deleteItemIndex !== null) {
- handleRemoveItem(deleteItemIndex);
+ handleRemoveInvoiceItem(deleteItemIndex);
setDeleteItemIndex(null);
}
}}