Skip to content

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

chore: update Playwright test version and refactor CTA toast logic (#151)

Vlad Sazonaud2178fafa170
diff --git a/.cursor/rules/project-structure.mdc b/.cursor/rules/project-structure.mdc
index bf61a4e..4ee5b5e 100644
--- a/.cursor/rules/project-structure.mdc
+++ b/.cursor/rules/project-structure.mdc
@@ -1,11 +1,13 @@
---
-description:
-globs:
+description:
+globs:
alwaysApply: true
---
+
Project Structure and Architecture Guidelines
Directory Structure:
+
```
├── app/ # Next.js App Router directory
│ ├── (auth)/ # Auth-related routes (grouped)
@@ -23,18 +25,21 @@ Directory Structure:
```
Component Organization:
+
- Group related components in feature directories
- Keep components small and focused
- Extract reusable logic into custom hooks
- Place shared types in dedicated files
File Naming:
+
- Use kebab-case for directories and files
- Components: PascalCase.tsx
- Utilities: camelCase.ts
- Types: PascalCase.types.ts
Component Structure:
+
```typescript
// types.ts
interface Props {
@@ -47,8 +52,8 @@ function helperFunction() {
}
// Component.tsx
-import { type Props } from './types';
-import { helperFunction } from './helpers';
+import { type Props } from "./types";
+import { helperFunction } from "./helpers";
export function Component({ prop1, prop2 }: Props) {
// ... component logic
@@ -56,24 +61,57 @@ export function Component({ prop1, prop2 }: Props) {
```
Data Fetching:
+
- Use Server Components for data fetching
- Implement proper caching strategies
- Handle loading and error states
- Use React Suspense boundaries
Route Organization:
+
- Group related routes in directories
- Use route groups (parentheses) for organization
- Keep page components lean
- Extract business logic to separate files
State Management:
+
- Use Server Components when possible
- Keep client state minimal
- Use React Context sparingly
API Structure:
+
- Organize by feature/resource
- Use consistent error handling
- Implement proper validation
- Follow RESTful conventions
+
+Red flags in a React codebase
+
+🚩 functions like <button onClick={handleClick}
+
+- handleClick doesn't explain what it does
+- you lose colocation
+- need new names for each callback
+
+Inline callbacks can call multiple functions with good names
+
+onClick={() => {
+analytics.event('this-button')
+openModal()
+
+🚩 useMemo
+
+React devs are terrified of renders and often overuseMemo
+
+- memoize things that you pass as props to components that may have expensive children
+- it's ok for leaf components to over-render
+
+useMemo does not fix bugs, it just makes them happen less often
+
+🚩 <div onClick
+
+divs are not interactive elements and adding onClick requires implementing keyboard control, screen reader announcement, etc
+
+This is almost never the right move, and anyone capable of doing it right (the new tweet button) isn't going to be swayed by this tweet
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
index c9f47b7..6bd3964 100644
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -65,7 +65,7 @@ jobs:
- uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 #4.6.1
name: 🎲 Upload Playwright report
- if: always()
+ if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-output/report/
diff --git a/package.json b/package.json
index 864acf4..01d2ba4 100644
--- a/package.json
+++ b/package.json
@@ -91,7 +91,7 @@
"devDependencies": {
"@eslint/eslintrc": "3.3.1",
"@next/eslint-plugin-next": "15.2.3",
- "@playwright/test": "1.52.0",
+ "@playwright/test": "1.56.1",
"@types/file-saver": "2.0.7",
"@types/node": "22.8.1",
"@types/pdf-parse": "1.1.5",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 41952e7..343cab8 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -66,7 +66,7 @@ importers:
version: 4.3.0([email protected])
"@sentry/nextjs":
specifier: 9.3.0
- version: 9.3.0(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected])
+ version: 9.3.0(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected])
"@t3-oss/env-nextjs":
specifier: 0.13.4
@@ -87,7 +87,7 @@ importers:
version: 1.34.6
"@vercel/speed-insights":
specifier: 1.2.0
class-variance-authority:
specifier: 0.7.1
version: 0.7.1
@@ -129,10 +129,10 @@ importers:
version: 1.21.0
next:
specifier: 14.2.15
next-intl:
specifier: 4.0.2
pdf-parse:
specifier: 1.1.1
version: 1.1.1
@@ -183,8 +183,8 @@ importers:
specifier: 15.2.3
version: 15.2.3
"@playwright/test":
- specifier: 1.52.0
- version: 1.52.0
+ specifier: 1.56.1
+ version: 1.56.1
"@types/file-saver":
specifier: 2.0.7
version: 2.0.7
@@ -238,10 +238,10 @@ importers:
version: 0.6.11([email protected])
react-email:
specifier: 4.0.4
react-scan:
specifier: 0.3.4
schema-dts:
specifier: 1.1.5
version: 1.1.5
@@ -2067,10 +2067,10 @@ packages:
}
engines: { node: ">=14" }
- "@playwright/[email protected]":
+ "@playwright/[email protected]":
resolution:
{
- integrity: sha512-uh6W7sb55hl7D6vsAeA+V2p5JnlAqzhqFyF0VcJkKZXkgnFcVG9PziERRHQfPLfNGx1C292a4JqbWzhR8L4R1g==,
+ integrity: sha512-vSMYtL/zOcFpvJCW71Q/OEGQb7KYBPAdKh35WNSkaZA75JlAO8ED8UN6GUNTm3drWomcbcqRPFqQbLae8yBTdg==,
}
engines: { node: ">=18" }
hasBin: true
@@ -8728,6 +8728,14 @@ packages:
engines: { node: ">=18" }
hasBin: true
+ resolution:
+ {
+ integrity: sha512-hutraynyn31F+Bifme+Ps9Vq59hKuUCz7H1kDOcBs+2oGguKkWTU50bBWrtz34OUWmIwpBTWDxaRPXrIXkgvmQ==,
+ }
+ engines: { node: ">=18" }
+ hasBin: true
+
resolution:
{
@@ -8736,6 +8744,14 @@ packages:
engines: { node: ">=18" }
hasBin: true
+ resolution:
+ {
+ integrity: sha512-aFi5B0WovBHTEvpM3DzXTUaeN6eN0qWnTkKx4NQaH4Wvcmc153PdaY2UBdSYKaGYw+UyWXSVyxDUg5DoPEttjw==,
+ }
+ engines: { node: ">=18" }
+ hasBin: true
+
resolution:
{
@@ -12178,9 +12194,9 @@ snapshots:
optional: true
- "@playwright/[email protected]":
+ "@playwright/[email protected]":
dependencies:
- playwright: 1.52.0
+ playwright: 1.56.1
"@preact/[email protected]": {}
@@ -13153,7 +13169,7 @@ snapshots:
"@sentry/[email protected]": {}
dependencies:
"@opentelemetry/api": 1.9.0
"@opentelemetry/semantic-conventions": 1.30.0
@@ -13166,7 +13182,7 @@ snapshots:
"@sentry/vercel-edge": 9.3.0
"@sentry/webpack-plugin": 3.1.2([email protected])
chalk: 3.0.0
resolve: 1.22.8
rollup: 3.29.5
stacktrace-parser: 0.1.11
@@ -13619,9 +13635,9 @@ snapshots:
dependencies:
crypto-js: 4.2.0
optionalDependencies:
react: 18.3.1
"@vitest/[email protected]":
@@ -16419,17 +16435,17 @@ snapshots:
dependencies:
"@formatjs/intl-localematcher": 0.5.10
negotiator: 1.0.0
react: 18.3.1
use-intl: 4.0.2([email protected])
optionalDependencies:
typescript: 5.9.3
dependencies:
"@next/env": 14.2.15
"@swc/helpers": 0.5.5
@@ -16451,12 +16467,12 @@ snapshots:
"@next/swc-win32-ia32-msvc": 14.2.15
"@next/swc-win32-x64-msvc": 14.2.15
"@opentelemetry/api": 1.9.0
- "@playwright/test": 1.52.0
+ "@playwright/test": 1.56.1
transitivePeerDependencies:
- "@babel/core"
- babel-plugin-macros
dependencies:
"@next/env": 15.2.3
"@swc/counter": 0.1.3
@@ -16477,7 +16493,7 @@ snapshots:
"@next/swc-win32-arm64-msvc": 15.2.3
"@next/swc-win32-x64-msvc": 15.2.3
"@opentelemetry/api": 1.9.0
- "@playwright/test": 1.52.0
+ "@playwright/test": 1.56.1
sharp: 0.33.5
transitivePeerDependencies:
- "@babel/core"
@@ -16739,12 +16755,20 @@ snapshots:
+
dependencies:
playwright-core: 1.52.0
optionalDependencies:
fsevents: 2.3.2
+ dependencies:
+ playwright-core: 1.56.1
+ optionalDependencies:
+ fsevents: 2.3.2
+
@@ -16894,7 +16918,7 @@ snapshots:
react: 18.3.1
scheduler: 0.23.2
dependencies:
"@babel/parser": 7.24.5
"@babel/traverse": 7.25.6
@@ -16906,7 +16930,7 @@ snapshots:
glob: 10.3.4
log-symbols: 4.1.0
mime-types: 2.1.35
normalize-path: 3.0.0
ora: 5.4.1
socket.io: 4.8.1
@@ -16986,7 +17010,7 @@ snapshots:
optionalDependencies:
"@types/react": 18.3.12
dependencies:
"@babel/core": 7.26.9
"@babel/generator": 7.26.9
@@ -17008,7 +17032,7 @@ snapshots:
react-dom: 18.3.1([email protected])
tsx: 4.19.4
optionalDependencies:
unplugin: 2.1.0
transitivePeerDependencies:
- "@types/react"
diff --git a/src/app/(app)/components/invoice-pdf-download-link.tsx b/src/app/(app)/components/invoice-pdf-download-link.tsx
index 9e90abe..a41ccdd 100644
--- a/src/app/(app)/components/invoice-pdf-download-link.tsx
+++ b/src/app/(app)/components/invoice-pdf-download-link.tsx
@@ -123,7 +123,7 @@ export function InvoicePDFDownloadLink({
"Your support helps me keep this free tool running and build even better features! 🙏",
});
}
- }, 4000);
+ }, 3000);
}
},
[
diff --git a/src/app/(app)/hooks/use-engagement-cta.tsx b/src/app/(app)/hooks/use-engagement-cta.tsx
deleted file mode 100644
index ecd380b..0000000
--- a/src/app/(app)/hooks/use-engagement-cta.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-"use client";
-
-import { useEffect } from "react";
-import { showRandomCTAToast } from "../components/cta-toasts";
-
-const CTA_TOAST_SHOWN_LOCAL_STORAGE_KEY = "EASY_INVOICE_CTA_TOAST_SHOWN";
-const INTERACTION_COUNT_THRESHOLD = 2;
-const DELAY_BEFORE_SHOWING_CTA_TOAST = 15_000;
-
-/**
- * This hook is used to show a CTA toast after a certain number of interactions with the page.
- */
-export function useShowRandomCTAToastOnEngagement() {
- useEffect(() => {
- if (process.env.NODE_ENV !== "production") return;
-
- const hasShown = localStorage.getItem(CTA_TOAST_SHOWN_LOCAL_STORAGE_KEY);
-
- if (hasShown) return;
-
- let interactionCount = 0;
- let timer: ReturnType<typeof setTimeout> | null = null;
-
- const handleInteraction = () => {
- interactionCount++;
-
- if (interactionCount === INTERACTION_COUNT_THRESHOLD) {
- timer = setTimeout(() => {
- showRandomCTAToast();
- localStorage.setItem(CTA_TOAST_SHOWN_LOCAL_STORAGE_KEY, "true");
- }, DELAY_BEFORE_SHOWING_CTA_TOAST);
-
- window.removeEventListener("click", handleInteraction);
- }
- };
-
- window.addEventListener("click", handleInteraction);
-
- return () => {
- window.removeEventListener("click", handleInteraction);
- if (timer) {
- clearTimeout(timer);
- }
- };
- }, []);
-}
diff --git a/src/app/(app)/hooks/use-show-random-cta-toast.tsx b/src/app/(app)/hooks/use-show-random-cta-toast.tsx
new file mode 100644
index 0000000..ed15e2c
--- /dev/null
+++ b/src/app/(app)/hooks/use-show-random-cta-toast.tsx
@@ -0,0 +1,112 @@
+"use client";
+
+import { useEffect } from "react";
+import { umamiTrackEvent } from "@/lib/umami-analytics-track-event";
+import { showRandomCTAToast } from "../components/cta-toasts";
+import dayjs from "dayjs";
+import duration from "dayjs/plugin/duration";
+
+dayjs.extend(duration);
+
+const STORAGE_KEY = "EASY_INVOICE_CTA_LAST_SHOWN_AT";
+const COOLDOWN_DAYS = 7;
+const MIN_TIME_ON_PAGE = 15_000; // in milliseconds
+const IDLE_TIME = 5_000; // in milliseconds
+
+/**
+ * This hook is used to show a CTA toast after a certain number of interactions with the page.
+ *
+ * - User stays on page 10s (MIN_TIME_ON_PAGE) → we consider them “present”.
+ * - Any real interaction (type, click) → we mark them engaged.
+ * - Once they stop interacting for X seconds (IDLE_TIME) → toast appears.
+ */
+export function useShowRandomCTAToast() {
+ useEffect(() => {
+ const last = localStorage.getItem(STORAGE_KEY);
+
+ // Check if the last time the CTA toast was shown was less than 7 days ago
+ // Parse and validate the stored timestamp
+ const parsedLast = last ? Number(last) : NaN;
+ const isValidTimestamp = Number.isFinite(parsedLast);
+
+ // If invalid timestamp, clear it from storage and treat as not in cooldown
+ if (last && !isValidTimestamp) {
+ localStorage.removeItem(STORAGE_KEY);
+ }
+
+ const isWithinCooldownPeriod =
+ isValidTimestamp &&
+ dayjs().diff(dayjs(parsedLast)) <
+ dayjs.duration(COOLDOWN_DAYS, "day").asMilliseconds();
+
+ // If the last time the CTA toast was shown was less than 7 days ago, skip showing the toast
+ if (last && isWithinCooldownPeriod) {
+ umamiTrackEvent("cta_toast_skipped_recently");
+ return;
+ }
+
+ let timeOnPageTimer: ReturnType<typeof setTimeout> | null = null;
+ let idleTimer: ReturnType<typeof setTimeout> | null = null;
+ let hasMeaningfulInteraction = false;
+ let hasMinTimeElapsed = false;
+ let triggered = false;
+
+ function tryTrigger() {
+ if (triggered) return;
+ if (!hasMeaningfulInteraction) return;
+ if (!hasMinTimeElapsed) return;
+
+ triggered = true;
+ showRandomCTAToast();
+
+ // save last shown timestamp to localStorage
+ localStorage.setItem(STORAGE_KEY, String(Date.now()));
+
+ // track event
+ umamiTrackEvent("cta_toast_shown");
+ }
+
+ function handleIdle() {
+ idleTimer = setTimeout(() => {
+ tryTrigger();
+ }, IDLE_TIME);
+ }
+
+ function resetIdle() {
+ if (idleTimer) clearTimeout(idleTimer);
+ handleIdle();
+ }
+
+ function handleMeaningfulInteraction() {
+ hasMeaningfulInteraction = true;
+ }
+
+ // start tracking
+ timeOnPageTimer = setTimeout(() => {
+ // user has been here long enough, now wait for idle
+ hasMinTimeElapsed = true;
+ handleIdle();
+ }, MIN_TIME_ON_PAGE);
+
+ // interaction types
+ window.addEventListener("pointerdown", handleMeaningfulInteraction);
+ window.addEventListener("keydown", handleMeaningfulInteraction);
+ // window.addEventListener("scroll", resetIdle, {
+ // passive: true,
+ // capture: true,
+ // });
+ window.addEventListener("pointerdown", resetIdle);
+ window.addEventListener("keydown", resetIdle);
+
+ return () => {
+ if (timeOnPageTimer) clearTimeout(timeOnPageTimer);
+ if (idleTimer) clearTimeout(idleTimer);
+
+ window.removeEventListener("pointerdown", handleMeaningfulInteraction);
+ window.removeEventListener("keydown", handleMeaningfulInteraction);
+ // window.removeEventListener("scroll", resetIdle);
+ window.removeEventListener("pointerdown", resetIdle);
+ window.removeEventListener("keydown", resetIdle);
+ };
+ }, []);
+}
diff --git a/src/app/(app)/page.client.tsx b/src/app/(app)/page.client.tsx
index 6465d6b..490cd88 100644
--- a/src/app/(app)/page.client.tsx
+++ b/src/app/(app)/page.client.tsx
@@ -46,7 +46,7 @@ import { z } from "zod";
import { InvoiceClientPage } from "./components";
import { InvoicePDFDownloadLink } from "./components/invoice-pdf-download-link";
import { handleInvoiceNumberBreakingChange } from "./utils/invoice-number-breaking-change";
-import { useShowRandomCTAToastOnEngagement } from "./hooks/use-engagement-cta";
+import { useShowRandomCTAToast } from "./hooks/use-show-random-cta-toast";
// import { DevLocalStorageView } from "./components/dev/dev-local-storage-view";
// import { InvoicePDFDownloadMultipleLanguages } from "./components/invoice-pdf-download-multiple-languages";
@@ -86,7 +86,7 @@ export function AppPageClient({
const [canShareInvoice, setCanShareInvoice] = useState(true);
- useShowRandomCTAToastOnEngagement();
+ useShowRandomCTAToast();
// Helper function to load from localStorage
const loadFromLocalStorage = useCallback(() => {
diff --git a/src/components/footer.tsx b/src/components/footer.tsx
index 4f33ab4..7c1337d 100644
--- a/src/components/footer.tsx
+++ b/src/components/footer.tsx
@@ -130,7 +130,7 @@ export function Footer({
<p className="text-xs text-slate-500">
{translations.footerCreatedBy}{" "}
<Link
- href="https://github.com/VladSez"
+ href="https://dub.sh/vladsazon.com"
target="_blank"
rel="noopener noreferrer"
className="underline hover:text-slate-900"