Skip to content

Commit

Permalink
Redirect user back to names page if they try to visit a reserved prof…
Browse files Browse the repository at this point in the history
…ile (#904)

* Redirect user back to names page if they try to visit a reserved name profile

* Remove console log
  • Loading branch information
omkarb authored Aug 21, 2024
1 parent 6bc59c2 commit 28c547a
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,39 @@ import notFoundIllustration from './notFoundIllustration.svg';
import { StaticImageData } from 'next/image';
import { Button, ButtonVariants } from 'apps/web/src/components/Button/Button';
import Link from 'next/link';
import { useSearchParams } from 'next/navigation';
import { redirect, useSearchParams } from 'next/navigation';
import ImageWithLoading from 'apps/web/src/components/ImageWithLoading';
import { useIsNameAvailable } from 'apps/web/src/hooks/useIsNameAvailable';
import classNames from 'classnames';
import { Icon } from 'libs/base-ui';

const spinnerWrapperClasses = classNames('flex w-full items-center justify-center');

export default function UsernameProfileNotFound() {
const params = useSearchParams();
const username = params?.get('name');

if (!username) {
redirect(`/names`);
}
const {
isLoading: isLoadingNameAvailability,
data: isNameAvailable,
isFetching,
} = useIsNameAvailable(username);

if (isFetching && isLoadingNameAvailability) {
return (
<div className={spinnerWrapperClasses}>
<Icon name="spinner" color="black" />
</div>
);
}

if (!isFetching && !isLoadingNameAvailability && !isNameAvailable) {
redirect(`/names`);
}

const title = `${username ?? 'Name'} is not found`;
const description = username
? "There's no profile associated with this name, but it could be yours!"
Expand Down

0 comments on commit 28c547a

Please sign in to comment.