Skip to content

Scheduling infrastructure for absolutely everyone.

chore: Adds deprecated-imports-next-router (#14486)

Omar Lópezf2eebe95bde7
diff --git a/apps/web/components/settings/organizations/platform/oauth-clients/OAuthClientForm.tsx b/apps/web/components/settings/organizations/platform/oauth-clients/OAuthClientForm.tsx
index 39ad429caa8..7225896d9d2 100644
--- a/apps/web/components/settings/organizations/platform/oauth-clients/OAuthClientForm.tsx
+++ b/apps/web/components/settings/organizations/platform/oauth-clients/OAuthClientForm.tsx
@@ -1,4 +1,4 @@
-import { useRouter } from "next/router";
+import { useRouter } from "next/navigation";
import type { FC } from "react";
import React, { useState, useCallback, useEffect } from "react";
import { useForm, useFieldArray } from "react-hook-form";
diff --git a/apps/web/pages/settings/organizations/platform/oauth-clients/index.tsx b/apps/web/pages/settings/organizations/platform/oauth-clients/index.tsx
index 5daeb9fb7c7..8daef7c8472 100644
--- a/apps/web/pages/settings/organizations/platform/oauth-clients/index.tsx
+++ b/apps/web/pages/settings/organizations/platform/oauth-clients/index.tsx
@@ -1,5 +1,5 @@
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
-import { useRouter } from "next/router";
+import { useRouter } from "next/navigation";
import React from "react";
import { getLayout } from "@calcom/features/settings/layouts/SettingsLayout";
diff --git a/packages/eslint-plugin/src/configs/recommended.ts b/packages/eslint-plugin/src/configs/recommended.ts
index f1e114d4be4..05c5405e758 100644
--- a/packages/eslint-plugin/src/configs/recommended.ts
+++ b/packages/eslint-plugin/src/configs/recommended.ts
@@ -3,6 +3,7 @@ const recommended = {
parserOptions: { sourceType: "module" },
rules: {
"@calcom/eslint/deprecated-imports": "error",
+ "@calcom/eslint/deprecated-imports-next-router": "error",
"@calcom/eslint/avoid-web-storage": "error",
"@calcom/eslint/avoid-prisma-client-import-for-enums": "error",
},
diff --git a/packages/eslint-plugin/src/rules/deprecated-imports-next-router.ts b/packages/eslint-plugin/src/rules/deprecated-imports-next-router.ts
new file mode 100644
index 00000000000..d0cef9e2297
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/deprecated-imports-next-router.ts
@@ -0,0 +1,38 @@
+import { ESLintUtils } from "@typescript-eslint/utils";
+
+const createRule = ESLintUtils.RuleCreator((name) => `https://developer.cal.com/eslint/rule/${name}`);
+
+const rule = createRule({
+ name: "deprecated-imports-next-router",
+ meta: {
+ fixable: "code",
+ docs: {
+ description: "Importing router from 'next/router' is deprecated, use 'next/navigation' instead",
+ recommended: "error",
+ },
+ messages: {
+ "deprecated-next-router":
+ "Importing router from 'next/router' is deprecated, use 'next/navigation' instead",
+ },
+ type: "problem",
+ schema: [],
+ },
+ defaultOptions: [],
+ create(context) {
+ return {
+ ImportDeclaration(node) {
+ if (node.source.value === "next/router") {
+ context.report({
+ node,
+ messageId: "deprecated-next-router",
+ fix: function (fixer) {
+ return fixer.replaceText(node.source, "'next/navigation'");
+ },
+ });
+ }
+ },
+ };
+ },
+});
+
+export default rule;
diff --git a/packages/eslint-plugin/src/rules/index.ts b/packages/eslint-plugin/src/rules/index.ts
index 60ce1261782..da144ae093d 100644
--- a/packages/eslint-plugin/src/rules/index.ts
+++ b/packages/eslint-plugin/src/rules/index.ts
@@ -5,4 +5,5 @@ export default {
"deprecated-imports": require("./deprecated-imports").default,
"avoid-web-storage": require("./avoid-web-storage").default,
"avoid-prisma-client-import-for-enums": require("./avoid-prisma-client-import-for-enums").default,
+ "deprecated-imports-next-router": require("./deprecated-imports-next-router").default,
} as ESLint.Plugin["rules"];
diff --git a/packages/lib/next-seo.config.ts b/packages/lib/next-seo.config.ts
index edff0d59f4f..27c25901792 100644
--- a/packages/lib/next-seo.config.ts
+++ b/packages/lib/next-seo.config.ts
@@ -1,5 +1,4 @@
import type { DefaultSeoProps, NextSeoProps } from "next-seo";
-import type { Router } from "next/router";
import { APP_NAME, SEO_IMG_DEFAULT, SEO_IMG_OGIMG } from "@calcom/lib/constants";
@@ -47,12 +46,6 @@ export const seoConfig: {
* @param path NextJS' useRouter().asPath
* @returns
*/
-export const buildCanonical = ({
- origin,
- path,
-}: {
- origin: Location["origin"];
- path: Router["asPath"] | null;
-}) => {
+export const buildCanonical = ({ origin, path }: { origin: Location["origin"]; path: string | null }) => {
return `${origin}${path === "/" ? "" : path}`.split("?")[0];
};
diff --git a/packages/platform/examples/base/src/pages/[bookingUid].tsx b/packages/platform/examples/base/src/pages/[bookingUid].tsx
index 54968af26b1..3c85817162d 100644
--- a/packages/platform/examples/base/src/pages/[bookingUid].tsx
+++ b/packages/platform/examples/base/src/pages/[bookingUid].tsx
@@ -2,7 +2,7 @@ import { Navbar } from "@/components/Navbar";
import { CheckCircle2Icon } from "lucide-react";
import { X } from "lucide-react";
import { Inter } from "next/font/google";
-import { useRouter } from "next/router";
+import { useRouter } from "next/navigation";
import { useGetBooking, useCancelBooking } from "@calcom/atoms";
import dayjs from "@calcom/dayjs";
diff --git a/packages/platform/examples/base/src/pages/booking.tsx b/packages/platform/examples/base/src/pages/booking.tsx
index 1a8f8c81efa..e7966168410 100644
--- a/packages/platform/examples/base/src/pages/booking.tsx
+++ b/packages/platform/examples/base/src/pages/booking.tsx
@@ -1,6 +1,6 @@
import { Navbar } from "@/components/Navbar";
import { Inter } from "next/font/google";
-import { useRouter } from "next/router";
+import { useRouter } from "next/navigation";
import { useState } from "react";
import { Booker, useEventTypesPublic } from "@calcom/atoms";
diff --git a/packages/platform/examples/base/src/pages/bookings.tsx b/packages/platform/examples/base/src/pages/bookings.tsx
index d9d38c4db51..ee4e0aed199 100644
--- a/packages/platform/examples/base/src/pages/bookings.tsx
+++ b/packages/platform/examples/base/src/pages/bookings.tsx
@@ -1,6 +1,6 @@
import { Navbar } from "@/components/Navbar";
import { Inter } from "next/font/google";
-import { useRouter } from "next/router";
+import { useRouter } from "next/navigation";
import { useGetBookings } from "@calcom/atoms";
import dayjs from "@calcom/dayjs";