Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix-issue-7011 #7125

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion frontend/src/pages/SignUp/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type FormValues = {
function SignUp({ version }: SignUpProps): JSX.Element {
const { t } = useTranslation(['signup']);
const [loading, setLoading] = useState(false);
const { notifications } = useNotifications();

const [precheck, setPrecheck] = useState<LoginPrecheckPayloadProps>({
sso: false,
Expand All @@ -59,6 +60,13 @@ function SignUp({ version }: SignUpProps): JSX.Element {
const { search } = useLocation();
const params = new URLSearchParams(search);
const token = params.get('token');
if (token === '') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid side-effects during render: redirecting (history.push) and triggering notifications should be done in useEffect rather than in the component body.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition 'if (token === "")' only catches empty strings. Consider using 'if (!token)' to also handle the null case, ensuring missing tokens are correctly redirected.

Suggested change
if (token === '') {
if (!token) {

history.push(ROUTES.LOGIN);
notifications.error({
message: t('token_required'),
});
}

const [isDetailsDisable, setIsDetailsDisable] = useState<boolean>(false);

const isOnboardingEnabled = useFeatureFlag(FeatureKeys.ONBOARDING)?.active;
Expand All @@ -72,7 +80,6 @@ function SignUp({ version }: SignUpProps): JSX.Element {
enabled: token !== null,
});

const { notifications } = useNotifications();
const [form] = Form.useForm<FormValues>();

useEffect(() => {
Expand Down Expand Up @@ -106,6 +113,7 @@ function SignUp({ version }: SignUpProps): JSX.Element {
getInviteDetailsResponse.status === 'success' &&
getInviteDetailsResponse.data?.error
) {
history.push(ROUTES.LOGIN);
const { error } = getInviteDetailsResponse.data;
notifications.error({
message: error,
Expand Down