From 08aa132b7cf28aab6cfdd1a8ef597bf6764b3ad4 Mon Sep 17 00:00:00 2001 From: mehditorabiv Date: Wed, 11 Dec 2024 11:37:59 +0300 Subject: [PATCH] fix public view page --- src/pages/reputation-score/index.tsx | 2 +- .../score.tsx} | 23 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) rename src/pages/{[...score].tsx => reputation-score/score.tsx} (90%) diff --git a/src/pages/reputation-score/index.tsx b/src/pages/reputation-score/index.tsx index 201f635..eb03a45 100644 --- a/src/pages/reputation-score/index.tsx +++ b/src/pages/reputation-score/index.tsx @@ -86,7 +86,7 @@ function ReputationScore() { color='primary' onClick={() => router.push( - `/${dynamicNFTModuleInfo?.metadata[0]?.tokenId}/${address}/score` + `/reputation-score/score?tokenId=${dynamicNFTModuleInfo?.metadata[0]?.tokenId}&address=${address}` ) } disabled={!isConnected} diff --git a/src/pages/[...score].tsx b/src/pages/reputation-score/score.tsx similarity index 90% rename from src/pages/[...score].tsx rename to src/pages/reputation-score/score.tsx index 9cb3226..80dd6ff 100644 --- a/src/pages/[...score].tsx +++ b/src/pages/reputation-score/score.tsx @@ -1,7 +1,6 @@ 'use client'; import React, { useEffect, useState } from 'react'; -import { useRouter } from 'next/router'; import { FiShare2 } from 'react-icons/fi'; import GaugeChart from '@/components/global/GaugeChart'; @@ -16,7 +15,6 @@ import { useSnackbar } from '@/context/SnackbarContext'; const ScorePage = () => { const { showMessage } = useSnackbar(); const { retrieveReputationScore } = useAppStore(); - const router = useRouter(); const [communityName, setCommunityName] = useState(null); const [reputationScore, setReputationScore] = useState(null); @@ -41,18 +39,19 @@ const ScorePage = () => { } }; - if (router.isReady) { - const { score } = router.query; // Retrieve query params from URL - if (!score || !Array.isArray(score) || score.length < 2) { - setError('Invalid URL format. Missing tokenId or address.'); - setLoading(false); - return; - } + // Use URLSearchParams to extract query parameters + const params = new URLSearchParams(window.location.search); + const tokenId = params.get('tokenId'); + const address = params.get('address'); - const [tokenId, address] = score; - fetchReputationScore(tokenId, address); + if (!tokenId || !address) { + setError('Invalid URL format. Missing tokenId or address.'); + setLoading(false); + return; } - }, [router.isReady, router.query, retrieveReputationScore]); + + fetchReputationScore(tokenId, address); + }, [retrieveReputationScore]); const gaugeOptions = { chart: {