|
|
@@ -3,6 +3,7 @@ import {
|
|
|
} from 'react';
|
|
|
|
|
|
import { useTranslation } from 'next-i18next';
|
|
|
+import { useRouter } from 'next/router';
|
|
|
|
|
|
import { i18n as i18nConfig } from '^/config/next-i18next.config';
|
|
|
|
|
|
@@ -12,6 +13,8 @@ import { apiv3Post } from '~/client/util/apiv3-client';
|
|
|
const InstallerForm = memo((): JSX.Element => {
|
|
|
const { t, i18n } = useTranslation();
|
|
|
|
|
|
+ const router = useRouter();
|
|
|
+
|
|
|
const [isValidUserName, setValidUserName] = useState(true);
|
|
|
const [isSubmittingDisabled, setSubmittingDisabled] = useState(false);
|
|
|
const [currentLocale, setCurrentLocale] = useState('en_US');
|
|
|
@@ -70,7 +73,7 @@ const InstallerForm = memo((): JSX.Element => {
|
|
|
|
|
|
try {
|
|
|
await apiv3Post('/installer', data);
|
|
|
- window.location.href = '/';
|
|
|
+ router.push('/');
|
|
|
}
|
|
|
catch (errs) {
|
|
|
const err = errs[0];
|
|
|
@@ -78,12 +81,12 @@ const InstallerForm = memo((): JSX.Element => {
|
|
|
|
|
|
if (code === 'failed_to_login_after_install') {
|
|
|
toastError(t('installer.failed_to_login_after_install'));
|
|
|
- setTimeout(() => { window.location.href = '/login' }, 700); // Wait 700 ms to show toastr
|
|
|
+ setTimeout(() => { router.push('/login') }, 700); // Wait 700 ms to show toastr
|
|
|
}
|
|
|
|
|
|
toastError(t('installer.failed_to_install'));
|
|
|
}
|
|
|
- }, [isSubmittingDisabled, t, currentLocale]);
|
|
|
+ }, [isSubmittingDisabled, currentLocale, router, t]);
|
|
|
|
|
|
const hasErrorClass = isValidUserName ? '' : ' has-error';
|
|
|
const unavailableUserId = isValidUserName
|