Skip to content

Commit

Permalink
fix(demo): reenable forgot password reset in demo
Browse files Browse the repository at this point in the history
  • Loading branch information
unleashit committed Feb 2, 2024
1 parent 257472c commit f592670
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 61 deletions.
10 changes: 5 additions & 5 deletions demos/frontend/src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -30,10 +30,10 @@ function App() {
<Route path="/login" element={<Login />} />
<Route path="/signup" element={<Signup />} />
<Route path="/forgot-password" element={<ForgotPassword />} />
{/* <Route */}
{/* path="/forgot-password/reset/:userid/:token" */}
{/* element={<ForgotPasswordReset />} */}
{/* /> */}
<Route
path="/forgot-password/:userid/:token"
element={<ForgotPasswordReset />}
/>
<Route path="/async-handler" element={<AsyncHandler />} />
<Route
path="/recursive-data-lister"
Expand Down
2 changes: 1 addition & 1 deletion demos/frontend/src/components/App/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Navigation() {
</li>
<li>
<Link
to="/forgot-password/reset/1/1234567890"
to="/forgot-password/1/1234567890"
className="main-navigation__link"
>
Forgot Password Reset
Expand Down
115 changes: 60 additions & 55 deletions demos/frontend/src/components/forgotPasswordReset/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
// <>
// <p style={{ marginBottom: '2.5rem', color: '#aaaaaa' }}>
// User ID = 1, token = 1234567890, taken from url in this example
// </p>
// <ForgotPasswordReset
// forgotPasswordResetHandler={this.forgotPasswordResetHandler}
// onSuccess={this.onSuccess}
// showDefaultConfirmation
// />
// </>
// );
// }
// }
//
// 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 = () => (
<div className={css.header}>
<h2>Reset Password</h2>
<p>Please enter a new password and confirm.</p>
<p style={{ marginBottom: '2.5rem', color: '#aaaaaa' }}>
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.
</p>
</div>
);

function ForgotPasswordResetDemo() {
const forgotPasswordResetHandler = async (
values: FormValuesReset,
): Promise<any> => {
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 (
<ForgotPasswordReset
handler={forgotPasswordResetHandler}
header={Header}
onSuccess={onSuccess}
cssModule={css}
/>
);
}

export default ForgotPasswordResetDemo;

0 comments on commit f592670

Please sign in to comment.