Skip to content

Commit

Permalink
ViewCampaignPage: Show page not found, on wrong slug
Browse files Browse the repository at this point in the history
  • Loading branch information
sashko9807 committed Aug 1, 2023
1 parent 553b732 commit 7df2891
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/common/hooks/campaigns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DonationStatus } from 'gql/donations.enums'
import { apiClient } from 'service/apiClient'
import { useCurrentPerson } from 'common/util/useCurrentPerson'
import { isAdmin } from 'common/util/roles'
import { AxiosError, AxiosResponse } from 'axios'

// NOTE: shuffling the campaigns so that each gets its fair chance to be on top row
export const campaignsOrderQueryFunction: QueryFunction<CampaignResponse[]> = async ({
Expand Down Expand Up @@ -77,7 +78,15 @@ export function useCampaignTypesList() {
}

export function useViewCampaign(slug: string) {
return useQuery<{ campaign: CampaignResponse }>([endpoints.campaign.viewCampaign(slug).url])
return useQuery<{ campaign: CampaignResponse }, AxiosError>(
[endpoints.campaign.viewCampaign(slug).url],
{
retry(failureCount, error) {
if (error.isAxiosError && error.response?.status === 404) return false
return true
},
},
)
}

export function useViewCampaignById(id: string) {
Expand Down
11 changes: 9 additions & 2 deletions src/components/client/campaigns/ViewCampaignPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ import CenteredSpinner from 'components/common/CenteredSpinner'
import InlineDonation from './InlineDonation'
import CampaignDetails from './CampaignDetails'
import dynamic from 'next/dynamic'
import NotFoundPage from 'pages/404'

type Props = { slug: string }
const HotJar = dynamic(() => import('common/hotjar/HotJar'), { ssr: false })

export default function ViewCampaignPage({ slug }: Props) {
const { data, isLoading } = useViewCampaign(slug)
const { data, isLoading, isError } = useViewCampaign(slug)
const { mobile, small } = useMobile()
if (isLoading || !data) return <CenteredSpinner size="2rem" />
if (isLoading || !data)
return (
<>
{isLoading && <CenteredSpinner size={'2rem'} />}
{isError && <NotFoundPage />}
</>
)
const { campaign } = data
const ogImageUrl = campaignListPictureUrl(campaign)
const ShouldIncludeHotJar = slug === 'petar-v-cambridge' ? HotJar : () => null
Expand Down

0 comments on commit 7df2891

Please sign in to comment.