-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(demo): reenable forgot password reset in demo
- Loading branch information
Showing
3 changed files
with
66 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 60 additions & 55 deletions
115
demos/frontend/src/components/forgotPasswordReset/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |