@autobusal/account-password 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Change.tsx +60 -0
- package/index.ts +5 -0
- package/package.json +6 -0
- package/services.ts +16 -0
- package/types.ts +4 -0
package/Change.tsx
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
|
+
import { useNavigate } from 'react-router-dom';
|
|
3
|
+
import { Meta, Viewer } from '@autobusal/common';
|
|
4
|
+
import { usePage } from '@autobusal/hooks';
|
|
5
|
+
import { success } from '@autobusal/utilities';
|
|
6
|
+
import { PasswordData } from './types';
|
|
7
|
+
import { PostPassword } from './services';
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
t: TFunction<'common'>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const Change = ({ t }: Props): JSX.Element => {
|
|
14
|
+
usePage('-');
|
|
15
|
+
|
|
16
|
+
const navigate = useNavigate();
|
|
17
|
+
|
|
18
|
+
const { mutate: Update, isPending } = PostPassword();
|
|
19
|
+
|
|
20
|
+
const onSave = (data: PasswordData): void => {
|
|
21
|
+
Update(data, {
|
|
22
|
+
onSuccess: () => {
|
|
23
|
+
success(t('account_password.messages.changed', { ns: 'common' }));
|
|
24
|
+
|
|
25
|
+
navigate('/account');
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<Meta title={ t('account_password.title', { ns: 'common' }) }>
|
|
32
|
+
<h1>{ t('account_password.title', { ns: 'common' }) }</h1>
|
|
33
|
+
|
|
34
|
+
<Viewer
|
|
35
|
+
id={ 0 }
|
|
36
|
+
data={ [{
|
|
37
|
+
label: t('account_password.old_password', { ns: 'common' }),
|
|
38
|
+
name: 'old_password',
|
|
39
|
+
type: 'password',
|
|
40
|
+
value: '',
|
|
41
|
+
rules: 'required|min_length:6|max_length:20'
|
|
42
|
+
}, {
|
|
43
|
+
label: t('account_password.new_password', { ns: 'common' }),
|
|
44
|
+
name: 'new_password',
|
|
45
|
+
type: 'password',
|
|
46
|
+
value: '',
|
|
47
|
+
rules: 'required|min_length:6|max_length:20'
|
|
48
|
+
}] }
|
|
49
|
+
pending={ isPending }
|
|
50
|
+
t={ t }
|
|
51
|
+
actions={ [
|
|
52
|
+
'update'
|
|
53
|
+
]}
|
|
54
|
+
onSave={ onSave }
|
|
55
|
+
/>
|
|
56
|
+
</Meta>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default Change;
|
package/index.ts
ADDED
package/package.json
ADDED
package/services.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UseMutationResult, useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { apiClient } from '@autobusal/providers';
|
|
3
|
+
import { PasswordData } from './types';
|
|
4
|
+
|
|
5
|
+
export const PostPassword = (): UseMutationResult<void, Error, PasswordData, unknown> => (
|
|
6
|
+
useMutation({
|
|
7
|
+
mutationKey: ['account-password'],
|
|
8
|
+
mutationFn: async (data: PasswordData) => (
|
|
9
|
+
await apiClient
|
|
10
|
+
.post('/api/account/password', data)
|
|
11
|
+
.then(response => (
|
|
12
|
+
response.data
|
|
13
|
+
))
|
|
14
|
+
)
|
|
15
|
+
})
|
|
16
|
+
);
|
package/types.ts
ADDED