Skip to content

Commit 54aec5d

Browse files
committed
fix: show the right error message for the password error
1 parent bf98acd commit 54aec5d

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/components/ui/UsernameInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function UsernameInput({ register, errors, usernameValue, testId
3636
placeholder={`${t("login-page.username.placeholde")}`}
3737
label={`${t("login-page.username.label")}`}
3838
value={usernameValue}
39-
error={errors.username?.message || (error?.error?.data.details.username as string)}
39+
error={errors.username?.message || (error?.error?.data?.details?.username as string)}
4040
{...register("username", {
4141
required: "This field is required",
4242
minLength: {

src/pages/signup.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Head from "next/head";
99
import Link from "next/link";
1010
import { GetServerSideProps } from "next";
1111
import i18Translate from "@/utilities/I18Translate";
12-
import { useSelector } from "@/hooks/useTypedSelector";
12+
import { useMultiSelector } from "@/hooks/useTypedSelector";
1313
import { useDispatch } from "@/hooks/useTypedDispatch";
1414
import classNames from "classnames";
1515
import Checkbox from "@/components/ui/Checkbox";
@@ -19,6 +19,8 @@ import LayoutWithoutFooter from "@/layouts/WithoutFooter";
1919
import EmailInput from "@/components/ui/EmailInput";
2020
import UsernameInput from "@/components/ui/UsernameInput";
2121
import { setError } from "@/store/feature/index.slice";
22+
import { IRootState } from "@/store";
23+
import { Referral } from "@/types/community";
2224

2325
/**
2426
* Signup form values
@@ -36,6 +38,23 @@ export interface FormValues {
3638
checkTerms: boolean;
3739
}
3840

41+
interface ErrorDetails {
42+
error: {
43+
data: {
44+
details: {
45+
password?: string;
46+
};
47+
};
48+
};
49+
}
50+
51+
interface MultiSelector {
52+
referrals: Referral[];
53+
error: ErrorDetails;
54+
}
55+
56+
57+
3958
/**
4059
* signup page
4160
* @date 4/6/2023 - 4:15:13 PM
@@ -56,7 +75,10 @@ export default function SignupWithInvite(): ReactElement {
5675
const referralCodeValue = watch("referralCode") || "";
5776
const { query, locale } = useRouter();
5877
const referrer = query.invite;
59-
const referrals = useSelector((state) => state.referrals.list);
78+
const { referrals, error } = useMultiSelector<unknown, MultiSelector>({
79+
referrals: (state: IRootState) => state.referrals.list,
80+
error: (state: IRootState) => state.store.error,
81+
});
6082
const { t } = useTranslation();
6183
const [loading, setLoading] = useState(false);
6284
const dispatch = useDispatch();
@@ -122,7 +144,7 @@ export default function SignupWithInvite(): ReactElement {
122144
value={passwordValue}
123145
placeholder={`${t("login-page.password.placeholde")}`}
124146
label={`${t("login-page.password.label")}`}
125-
error={errors.password?.message}
147+
error={error?.error?.data?.details?.password}
126148
{...register("password", {
127149
required: "This field is required",
128150
minLength: { value: 3, message: "The password is too short" },

0 commit comments

Comments
 (0)