Skip to content

Commit

Permalink
chore: upgrade react router v7
Browse files Browse the repository at this point in the history
  • Loading branch information
nihalgonsalves committed Nov 25, 2024
1 parent cf33662 commit 6396a88
Show file tree
Hide file tree
Showing 27 changed files with 75 additions and 72 deletions.
2 changes: 1 addition & 1 deletion packages/frontend/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Preview } from "@storybook/react";
import "../src/tailwind.css";
import { MemoryRouter } from "react-router-dom";
import { MemoryRouter } from "react-router";

const preview: Preview = {
parameters: {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"react-helmet": "^6.1.0",
"react-hook-form": "^7.53.2",
"react-hot-toast": "^2.4.1",
"react-router-dom": "^6.27.0",
"react-router": "^7.0.1",
"react-twc": "^1.4.2",
"react-use": "^17.5.1",
"tailwind-merge": "^2.5.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
matchRoutes,
useLocation,
useNavigationType,
} from "react-router-dom";
} from "react-router";

import { TrpcProvider } from "./api/TrpcProvider";
import { useOffLineToaster } from "./api/useOffLineToaster";
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/CategoryStats.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from "react";
import type { DateRange } from "react-day-picker";
import { Link } from "react-router-dom";
import { Link } from "react-router";

import {
addMoney,
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/FloatingActionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AccessibleIcon } from "@radix-ui/react-accessible-icon";
import { motion } from "framer-motion";
import React from "react";
import { Link } from "react-router-dom";
import { Link } from "react-router";

import { Button } from "./ui/button";
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/NavBarAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AccessibleIcon } from "@radix-ui/react-accessible-icon";
import { AvatarIcon } from "@radix-ui/react-icons";
import { Link } from "react-router-dom";
import { Link } from "react-router";

import { trpc } from "../api/trpc";
import { useResetCache } from "../api/useCacheReset";
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/ResetPasswordForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { useNavigate } from "react-router-dom";
import { useNavigate } from "react-router";
import type { z } from "zod";

import { ZResetPasswordInput } from "@nihalgonsalves/expenses-shared/types/user";
Expand Down Expand Up @@ -38,7 +38,7 @@ export const ResetPasswordForm = ({ token }: { token: string }) => {
const onSubmit = async (values: z.infer<typeof ZResetPasswordInput>) => {
await resetPassword(values);

navigate("/auth/sign-in");
await navigate("/auth/sign-in");
};

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/SheetsList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AccessibleIcon } from "@radix-ui/react-accessible-icon";
import { PlusIcon } from "@radix-ui/react-icons";
import { useMemo, useState } from "react";
import { Link } from "react-router-dom";
import { Link } from "react-router";

import type { SheetsResponse } from "@nihalgonsalves/expenses-shared/types/sheet";

Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/VerifyEmailForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useNavigate } from "react-router-dom";
import { useNavigate } from "react-router";

import { trpc } from "../api/trpc";

Expand All @@ -18,7 +18,7 @@ export const VerifyEmailForm = ({ token }: { token: string }) => {
await verifyEmail(token);
await utils.user.me.invalidate();

navigate("/settings");
await navigate("/settings");
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TrashIcon,
} from "@radix-ui/react-icons";
import { useCallback, useState } from "react";
import { useNavigate } from "react-router-dom";
import { useNavigate } from "react-router";

