From f59267092281b25b8951d72b38e94c3c2e5c5a5d Mon Sep 17 00:00:00 2001 From: unleashit Date: Fri, 2 Feb 2024 01:18:13 -0800 Subject: [PATCH] fix(demo): reenable forgot password reset in demo --- demos/frontend/src/components/App/App.tsx | 10 +- .../src/components/App/Navigation.tsx | 2 +- .../components/forgotPasswordReset/index.tsx | 115 +++++++++--------- 3 files changed, 66 insertions(+), 61 deletions(-) diff --git a/demos/frontend/src/components/App/App.tsx b/demos/frontend/src/components/App/App.tsx index e1729292..e44ad260 100644 --- a/demos/frontend/src/components/App/App.tsx +++ b/demos/frontend/src/components/App/App.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; import AsyncHandler from '../asyncHandler'; import ForgotPassword from '../forgotPassword'; -// import ForgotPasswordReset from '../forgotPasswordReset'; +import ForgotPasswordReset from '../forgotPasswordReset'; import Home from '../Home/Home'; import Login from '../login'; import ModalDemo from '../modal'; @@ -30,10 +30,10 @@ function App() { } /> } /> } /> - {/* } */} - {/* /> */} + } + /> } />
  • Forgot Password Reset diff --git a/demos/frontend/src/components/forgotPasswordReset/index.tsx b/demos/frontend/src/components/forgotPasswordReset/index.tsx index 4debe9d2..503e7705 100644 --- a/demos/frontend/src/components/forgotPasswordReset/index.tsx +++ b/demos/frontend/src/components/forgotPasswordReset/index.tsx @@ -1,56 +1,61 @@ -// import '@unleashit/forgot-password/dist/forgot-password.css'; -// -// import { -// ForgotPasswordReset, -// FormValuesReset, -// ServerResponse, -// } from '@unleashit/forgot-password'; -// import React from 'react'; -// -// class ForgotPasswordResetDemo extends React.Component { -// async forgotPasswordResetHandler(values: FormValuesReset) { -// const [token, userid] = new URL(window.location.href).pathname -// .split('/') -// .filter(Boolean) -// .reverse(); -// -// return await fetch( -// `https://unleashit-forgot-password.vercel.app/passwordreset/${userid}/${token}`, -// { -// method: 'POST', -// headers: { -// 'Content-Type': 'application/json', -// }, -// body: JSON.stringify(values), -// }, -// ).then((resp) => { -// if (resp.ok) { -// return resp.json(); -// } -// throw new Error('Problem connecting to the server'); -// }); -// } -// -// onSuccess(res: ServerResponse) { -// console.log(res); -// } -// -// render() { -// return ( -// <> -//

    -// User ID = 1, token = 1234567890, taken from url in this example -//

    -// -// -// ); -// } -// } -// -// export default ForgotPasswordResetDemo; +import React from 'react'; +import { + ForgotPasswordReset, + FormValuesReset, + ServerResponseReset, +} from '@unleashit/forgot-password'; +import css from '@unleashit/forgot-password/dist/forgot-password.module.css'; -export default null; +const Header = () => ( +
    +

    Reset Password

    +

    Please enter a new password and confirm.

    +

    + In this example, in the handler prop, the user Id and token are taken from + url and posted to the server for verification. If the either the id or + token don't match or the user input is wrong, it will fail. +

    +
    +); + +function ForgotPasswordResetDemo() { + const forgotPasswordResetHandler = async ( + values: FormValuesReset, + ): Promise => { + const [token, userid] = new URL(window.location.href).pathname + .split('/') + .filter(Boolean) + .reverse(); + + return await fetch( + `${process.env.DEMO_URL}/forgot-password/${userid}/${token}`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(values), + }, + ).then((resp) => { + if (resp.ok) { + return resp.json(); + } + throw new Error('Problem connecting to the server'); + }); + }; + + const onSuccess = (res: ServerResponseReset) => { + console.log(res); + }; + + return ( + + ); +} + +export default ForgotPasswordResetDemo;