mirror of
https://github.com/umami-software/umami.git
synced 2026-02-20 04:25:39 +01:00
Rewrite admin.
This commit is contained in:
parent
f4db04c3c6
commit
6cf6a97b4d
114 changed files with 2174 additions and 1820 deletions
52
components/forms/PasswordResetForm.js
Normal file
52
components/forms/PasswordResetForm.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { useRef } from 'react';
|
||||
import { Form, FormInput, FormButtons, PasswordField, Button } from 'react-basics';
|
||||
import { useApi } from 'next-basics';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { getAuthToken } from 'lib/client';
|
||||
import styles from './Form.module.css';
|
||||
|
||||
export default function PasswordResetForm({ token, onSave }) {
|
||||
const { post } = useApi(getAuthToken());
|
||||
const { mutate, error, isLoading } = useMutation(data =>
|
||||
post('/account/reset-password', { ...data, token }),
|
||||
);
|
||||
const ref = useRef(null);
|
||||
|
||||
const handleSubmit = async data => {
|
||||
mutate(data, {
|
||||
onSuccess: async () => {
|
||||
onSave();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const samePassword = value => {
|
||||
if (value !== ref?.current?.getValues('new_password')) {
|
||||
return "Passwords don't match";
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Form ref={ref} className={styles.form} onSubmit={handleSubmit} error={error}>
|
||||
<h2>Reset your password</h2>
|
||||
<FormInput name="new_password" label="New password" rules={{ required: 'Required' }}>
|
||||
<PasswordField autoComplete="off" />
|
||||
</FormInput>
|
||||
<FormInput
|
||||
name="confirm_password"
|
||||
label="Confirm password"
|
||||
rules={{ required: 'Required', validate: samePassword }}
|
||||
>
|
||||
<PasswordField autoComplete="off" />
|
||||
</FormInput>
|
||||
<FormButtons align="center" className={styles.buttons}>
|
||||
<Button type="submit" variant="primary" disabled={isLoading}>
|
||||
Update password
|
||||
</Button>
|
||||
</FormButtons>
|
||||
</Form>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue