2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

fix: email endpoints (to be cleaned TODO@matmair)

This commit is contained in:
Matthias Mair
2024-12-28 12:05:24 +01:00
parent 61e0fae7a3
commit c003084690
2 changed files with 40 additions and 20 deletions

View File

@ -21,10 +21,7 @@ export enum ApiEndpoints {
user_change_password = 'auth/password/change/', user_change_password = 'auth/password/change/',
user_sso = 'auth/social/', user_sso = 'auth/social/',
user_sso_remove = 'auth/social/:id/disconnect/', user_sso_remove = 'auth/social/:id/disconnect/',
user_emails = 'auth/emails/', user_emails = '_allauth/app/v1/account/email',
user_email_remove = 'auth/emails/:id/remove/',
user_email_verify = 'auth/emails/:id/verify/',
user_email_primary = 'auth/emails/:id/primary/',
user_login = '_allauth/app/v1/auth/login', user_login = '_allauth/app/v1/auth/login',
user_login_mfa = '_allauth/app/v1/auth/2fa/authenticate', user_login_mfa = '_allauth/app/v1/auth/2fa/authenticate',
user_logout = '_allauth/app/v1/auth/session', user_logout = '_allauth/app/v1/auth/session',

View File

@ -106,20 +106,45 @@ function EmailContent() {
api.get(apiUrl(ApiEndpoints.user_emails)).then((res) => res.data) api.get(apiUrl(ApiEndpoints.user_emails)).then((res) => res.data)
}); });
function runServerAction(url: ApiEndpoints) { function runServerAction(
url: ApiEndpoints,
action: 'post' | 'put' | 'delete' = 'post'
) {
let act: any;
switch (action) {
case 'post':
act = api.post;
break;
case 'put':
act = api.put;
break;
case 'delete':
act = api.delete;
break;
}
act(apiUrl(url), { email: value })
.then(() => {
refetch();
})
.catch((res: any) => console.log(res.data));
}
function addEmail() {
api api
.post(apiUrl(url, undefined, { id: value }), {}) .post(apiUrl(ApiEndpoints.user_emails), {
email: newEmailValue
})
.then(() => { .then(() => {
refetch(); refetch();
}) })
.catch((res) => console.log(res.data)); .catch((res) => console.log(res.data));
} }
function addEmail() { function changePrimary() {
api api
.post(apiUrl(ApiEndpoints.user_emails), { .post(apiUrl(ApiEndpoints.user_emails), {
email: newEmailValue, email: value,
user: user?.pk primary: true
}) })
.then(() => { .then(() => {
refetch(); refetch();
@ -139,19 +164,19 @@ function EmailContent() {
label={t`The following email addresses are associated with your account:`} label={t`The following email addresses are associated with your account:`}
> >
<Stack mt='xs'> <Stack mt='xs'>
{data.map((link: any) => ( {data.map((email: any) => (
<Radio <Radio
key={link.id} key={email.id}
value={String(link.id)} value={String(email.id)}
label={ label={
<Group justify='space-between'> <Group justify='space-between'>
{link.email} {email.email}
{link.primary && ( {email.primary && (
<Badge color='blue'> <Badge color='blue'>
<Trans>Primary</Trans> <Trans>Primary</Trans>
</Badge> </Badge>
)} )}
{link.verified ? ( {email.verified ? (
<Badge color='green'> <Badge color='green'>
<Trans>Verified</Trans> <Trans>Verified</Trans>
</Badge> </Badge>
@ -183,18 +208,16 @@ function EmailContent() {
</Grid.Col> </Grid.Col>
<Grid.Col span={6}> <Grid.Col span={6}>
<Group> <Group>
<Button <Button onClick={() => changePrimary()}>
onClick={() => runServerAction(ApiEndpoints.user_email_primary)}
>
<Trans>Make Primary</Trans> <Trans>Make Primary</Trans>
</Button> </Button>
<Button <Button
onClick={() => runServerAction(ApiEndpoints.user_email_verify)} onClick={() => runServerAction(ApiEndpoints.user_emails, 'put')}
> >
<Trans>Re-send Verification</Trans> <Trans>Re-send Verification</Trans>
</Button> </Button>
<Button <Button
onClick={() => runServerAction(ApiEndpoints.user_email_remove)} onClick={() => runServerAction(ApiEndpoints.user_emails, 'delete')}
> >
<Trans>Remove</Trans> <Trans>Remove</Trans>
</Button> </Button>