MCPcopy Index your code
hub / github.com/Packstack-Tech/packstack / ResetPassword

Function ResetPassword

frontend/src/app/Auth/ResetPassword.tsx:16–90  ·  view source on GitHub ↗
({ resetPassword, history, match })

Source from the content-addressed store, hash-verified

14import { AuthWrapper, AuthPage } from "./styles";
15
16const ResetPassword: React.FC<ResetPasswordSpecs.Props> = ({ resetPassword, history, match }) => {
17 const [matchError, setMatchError] = React.useState<boolean>(false);
18
19 return (
20 <Formik
21 initialValues={{
22 callbackId: match.params.callbackId,
23 password: '',
24 confirmPassword: ''
25 }}
26 onSubmit={(values) => {
27 resetPassword(values.callbackId, values.password)
28 .then(() => {
29 alertSuccess({ message: 'Your password has been reset' });
30 history.push(LOGIN);
31 })
32 .catch(() => {
33 alertError({ message: 'An error occurred while resetting your password.' })
34 })
35 }}
36 validationSchema={Yup.object().shape({
37 password: Yup.string()
38 .min(6, 'Password must be at least 6 characters')
39 .max(100)
40 .required('Password is required'),
41 confirmPassword: Yup.string().required('Passwords must match')
42 })}
43 >
44 {(props: FormikProps<ResetPasswordSpecs.FormValues>) => {
45 const { values, errors, setFieldValue, submitForm, submitCount, isSubmitting } = props;
46 const wasSubmitted = submitCount > 0;
47 setMatchError(wasSubmitted && values.password !== values.confirmPassword);
48
49 return (
50 <AuthPage>
51 <AuthWrapper>
52 <Box>
53 <h1>Password Reset</h1>
54 {matchError && (
55 <Alert message="Passwords do not match." type="error"
56 style={{ marginBottom: '16px' }}/>
57 )}
58 <Input label="New Password"
59 type="password"
60 value={values.password}
61 error={wasSubmitted && !!errors.password}
62 errorMsg={errors.password}
63 autocomplete="new-password"
64 onChange={v => setFieldValue('password', v)}/>
65
66 <Input label="Repeat New Password"
67 type="password"
68 value={values.confirmPassword}
69 error={wasSubmitted && !!errors.confirmPassword}
70 errorMsg={errors.confirmPassword}
71 autocomplete="new-password"
72 onChange={v => setFieldValue('confirmPassword', v)}/>
73

Callers

nothing calls this directly

Calls 2

alertSuccessFunction · 0.90
alertErrorFunction · 0.90

Tested by

no test coverage detected