-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): add password reset modal
- Loading branch information
Showing
13 changed files
with
164 additions
and
10 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
19 changes: 19 additions & 0 deletions
19
src/components/ResetPasswordForm/ResetPasswordForm.module.scss
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@use '../../styles/variables'; | ||
@use '../../styles/theme'; | ||
|
||
.title { | ||
margin: 24px 0; | ||
font-family: theme.$body-alt-font-family; | ||
font-weight: 700; | ||
font-size: 26px; | ||
} | ||
|
||
.text { | ||
margin-bottom: 24px; | ||
font-family: theme.$body-alt-font-family; | ||
font-size: 16px; | ||
} | ||
|
||
.button { | ||
margin-bottom: 8px; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/components/ResetPasswordForm/ResetPasswordForm.test.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import ResetPasswordForm from './ResetPasswordForm'; | ||
|
||
describe('<ResetPassword>', () => { | ||
test('renders and matches snapshot', () => { | ||
const { container } = render(<ResetPasswordForm onCancel={jest.fn()} onReset={jest.fn()} />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import Button from '../Button/Button'; | ||
|
||
import styles from './ResetPasswordForm.module.scss'; | ||
|
||
type Props = { | ||
onCancel: () => void; | ||
onReset: () => void; | ||
}; | ||
|
||
const ResetPasswordForm: React.FC<Props> = ({ onCancel, onReset }: Props) => { | ||
const { t } = useTranslation('account'); | ||
return ( | ||
<div className={styles.resetPassword}> | ||
<h5 className={styles.title}>{t('reset.reset_password')}</h5> | ||
<p className={styles.text}>{t('reset.text')}</p> | ||
<Button onClick={onCancel} className={styles.button} fullWidth color="primary" label={t('reset.yes')} /> | ||
<Button onClick={onReset} fullWidth label={t('reset.no')} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ResetPasswordForm; |
32 changes: 32 additions & 0 deletions
32
src/components/ResetPasswordForm/__snapshots__/ResetPasswordForm.test.tsx.snap
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<ResetPassword> renders and matches snapshot 1`] = ` | ||
<div> | ||
<div> | ||
<h5 | ||
class="title" | ||
> | ||
reset.reset_password | ||
</h5> | ||
<p | ||
class="text" | ||
> | ||
reset.text | ||
</p> | ||
<button | ||
class="button button primary outlined fullWidth" | ||
> | ||
<span> | ||
reset.yes | ||
</span> | ||
</button> | ||
<button | ||
class="button default outlined fullWidth" | ||
> | ||
<span> | ||
reset.no | ||
</span> | ||
</button> | ||
</div> | ||
</div> | ||
`; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
|
||
import { resetPassword } from '../../../stores/AccountStore'; | ||
import { removeQueryParam } from '../../../utils/history'; | ||
import ResetPasswordForm from '../../../components/ResetPasswordForm/ResetPasswordForm'; | ||
|
||
const ResetPassword: React.FC = () => { | ||
const history = useHistory(); | ||
|
||
const onCancelClickHandler = () => { | ||
history.push(removeQueryParam(history, 'u')); | ||
}; | ||
|
||
const onResetClickHandler = async () => { | ||
const resetUrl = `${window.location.origin}/u/my-account?u=edit-password`; | ||
|
||
try { | ||
const response = await resetPassword(resetUrl); | ||
if (response.errors.length > 0) throw new Error(response.errors[0]); | ||
|
||
history.push('/u/logout'); | ||
} catch (error: unknown) { | ||
if (error instanceof Error) { | ||
if (error.message.toLowerCase().includes('invalid param email')) { | ||
console.info(error.message); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
return <ResetPasswordForm onCancel={onCancelClickHandler} onReset={onResetClickHandler} />; | ||
}; | ||
|
||
export default ResetPassword; |
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
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 |
---|---|---|
|
@@ -51,5 +51,11 @@ | |
"month": "", | ||
"week": "", | ||
"year": "" | ||
}, | ||
"reset": { | ||
"no": "", | ||
"reset_password": "", | ||
"text": "", | ||
"yes": "" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,6 +7,5 @@ | |
"live": "", | ||
"play_item": "", | ||
"slide_left": "", | ||
"slide_right": "", | ||
"show_page": "" | ||
"slide_right": "" | ||
} |
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