From cbe96fc88b671b7f6da609dfead0bef6dcec7b98 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 12 Nov 2023 04:35:07 -0500 Subject: [PATCH] query session, error strings consolidated --- .../fakeyou.com/src/v2/view/PageContainer.tsx | 11 +-- .../PasswordResetChangePage.tsx | 80 ------------------- .../PasswordResetVerificationPage.tsx | 28 ++++--- 3 files changed, 23 insertions(+), 96 deletions(-) delete mode 100644 packages/fakeyou.com/src/v2/view/pages/password_reset/PasswordResetChangePage.tsx diff --git a/packages/fakeyou.com/src/v2/view/PageContainer.tsx b/packages/fakeyou.com/src/v2/view/PageContainer.tsx index edce3e7bdf..03cd213e71 100644 --- a/packages/fakeyou.com/src/v2/view/PageContainer.tsx +++ b/packages/fakeyou.com/src/v2/view/PageContainer.tsx @@ -97,7 +97,6 @@ import { VoiceDesignerVoiceEditPage } from "./pages/voice_designer/VoiceDesigner import VoiceDesignerUseVoicePage from "./pages/voice_designer/VoiceDesignerUseVoicePage"; import { PasswordResetEmailPage } from "./pages/password_reset/PasswordResetEmailPage"; import { PasswordResetVerificationPage } from "./pages/password_reset/PasswordResetVerificationPage"; -import { PasswordResetChangePage } from "./pages/password_reset/PasswordResetChangePage"; interface Props { sessionWrapper: SessionWrapper; @@ -274,15 +273,13 @@ class PageContainer extends React.Component< /> - - - - diff --git a/packages/fakeyou.com/src/v2/view/pages/password_reset/PasswordResetChangePage.tsx b/packages/fakeyou.com/src/v2/view/pages/password_reset/PasswordResetChangePage.tsx deleted file mode 100644 index f8e1127982..0000000000 --- a/packages/fakeyou.com/src/v2/view/pages/password_reset/PasswordResetChangePage.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import React, { useState } from "react"; -import { SessionWrapper } from "@storyteller/components/src/session/SessionWrapper"; -import { useHistory } from "react-router-dom"; -import { usePrefixedDocumentTitle } from "../../../../common/UsePrefixedDocumentTitle"; -import Container from "components/common/Container"; -import PageHeader from "components/layout/PageHeader"; -import Input from "components/common/Input"; -import { Button } from "components/common"; -import Panel from "components/common/Panel"; -import { faKey } from "@fortawesome/pro-solid-svg-icons"; -import BackButton from "components/common/BackButton"; - -interface Props { - sessionWrapper: SessionWrapper; -} - -function PasswordResetChangePage(props: Props) { - let history = useHistory(); - const [isPasswordChanged, setIsPasswordChanged] = useState(false); - const [isLoading, setIsLoading] = useState(false); - - if (props.sessionWrapper.isLoggedIn()) { - history.push("/"); - } - - usePrefixedDocumentTitle("Reset Password"); - - const handlePasswordChange = async () => { - // Simulate a delay using a timer (dummy timer) - setIsLoading(true); - - setTimeout(() => { - setIsPasswordChanged(true); - setIsLoading(false); - }, 2000); - }; - - return ( - - - - - {isPasswordChanged ? ( -
-

Your password has been successfully changed!

- -
- ) : ( -
-
- - - - -
-
- )} -
-
- ); -} - -export { PasswordResetChangePage }; diff --git a/packages/fakeyou.com/src/v2/view/pages/password_reset/PasswordResetVerificationPage.tsx b/packages/fakeyou.com/src/v2/view/pages/password_reset/PasswordResetVerificationPage.tsx index b7d256bac6..c085cdae3d 100644 --- a/packages/fakeyou.com/src/v2/view/pages/password_reset/PasswordResetVerificationPage.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/password_reset/PasswordResetVerificationPage.tsx @@ -14,8 +14,16 @@ import { interface Props { sessionWrapper: SessionWrapper; + querySessionAction: () => void; + querySessionSubscriptionsAction: () => void; } +// TODO(bt,2023-11-12): Localize error messages +const ERR_CODE_NOT_SET = "password reset code is not set"; +const ERR_CODE_TOO_SHORT = "password reset code is too short"; +const ERR_PASSWORD_TOO_SHORT = "new password is too short"; +const ERR_PASSWORD_DOES_NOT_MATCH = "new password does not match"; + function PasswordResetVerificationPage(props: Props) { let history = useHistory(); @@ -27,11 +35,11 @@ function PasswordResetVerificationPage(props: Props) { const [newPassword, setNewPassword] = useState(""); const [newPasswordIsValid, setNewPasswordIsValid] = useState(false); - const [newPasswordInvalidReason, setNewPasswordInvalidReason] = useState("new password is too short"); + const [newPasswordInvalidReason, setNewPasswordInvalidReason] = useState(ERR_PASSWORD_TOO_SHORT); const [newPasswordConfirmation, setNewPasswordConfirmation] = useState(""); const [newPasswordConfirmationIsValid, setNewPasswordConfirmationIsValid] = useState(false); - const [newPasswordConfirmationInvalidReason, setNewPasswordConfirmationInvalidReason] = useState("new password is too short"); + const [newPasswordConfirmationInvalidReason, setNewPasswordConfirmationInvalidReason] = useState(ERR_PASSWORD_TOO_SHORT); if (props.sessionWrapper.isLoggedIn()) { history.push("/"); @@ -53,7 +61,7 @@ function PasswordResetVerificationPage(props: Props) { if (value.length < 5) { isValid = false; - invalidReason = "new password is too short"; + invalidReason = ERR_PASSWORD_TOO_SHORT; } setNewPassword(value); @@ -62,7 +70,7 @@ function PasswordResetVerificationPage(props: Props) { if (value !== newPasswordConfirmation) { setNewPasswordConfirmationIsValid(false); - setNewPasswordConfirmationInvalidReason("new password does not match") + setNewPasswordConfirmationInvalidReason(ERR_PASSWORD_DOES_NOT_MATCH) } else if (newPasswordConfirmation.length > 4) { setNewPasswordConfirmationIsValid(true); setNewPasswordConfirmationInvalidReason(undefined) @@ -77,11 +85,11 @@ function PasswordResetVerificationPage(props: Props) { if (value !== newPassword) { isValid = false; - invalidReason = "new password does not match"; + invalidReason = ERR_PASSWORD_DOES_NOT_MATCH; } else if (value.length < 5) { isValid = false; - invalidReason = "new password is too short"; + invalidReason = ERR_PASSWORD_TOO_SHORT; } setNewPasswordConfirmation(value); @@ -108,6 +116,8 @@ function PasswordResetVerificationPage(props: Props) { // TODO(bt,2023-11-12): Handle server-side errors if (RedeemResetPasswordIsSuccess(response)) { + props.querySessionAction(); + props.querySessionSubscriptionsAction(); history.push("/"); } @@ -135,7 +145,7 @@ function PasswordResetVerificationPage(props: Props) { @@ -191,10 +201,10 @@ function getCodeFromUrl() : string | null { // Handle error state at initialization function getResetCodeErrors(code: string | null) : string | undefined { if (!code) { - return "no code set"; + return ERR_CODE_NOT_SET; } if (code.length < 10) { - return "code is too short"; + return ERR_CODE_TOO_SHORT; }; }