Skip to content

Commit

Permalink
refactor: change AccountQueryParamSnackbar to use SearchParamsLoader
Browse files Browse the repository at this point in the history
Refs: #437
  • Loading branch information
P-manBrown committed Dec 25, 2024
1 parent aecdd65 commit 1ab8372
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
'use client'

import { useSearchParams } from 'next/navigation'
import { useEffect } from 'react'
import { ReadonlyURLSearchParams } from 'next/navigation'
import { useEffect, useState } from 'react'
import { useSnackbarsStore } from '@/app/_components/snackbars/use-snackbars-store'
import { SearchParamsLoader } from '@/components/search-params-loader'
import { useQueryParams } from '@/utils/query-param/use-query-params'

export function AccountQueryParamSnackbar() {
const searchParams = useSearchParams()
const accountConfSuccess = searchParams.get('account_confirmation_success')
const [searchParams, setSearchParams] =
useState<ReadonlyURLSearchParams | null>(null)
const accountConfSuccess = searchParams?.get('account_confirmation_success')
const openSnackbar = useSnackbarsStore((state) => state.openSnackbar)
const { cleanupQueryParams } = useQueryParams({ searchParams })

useEffect(() => {
if (searchParams.toString()) {
if (searchParams?.toString()) {
if (accountConfSuccess === 'true') {
openSnackbar({
severity: 'success',
Expand All @@ -28,5 +30,5 @@ export function AccountQueryParamSnackbar() {
}
}, [accountConfSuccess, openSnackbar, cleanupQueryParams, searchParams])

return null
return <SearchParamsLoader onParamsReceived={setSearchParams} />
}
4 changes: 1 addition & 3 deletions src/components/pages/account-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export function AccountPage() {
<Suspense fallback={<LoadingDeleteCurrentUserAccountButton />}>
<DeleteCurrentUserAccountButton />
</Suspense>
<Suspense>
<AccountQueryParamSnackbar />
</Suspense>
<AccountQueryParamSnackbar />
</div>
)
}

0 comments on commit 1ab8372

Please sign in to comment.