From 6d09dc7195825c9a05bf8f7c1e7bef7defb53c97 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Tue, 29 Dec 2020 20:27:32 +0200 Subject: [PATCH] try to fix changing custom url bug --- pages/u/[identifier].tsx | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/pages/u/[identifier].tsx b/pages/u/[identifier].tsx index b47346a90..b6cab3b9c 100644 --- a/pages/u/[identifier].tsx +++ b/pages/u/[identifier].tsx @@ -14,14 +14,14 @@ import { useBuildsByUser } from "hooks/u"; import { GANBA_DISCORD_ID } from "lib/constants"; import { getFullUsername } from "lib/strings"; import useUser from "lib/useUser"; -import { isCustomUrl } from "lib/validators/profile"; import { GetStaticPaths, GetStaticProps } from "next"; +import { useRouter } from "next/router"; import { getPlayersPeak } from "prisma/queries/getPlayersPeak"; import { getUserByIdentifier, GetUserByIdentifierData, } from "prisma/queries/getUserByIdentifier"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { FiEdit } from "react-icons/fi"; import { RiTShirtLine } from "react-icons/ri"; import useSWR from "swr"; @@ -33,6 +33,7 @@ interface Props { } const ProfilePage = (props: Props) => { + const router = useRouter(); const [showProfileModal, setShowProfileModal] = useState(false); const [buildToEdit, setBuildToEdit] = useState(false); @@ -51,6 +52,14 @@ const ProfilePage = (props: Props) => { props.user?.profile?.weaponPool ); + useEffect(() => { + if (user.profile?.customUrlPath) { + router.replace({ + pathname: `/u/${user.profile.customUrlPath}`, + }); + } + }, []); + const { i18n } = useLingui(); const canPostBuilds = () => { @@ -173,17 +182,6 @@ export const getStaticProps: GetStaticProps = async ({ params }) => { const user = await getUserByIdentifier(params!.identifier as string); if (!user) return { notFound: true }; - if ( - user.profile?.customUrlPath && - !isCustomUrl(params!.identifier as string) - ) { - return { - redirect: { - destination: `/u/${user.profile.customUrlPath}`, - permanent: true, - }, - }; - } const peak = user.player?.switchAccountId ? await getPlayersPeak(user.player.switchAccountId)