diff --git a/lib/build/emailpasswordprebuiltui.js b/lib/build/emailpasswordprebuiltui.js index 7614a23e1..8dcad4082 100644 --- a/lib/build/emailpasswordprebuiltui.js +++ b/lib/build/emailpasswordprebuiltui.js @@ -100,21 +100,12 @@ function BackToSignInButton(_a) { ); } -var EmailPasswordResetPasswordEmail = function (props) { +var EmailPasswordResetPasswordEmail = uiEntry.withOverride("EmailPasswordResetPasswordEmail", function (props) { var t = translationContext.useTranslation(); var userContext = uiEntry.useUserContext(); - var _a = React.useState("READY"), - status = _a[0], - setStatus = _a[1]; - var _b = React.useState(""), - emailFieldValue = _b[0], - setEmailFieldValue = _b[1]; - var onSuccess = function () { - setStatus("SENT"); - }; - var resend = function () { - setStatus("READY"); - }; + var _a = React.useState(""), + emailFieldValue = _a[0], + setEmailFieldValue = _a[1]; var formFields = props.formFields; var emailSuccessText = t("EMAIL_PASSWORD_RESET_SEND_BEFORE_EMAIL") + @@ -122,157 +113,148 @@ var EmailPasswordResetPasswordEmail = function (props) { ? emailFieldValue : t("EMAIL_PASSWORD_RESET_SEND_FALLBACK_EMAIL")) + t("EMAIL_PASSWORD_RESET_SEND_AFTER_EMAIL"); - if (status === "SENT") { - return jsxRuntime.jsx( - "div", - genericComponentOverrideContext.__assign( - { "data-supertokens": "container" }, - { - children: jsxRuntime.jsxs( - "div", - genericComponentOverrideContext.__assign( - { "data-supertokens": "row" }, - { - children: [ - jsxRuntime.jsxs( - "div", - genericComponentOverrideContext.__assign( - { "data-supertokens": "primaryText enterEmailSuccessMessage" }, - { - children: [ - emailSuccessText, - jsxRuntime.jsx( - "span", - genericComponentOverrideContext.__assign( - { - "data-supertokens": "link resendEmailLink", - onClick: resend, - }, - { children: t("EMAIL_PASSWORD_RESET_RESEND_LINK") } - ) - ), - ], - } - ) - ), - jsxRuntime.jsx(BackToSignInButton, { onClick: props.onBackButtonClicked }), - ], - } - ) - ), - } - ) - ); + if (props.status === "SENT") { + return jsxRuntime.jsxs(React.Fragment, { + children: [ + jsxRuntime.jsxs( + "div", + genericComponentOverrideContext.__assign( + { "data-supertokens": "primaryText enterEmailSuccessMessage" }, + { + children: [ + emailSuccessText, + jsxRuntime.jsx( + "span", + genericComponentOverrideContext.__assign( + { "data-supertokens": "link resendEmailLink", onClick: props.resend }, + { children: t("EMAIL_PASSWORD_RESET_RESEND_LINK") } + ) + ), + ], + } + ) + ), + jsxRuntime.jsx(BackToSignInButton, { onClick: props.onBackButtonClicked }), + ], + }); } // Otherwise, return Form. + return jsxRuntime.jsxs(React.Fragment, { + children: [ + jsxRuntime.jsxs( + "div", + genericComponentOverrideContext.__assign( + { "data-supertokens": "headerTitle withBackButton" }, + { + children: [ + jsxRuntime.jsx(uiEntry.BackButton, { onClick: props.onBackButtonClicked }), + t("EMAIL_PASSWORD_RESET_HEADER_TITLE"), + jsxRuntime.jsx("span", { "data-supertokens": "backButtonPlaceholder backButtonCommon" }), + ], + } + ) + ), + jsxRuntime.jsx( + "div", + genericComponentOverrideContext.__assign( + { "data-supertokens": "headerSubtitle secondaryText" }, + { children: t("EMAIL_PASSWORD_RESET_HEADER_SUBTITLE") } + ) + ), + props.error !== undefined && jsxRuntime.jsx(uiEntry.GeneralError, { error: props.error }), + jsxRuntime.jsx(formBase.FormBase, { + clearError: props.clearError, + onError: props.onError, + formFields: formFields, + buttonLabel: "EMAIL_PASSWORD_RESET_SEND_BTN", + onSuccess: props.onSuccess, + callAPI: function (formFields) { + return genericComponentOverrideContext.__awaiter(void 0, void 0, void 0, function () { + var validationErrors, emailField, resp; + return genericComponentOverrideContext.__generator(this, function (_a) { + switch (_a.label) { + case 0: + return [ + 4 /*yield*/, + genericComponentOverrideContext.validateForm( + formFields, + props.config.resetPasswordUsingTokenFeature.enterEmailForm.formFields + ), + ]; + case 1: + validationErrors = _a.sent(); + if (validationErrors.length > 0) { + return [ + 2 /*return*/, + { + status: "FIELD_ERROR", + formFields: validationErrors, + }, + ]; + } + emailField = formFields.find(function (field) { + return field.id === "email"; + }); + if (emailField !== undefined) { + setEmailFieldValue(emailField.value); + } + return [ + 4 /*yield*/, + props.recipeImplementation.sendPasswordResetEmail({ + formFields: formFields, + userContext: userContext, + }), + ]; + case 2: + resp = _a.sent(); + if (resp.status === "PASSWORD_RESET_NOT_ALLOWED") { + return [ + 2 /*return*/, + { + status: "FIELD_ERROR", + formFields: [{ id: "email", error: resp.reason }], + }, + ]; + } + return [2 /*return*/, resp]; + } + }); + }); + }, + showLabels: true, + validateOnBlur: true, + }), + ], + }); +}); +var ResetPasswordEmail = function (props) { + var _a = React.useState("READY"), + status = _a[0], + setStatus = _a[1]; + var onSuccess = function () { + setStatus("SENT"); + }; + var resend = function () { + setStatus("READY"); + }; return jsxRuntime.jsx( "div", genericComponentOverrideContext.__assign( - { "data-supertokens": "container resetPasswordEmailForm" }, + { "data-supertokens": "container ".concat(status === "SENT" ? "" : "resetPasswordEmailForm") }, { - children: jsxRuntime.jsxs( + children: jsxRuntime.jsx( "div", genericComponentOverrideContext.__assign( { "data-supertokens": "row" }, { - children: [ - jsxRuntime.jsxs( - "div", - genericComponentOverrideContext.__assign( - { "data-supertokens": "headerTitle withBackButton" }, - { - children: [ - jsxRuntime.jsx(uiEntry.BackButton, { - onClick: props.onBackButtonClicked, - }), - t("EMAIL_PASSWORD_RESET_HEADER_TITLE"), - jsxRuntime.jsx("span", { - "data-supertokens": "backButtonPlaceholder backButtonCommon", - }), - ], - } - ) - ), - jsxRuntime.jsx( - "div", - genericComponentOverrideContext.__assign( - { "data-supertokens": "headerSubtitle secondaryText" }, - { children: t("EMAIL_PASSWORD_RESET_HEADER_SUBTITLE") } - ) - ), - props.error !== undefined && - jsxRuntime.jsx(uiEntry.GeneralError, { error: props.error }), - jsxRuntime.jsx(formBase.FormBase, { - clearError: props.clearError, - onError: props.onError, - formFields: formFields, - buttonLabel: "EMAIL_PASSWORD_RESET_SEND_BTN", + children: jsxRuntime.jsx( + EmailPasswordResetPasswordEmail, + genericComponentOverrideContext.__assign({}, props, { + status: status, onSuccess: onSuccess, - callAPI: function (formFields) { - return genericComponentOverrideContext.__awaiter( - void 0, - void 0, - void 0, - function () { - var validationErrors, emailField, resp; - return genericComponentOverrideContext.__generator(this, function (_a) { - switch (_a.label) { - case 0: - return [ - 4 /*yield*/, - genericComponentOverrideContext.validateForm( - formFields, - props.config.resetPasswordUsingTokenFeature - .enterEmailForm.formFields - ), - ]; - case 1: - validationErrors = _a.sent(); - if (validationErrors.length > 0) { - return [ - 2 /*return*/, - { - status: "FIELD_ERROR", - formFields: validationErrors, - }, - ]; - } - emailField = formFields.find(function (field) { - return field.id === "email"; - }); - if (emailField !== undefined) { - setEmailFieldValue(emailField.value); - } - return [ - 4 /*yield*/, - props.recipeImplementation.sendPasswordResetEmail({ - formFields: formFields, - userContext: userContext, - }), - ]; - case 2: - resp = _a.sent(); - if (resp.status === "PASSWORD_RESET_NOT_ALLOWED") { - return [ - 2 /*return*/, - { - status: "FIELD_ERROR", - formFields: [ - { id: "email", error: resp.reason }, - ], - }, - ]; - } - return [2 /*return*/, resp]; - } - }); - } - ); - }, - showLabels: true, - validateOnBlur: true, - }), - ], + resend: resend, + }) + ), } ) ), @@ -280,7 +262,6 @@ var EmailPasswordResetPasswordEmail = function (props) { ) ); }; -var ResetPasswordEmail = uiEntry.withOverride("EmailPasswordResetPasswordEmail", EmailPasswordResetPasswordEmail); var EmailPasswordSubmitNewPassword = function (props) { var t = translationContext.useTranslation(); diff --git a/lib/build/recipe/emailpassword/components/themes/resetPasswordUsingToken/resetPasswordEmail.d.ts b/lib/build/recipe/emailpassword/components/themes/resetPasswordUsingToken/resetPasswordEmail.d.ts index bcc6e2b05..23e8fad07 100644 --- a/lib/build/recipe/emailpassword/components/themes/resetPasswordUsingToken/resetPasswordEmail.d.ts +++ b/lib/build/recipe/emailpassword/components/themes/resetPasswordUsingToken/resetPasswordEmail.d.ts @@ -1,16 +1,3 @@ /// -export declare const ResetPasswordEmail: import("react").ComponentType< - import("../../../../../types").ThemeBaseProps & { - formFields: Omit[]; - error: string | undefined; - } & { - recipeImplementation: import("supertokens-web-js/recipe/emailpassword").RecipeInterface; - error: string | undefined; - clearError: () => void; - onError: (error: string) => void; - config: import("../../../types").NormalisedConfig; - onBackButtonClicked: () => void; - } & { - children?: import("react").ReactNode; - } ->; +import type { EnterEmailProps } from "../../../types"; +export declare const ResetPasswordEmail: React.FC; diff --git a/lib/ts/recipe/emailpassword/components/themes/resetPasswordUsingToken/resetPasswordEmail.tsx b/lib/ts/recipe/emailpassword/components/themes/resetPasswordUsingToken/resetPasswordEmail.tsx index da81d334b..2d9669e62 100644 --- a/lib/ts/recipe/emailpassword/components/themes/resetPasswordUsingToken/resetPasswordEmail.tsx +++ b/lib/ts/recipe/emailpassword/components/themes/resetPasswordUsingToken/resetPasswordEmail.tsx @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -import { useState } from "react"; +import { Fragment, useState } from "react"; import { withOverride } from "../../../../../components/componentOverride/withOverride"; import { useTranslation } from "../../../../../translation/translationContext"; @@ -25,48 +25,44 @@ import GeneralError from "../../library/generalError"; import type { EnterEmailProps, EnterEmailStatus } from "../../../types"; -const EmailPasswordResetPasswordEmail: React.FC = (props) => { - const t = useTranslation(); - const userContext = useUserContext(); - const [status, setStatus] = useState("READY"); - const [emailFieldValue, setEmailFieldValue] = useState(""); - - const onSuccess = (): void => { - setStatus("SENT"); - }; - - const resend = (): void => { - setStatus("READY"); - }; - const { formFields } = props; +const EmailPasswordResetPasswordEmail = withOverride( + "EmailPasswordResetPasswordEmail", + ( + props: EnterEmailProps & { + status: EnterEmailStatus; + onSuccess: () => void; + resend: () => void; + } + ) => { + const t = useTranslation(); + const userContext = useUserContext(); + const [emailFieldValue, setEmailFieldValue] = useState(""); + const { formFields } = props; - const emailSuccessText = - t("EMAIL_PASSWORD_RESET_SEND_BEFORE_EMAIL") + - (emailFieldValue !== undefined && emailFieldValue.length > 0 - ? emailFieldValue - : t("EMAIL_PASSWORD_RESET_SEND_FALLBACK_EMAIL")) + - t("EMAIL_PASSWORD_RESET_SEND_AFTER_EMAIL"); + const emailSuccessText = + t("EMAIL_PASSWORD_RESET_SEND_BEFORE_EMAIL") + + (emailFieldValue !== undefined && emailFieldValue.length > 0 + ? emailFieldValue + : t("EMAIL_PASSWORD_RESET_SEND_FALLBACK_EMAIL")) + + t("EMAIL_PASSWORD_RESET_SEND_AFTER_EMAIL"); - if (status === "SENT") { - return ( -
-
+ if (props.status === "SENT") { + return ( +
{emailSuccessText} - + {t("EMAIL_PASSWORD_RESET_RESEND_LINK")}
-
-
- ); - } + + ); + } - // Otherwise, return Form. - return ( -
-
+ // Otherwise, return Form. + return ( +
{t("EMAIL_PASSWORD_RESET_HEADER_TITLE")} @@ -81,7 +77,7 @@ const EmailPasswordResetPasswordEmail: React.FC = (props) => { onError={props.onError} formFields={formFields} buttonLabel={"EMAIL_PASSWORD_RESET_SEND_BTN"} - onSuccess={onSuccess} + onSuccess={props.onSuccess} callAPI={async (formFields) => { const validationErrors = await validateForm( formFields, @@ -118,9 +114,26 @@ const EmailPasswordResetPasswordEmail: React.FC = (props) => { showLabels={true} validateOnBlur={true} /> + + ); + } +); + +export const ResetPasswordEmail: React.FC = (props) => { + const [status, setStatus] = useState("READY"); + const onSuccess = (): void => { + setStatus("SENT"); + }; + + const resend = (): void => { + setStatus("READY"); + }; + + return ( +
+
+
); }; - -export const ResetPasswordEmail = withOverride("EmailPasswordResetPasswordEmail", EmailPasswordResetPasswordEmail);