2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 12:05:53 +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_sso = 'auth/social/',
user_sso_remove = 'auth/social/:id/disconnect/',
user_emails = 'auth/emails/',
user_email_remove = 'auth/emails/:id/remove/',
user_email_verify = 'auth/emails/:id/verify/',
user_email_primary = 'auth/emails/:id/primary/',
user_emails = '_allauth/app/v1/account/email',
user_login = '_allauth/app/v1/auth/login',
user_login_mfa = '_allauth/app/v1/auth/2fa/authenticate',
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)
});
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
.post(apiUrl(url, undefined, { id: value }), {})
.post(apiUrl(ApiEndpoints.user_emails), {
email: newEmailValue
})
.then(() => {
refetch();
})
.catch((res) => console.log(res.data));
}
function addEmail() {
function changePrimary() {
api
.post(apiUrl(ApiEndpoints.user_emails), {
email: newEmailValue,
user: user?.pk
email: value,
primary: true
})
.then(() => {
refetch();
@ -139,19 +164,19 @@ function EmailContent() {
label={t`The following email addresses are associated with your account:`}
>
<Stack mt='xs'>
{data.map((link: any) => (
{data.map((email: any) => (
<Radio
key={link.id}
value={String(link.id)}
key={email.id}
value={String(email.id)}
label={
<Group justify='space-between'>
{link.email}
{link.primary && (
{email.email}
{email.primary && (
<Badge color='blue'>
<Trans>Primary</Trans>
</Badge>
)}
{link.verified ? (
{email.verified ? (
<Badge color='green'>
<Trans>Verified</Trans>
</Badge>
@ -183,18 +208,16 @@ function EmailContent() {
</Grid.Col>
<Grid.Col span={6}>
<Group>
<Button
onClick={() => runServerAction(ApiEndpoints.user_email_primary)}
>
<Button onClick={() => changePrimary()}>
<Trans>Make Primary</Trans>
</Button>
<Button
onClick={() => runServerAction(ApiEndpoints.user_email_verify)}
onClick={() => runServerAction(ApiEndpoints.user_emails, 'put')}
>
<Trans>Re-send Verification</Trans>
</Button>
<Button
onClick={() => runServerAction(ApiEndpoints.user_email_remove)}
onClick={() => runServerAction(ApiEndpoints.user_emails, 'delete')}
>
<Trans>Remove</Trans>
</Button>