|
1 | 1 | import { useTranslation } from "@prefabs.tech/react-i18n"; |
| 2 | +import { Message } from "@prefabs.tech/react-ui"; |
2 | 3 | import React, { useState } from "react"; |
3 | 4 | import { toast } from "react-toastify"; |
4 | 5 |
|
@@ -33,6 +34,10 @@ export const SignupWrapper: React.FC<IProperties> = ({ |
33 | 34 | }) => { |
34 | 35 | const { t } = useTranslation("user"); |
35 | 36 | const [signupLoading, setSignupLoading] = useState<boolean>(false); |
| 37 | + const [signupError, setSignupError] = useState< |
| 38 | + null | "emailAlreadyExists" | "other" |
| 39 | + >(null); |
| 40 | + |
36 | 41 | const { setUser } = useUser(); |
37 | 42 | const config = useConfig(); |
38 | 43 |
|
@@ -84,24 +89,39 @@ export const SignupWrapper: React.FC<IProperties> = ({ |
84 | 89 | } |
85 | 90 | }) |
86 | 91 | .catch(async (error) => { |
87 | | - const errorMessage = t("errors.otherErrors", { ns: "errors" }); |
88 | | - |
89 | 92 | onSignupFailed && (await onSignupFailed(error)); |
90 | 93 |
|
91 | | - if (error.status === "FIELD_ERROR") { |
92 | | - throw error as Error; |
| 94 | + if (error.message.includes("email already exists")) { |
| 95 | + setSignupError("emailAlreadyExists"); |
| 96 | + |
| 97 | + return; |
93 | 98 | } |
94 | 99 |
|
95 | | - toast.error(error.message || errorMessage); |
| 100 | + setSignupError("other"); |
96 | 101 | }) |
97 | 102 | .finally(() => { |
98 | 103 | setSignupLoading(false); |
99 | 104 | }); |
100 | 105 | } |
101 | 106 | }; |
102 | 107 |
|
| 108 | + const message = |
| 109 | + signupError === "emailAlreadyExists" |
| 110 | + ? t("errors.emailAlreadyExists", { ns: "errors" }) |
| 111 | + : t("errors.otherErrors", { ns: "errors" }); |
| 112 | + |
103 | 113 | return ( |
104 | 114 | <> |
| 115 | + {signupError && ( |
| 116 | + <Message |
| 117 | + enableClose={true} |
| 118 | + message={message} |
| 119 | + onClose={() => { |
| 120 | + setSignupError(null); |
| 121 | + }} |
| 122 | + severity="danger" |
| 123 | + /> |
| 124 | + )} |
105 | 125 | <SignupForm |
106 | 126 | handleSubmit={handleSignupSubmit} |
107 | 127 | loading={handleSubmit ? loading : signupLoading} |
|
0 commit comments