import type { Money } from "@nihalgonsalves/expenses-shared/money";
import type {
Expand Down Expand Up @@ -73,7 +73,7 @@ const PersonMenu = ({
]);

if (actorInfo.id === id) {
navigate("/groups");
await navigate("/groups");
}
} catch {
setIsInvalidating(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { AccessibleIcon } from "@radix-ui/react-accessible-icon";
import { PersonIcon, PlusIcon, TrashIcon } from "@radix-ui/react-icons";
import { useFieldArray, useForm } from "react-hook-form";
import { useNavigate } from "react-router-dom";
import { useNavigate } from "react-router";
import type { z } from "zod";

import { ZCreateGroupSheetInput } from "@nihalgonsalves/expenses-shared/types/sheet";
Expand Down Expand Up @@ -64,7 +64,7 @@ export const CreateGroupForm = ({
const { id } = await createGroupSheet(values);

dialog.dismiss();
navigate(`/groups/${id}`, { replace: true });
await navigate(`/groups/${id}`, { replace: true });

await utils.sheet.mySheets.invalidate();
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActivityLogIcon } from "@radix-ui/react-icons";
import { Link } from "react-router-dom";
import { Link } from "react-router";

import type { GroupSheetByIdResponse } from "@nihalgonsalves/expenses-shared/types/sheet";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArchiveIcon, TrashIcon } from "@radix-ui/react-icons";
import { useCallback } from "react";
import { useNavigate } from "react-router-dom";
import { useNavigate } from "react-router";

import type { Sheet } from "@nihalgonsalves/expenses-shared/types/sheet";

Expand All @@ -27,7 +27,7 @@ export const GroupSheetAdminSection = ({
void utils.sheet.groupSheetById.invalidate(groupSheet.id);
void utils.sheet.mySheets.invalidate();

navigate("/sheets");
await navigate("/sheets");
}, [deleteGroupSheet, groupSheet.id, navigate, utils]);

const handleArchive = useCallback(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { ThickArrowDownIcon, ThickArrowUpIcon } from "@radix-ui/react-icons";
import { useForm, useWatch } from "react-hook-form";
import { useNavigate } from "react-router-dom";
import { useNavigate } from "react-router";
import { z } from "zod";

import type { Sheet } from "@nihalgonsalves/expenses-shared/types/sheet";
Expand Down Expand Up @@ -180,7 +180,7 @@ const CreatePersonalTransactionForm = ({
freq: values.recurrenceRule.freq,
},
});
navigate(`/sheets/${personalSheet.id}`, { replace: true });
await navigate(`/sheets/${personalSheet.id}`, { replace: true });
} else {
await createPersonalSheetTransaction({
...commonValues,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { PlusCircledIcon } from "@radix-ui/react-icons";
import { useForm } from "react-hook-form";
import { useNavigate } from "react-router-dom";
import { useNavigate } from "react-router";
import type { z } from "zod";

import { ZCreatePersonalSheetInput } from "@nihalgonsalves/expenses-shared/types/sheet";
Expand Down Expand Up @@ -50,7 +50,7 @@ export const CreateSheetForm = ({
const { id } = await createSheet(values);

dialog.dismiss();
navigate(`/sheets/${id}`, { replace: true });
await navigate(`/sheets/${id}`, { replace: true });

await utils.sheet.mySheets.invalidate();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TrashIcon,
UploadIcon,
} from "@radix-ui/react-icons";
import { Link } from "react-router-dom";
import { Link } from "react-router";

import type { Sheet } from "@nihalgonsalves/expenses-shared/types/sheet";
import type { TransactionListItem } from "@nihalgonsalves/expenses-shared/types/transaction";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArchiveIcon, TrashIcon } from "@radix-ui/react-icons";
import { useCallback } from "react";
import { useNavigate } from "react-router-dom";
import { useNavigate } from "react-router";

import type { Sheet } from "@nihalgonsalves/expenses-shared/types/sheet";

Expand All @@ -22,9 +22,11 @@ export const PersonalSheetAdminSection = ({

const handleDelete = useCallback(async () => {
await deleteSheet(personalSheet.id);
void utils.sheet.personalSheetById.invalidate(personalSheet.id);
void utils.sheet.mySheets.invalidate();
navigate("/sheets");
await Promise.all([
utils.sheet.personalSheetById.invalidate(personalSheet.id),
utils.sheet.mySheets.invalidate(),
]);
await navigate("/sheets");
}, [deleteSheet, personalSheet.id, navigate, utils]);

const handleArchive = useCallback(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { parse as dateFnsParse } from "date-fns";
import Papa from "papaparse";
import { useCallback, useId, useMemo, useState } from "react";
import { useNavigate } from "react-router-dom";
import { useNavigate } from "react-router";
import { z } from "zod";

import type { Sheet } from "@nihalgonsalves/expenses-shared/types/sheet";
Expand Down Expand Up @@ -391,7 +391,7 @@ export const PersonalTransactionsImporter = ({
personalSheetId: personalSheet.id,
});

navigate(`/sheets/${personalSheet.id}`);
await navigate(`/sheets/${personalSheet.id}`);
};

const fieldOptions = useMemo(
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/settings/PrivacyForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { useNavigate } from "react-router-dom";
import { useNavigate } from "react-router";
import type { z } from "zod";

import { ZAuthorizeUserInput } from "@nihalgonsalves/expenses-shared/types/user";
Expand Down Expand Up @@ -45,7 +45,7 @@ export const PrivacyForm = () => {
await anonymizeUser({ email: values.email, password: values.password });

await resetCache();
navigate("/");
await navigate("/");
};

const disabled = !onLine;
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/transactions/columns.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { createColumnHelper, type ColumnDef } from "@tanstack/react-table";
import { Link } from "react-router-dom";
import { Link } from "react-router";

import type { ConvertedTransactionWithSheet } from "../../api/useAllUserTransactions";
import { useCurrentUser } from "../../api/useCurrentUser";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from "@tanstack/react-table";
import { Fragment, useCallback, useEffect, useState } from "react";
import type { DateRange } from "react-day-picker";
import { useSearchParams } from "react-router-dom";
import { useSearchParams } from "react-router";
import { z } from "zod";

import type { ConvertedTransactionWithSheet } from "../../api/useAllUserTransactions";
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/AuthenticationPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Navigate, useMatch, useSearchParams } from "react-router-dom";
import { Navigate, useMatch, useSearchParams } from "react-router";

import { useCurrentUser } from "../api/useCurrentUser";
import { SignInForm } from "../components/SignInForm";
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/ResetPasswordPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useSearchParams } from "react-router-dom";
import { useSearchParams } from "react-router";

import { ResetPasswordForm } from "../components/ResetPasswordForm";
import { Alert, AlertTitle } from "../components/ui/alert";
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { AnimatePresence, motion, useReducedMotion } from "framer-motion";
import { useCallback, useState } from "react";
import { Helmet } from "react-helmet";
import { toast } from "react-hot-toast";
import { NavLink, useNavigate } from "react-router-dom";
import { NavLink, useNavigate } from "react-router";
import { useInterval } from "react-use";

import { trpc } from "../api/trpc";
Expand Down Expand Up @@ -106,7 +106,7 @@ export const Root = ({
$variant="ghost"
className="text-primary-foreground md:hidden"
onClick={() => {
navigate(-1);
void navigate(-1);
}}
>
<ArrowLeftIcon />
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/VerifyEmailPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useSearchParams } from "react-router-dom";
import { useSearchParams } from "react-router";

import { VerifyEmailForm } from "../components/VerifyEmailForm";
import { Alert, AlertTitle } from "../components/ui/alert";
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
useLocation,
Outlet,
type RouteObject,
} from "react-router-dom";
} from "react-router";
import { z, type ZodRawShape } from "zod";

import {
Expand Down Expand Up @@ -174,4 +174,4 @@ export const useParams = <T extends ZodRawShape>(schema: Zod.ZodObject<T>) => {

export const SheetParams = z.object({ sheetId: z.string() });

export { RouterProvider } from "react-router-dom";
export { RouterProvider } from "react-router/dom";
Loading

0 comments on commit 6396a88

Please sign in to comment.