-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathIndex.jsx
More file actions
157 lines (153 loc) · 4.74 KB
/
Copy pathIndex.jsx
File metadata and controls
157 lines (153 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { Button, Typography } from '@mui/material';
import { useTheme } from '@mui/material/styles';
import * as R from 'ramda';
import { useDispatch } from 'react-redux';
import { meTokens, renewToken, updateMeInformation, updateMePassword, updateMeProfile } from '../../../actions/users/User';
import Paper from '../../../components/common/Paper';
import { useFormatter } from '../../../components/i18n';
import { useHelper } from '../../../store';
import useDataLoader from '../../../utils/hooks/useDataLoader';
import { countryOption } from '../../../utils/Option';
import PasswordForm from './PasswordForm';
import ProfileForm from './ProfileForm';
import UserForm from './UserForm';
import XtmOneMcpAccess from './XtmOneMcpAccess';
const Index = () => {
const { t } = useFormatter();
const theme = useTheme();
const dispatch = useDispatch();
useDataLoader(() => {
dispatch(meTokens());
});
const { user, tokens } = useHelper(helper => ({
user: helper.getMe(),
tokens: helper.getMeTokens(),
}));
const onRenew = tokenId => dispatch(renewToken(tokenId));
const onUpdate = (data) => {
const inputValues = R.pipe(
R.assoc(
'user_organization',
data.user_organization && data.user_organization.id
? data.user_organization.id
: data.user_organization,
),
R.assoc(
'user_country',
data.user_country && data.user_country.id
? data.user_country.id
: data.user_country,
),
)(data);
return dispatch(updateMeProfile(inputValues));
};
const onUpdateInformation = data => dispatch(updateMeInformation(data));
const onUpdatePassword = data => dispatch(
updateMePassword(data.user_current_password, data.user_plain_password),
);
const initialValues = {
user_firstname: user.user_firstname,
user_lastname: user.user_lastname,
user_email: user.user_email,
user_phone: user.user_phone,
user_phone2: user.user_phone2,
user_pgp_key: user.user_pgp_key,
user_lang: user.user_lang,
user_theme: user.user_theme,
user_is_external: user.user_is_external,
user_organization: user.user_organization ?? '',
user_country: countryOption(user.user_country)?.id ?? '',
};
const userToken = tokens.length > 0 ? R.head(tokens) : undefined;
return (
<div style={{
width: 800,
margin: '0 auto',
display: 'grid',
gap: theme.spacing(3),
}}
>
<Paper>
<Typography variant="h1" style={{ marginBottom: 20 }}>
{t('Profile')}
</Typography>
<UserForm onSubmit={onUpdate} initialValues={initialValues} />
</Paper>
<Paper>
<Typography variant="h1" style={{ marginBottom: 20 }}>
{t('Information')}
</Typography>
<ProfileForm
onSubmit={onUpdateInformation}
initialValues={initialValues}
/>
</Paper>
{!initialValues.user_is_external && (
<Paper>
<Typography variant="h1" style={{ marginBottom: 20 }}>
{t('Password')}
</Typography>
<PasswordForm onSubmit={onUpdatePassword} />
</Paper>
)}
<Paper>
<Typography variant="h1" style={{ marginBottom: 20 }}>
{t('API access')}
</Typography>
<Typography variant="body1">
{t(
'The OpenAEV API relies on the REST standard. The token must be passed into the HTTP header',
)}
{' '}
<strong>{t('Authorization')}</strong>
.
</Typography>
<Typography
variant="h4"
gutterBottom={true}
style={{ marginTop: 20 }}
>
{t('Token key')}
</Typography>
<pre>{userToken?.token_value}</pre>
<Button
variant="contained"
color="primary"
component="a"
onClick={() => onRenew(userToken?.token_id)}
>
{t('RENEW')}
</Button>
<Typography
variant="h4"
gutterBottom={true}
style={{ marginTop: 20 }}
>
{t('Example')}
</Typography>
{/* eslint-disable-next-line i18next/no-literal-string */}
<pre>
GET /api/exercises
{/* eslint-disable-next-line i18next/no-literal-string */}
<br />
Content-Type: application/json
{/* eslint-disable-next-line i18next/no-literal-string */}
<br />
Authorization: Bearer
{' '}
{userToken?.token_value}
</pre>
<Button
variant="contained"
color="primary"
component="a"
href="/swagger-ui/index.html"
>
{t('API specifications')}
</Button>
</Paper>
<XtmOneMcpAccess />
</div>
);
};
export default Index;