Skip to content

Commit 130ae88

Browse files
committed
Fix redirects
1 parent a55df42 commit 130ae88

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

api/codeItems/useDeleteCodeItem.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import { useSnackbar } from "notistack";
22
import { fetchService } from "@/services";
33
import { useMutation, useQueryClient } from "@tanstack/react-query";
44
import { ApiResponse, CODEITEMS_API_ENDPOINT } from "@/types";
5+
import { useSearchParams } from "next/navigation";
56

67
export const useDeleteCodeItem = () => {
78
const queryClient = useQueryClient();
89
const { enqueueSnackbar } = useSnackbar();
10+
const searchParams = useSearchParams();
11+
const categoryId = searchParams.get("categoryId");
12+
const q = searchParams.get("q");
13+
const labels = searchParams.getAll("label");
914

1015
const { mutateAsync: deleteCodeItem, isPending } = useMutation({
1116
mutationFn: async (codeItemId: string) => {
@@ -20,8 +25,8 @@ export const useDeleteCodeItem = () => {
2025
throw new Error(response.error);
2126
}
2227

23-
await queryClient.invalidateQueries({
24-
queryKey: [CODEITEMS_API_ENDPOINT],
28+
await queryClient.refetchQueries({
29+
queryKey: [CODEITEMS_API_ENDPOINT, q, categoryId, labels],
2530
});
2631
},
2732
onSuccess: () => {

app/about/page.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Metadata } from "next";
22
import { Container, Typography, List, ListItem, Box } from "@mui/material";
33
import { Button } from "@/components/buttons";
44
import Link from "next/link";
5-
import Image from "next/image";
5+
import Image from "next/legacy/image";
66

77
export const metadata: Metadata = {
88
title: "About My Lib - Your Personal Code Library",
@@ -95,7 +95,8 @@ export default function AboutPage() {
9595
src="/about/categories.png"
9696
alt="Categories example"
9797
objectFit="contain"
98-
fill
98+
layout="fill"
99+
quality={100}
99100
/>
100101
</Box>
101102

@@ -116,7 +117,8 @@ export default function AboutPage() {
116117
src="/about/code-items-styles.png"
117118
alt="Code items example"
118119
objectFit="contain"
119-
fill
120+
layout="fill"
121+
quality={100}
120122
/>
121123
</Box>
122124
</Box>

app/login/page.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Grid, Typography } from "@mui/material";
33
import GoogleIcon from "@mui/icons-material/Google";
44
import * as z from "zod";
55
import { signIn } from "next-auth/react";
6-
import { useRouter, useSearchParams } from "next/navigation";
6+
import { useSearchParams } from "next/navigation";
77
import { useState } from "react";
88
import { Button, Form, TextInput, Link } from "@/components";
99
import { FieldValues } from "react-hook-form";
@@ -19,7 +19,6 @@ const schema = z.object({
1919

2020
const Login = () => {
2121
const [isLoading, setIsLoading] = useState(false);
22-
const { replace, refresh } = useRouter();
2322
const { enqueueSnackbar } = useSnackbar();
2423
const searchParams = useSearchParams();
2524
const callbackUrl = searchParams.get("callbackUrl") || "/";
@@ -36,8 +35,7 @@ const Login = () => {
3635
if (res?.error) {
3736
enqueueSnackbar(`${res?.error}`, { variant: "error" });
3837
} else {
39-
refresh();
40-
replace("/");
38+
window.location.assign("/");
4139
}
4240
} catch (err) {
4341
enqueueSnackbar(`${err}`, { variant: "error" });

app/registration/page.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useState } from "react";
33
import { Grid, Typography } from "@mui/material";
44
import * as z from "zod";
55
import { FieldValues } from "react-hook-form";
6-
import { useRouter } from "next/navigation";
76
import { Button, Form, TextInput, Link } from "@/components";
87
import { fetchService } from "@/services";
98
import { useSnackbar } from "notistack";
@@ -26,7 +25,6 @@ const schema = z
2625

2726
const Registration = () => {
2827
const [isLoading, setIsLoading] = useState(false);
29-
const { replace, refresh } = useRouter();
3028
const { enqueueSnackbar } = useSnackbar();
3129

3230
const onSubmit = async (data: FieldValues) => {
@@ -49,12 +47,11 @@ const Registration = () => {
4947
});
5048

5149
if (!result?.error && result?.status === 200) {
50+
window.location.assign("/");
51+
5252
enqueueSnackbar("Sign up successful. Welcome to My lib", {
5353
variant: "success",
5454
});
55-
56-
refresh();
57-
replace("/");
5855
} else {
5956
enqueueSnackbar(result?.error, { variant: "error" });
6057
}

0 commit comments

Comments
 (0)