mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 20:45:44 +00:00
fix remove sso provider account action; provider (user) admin stuff is done
This commit is contained in:
@ -17,7 +17,7 @@ import { IconAlertCircle, IconAt } from '@tabler/icons-react';
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { api, queryClient } from '../../../../App';
|
import { api } from '../../../../App';
|
||||||
import { YesNoButton } from '../../../../components/buttons/YesNoButton';
|
import { YesNoButton } from '../../../../components/buttons/YesNoButton';
|
||||||
import { ApiEndpoints } from '../../../../enums/ApiEndpoints';
|
import { ApiEndpoints } from '../../../../enums/ApiEndpoints';
|
||||||
import { ProviderLogin, authApi } from '../../../../functions/auth';
|
import { ProviderLogin, authApi } from '../../../../functions/auth';
|
||||||
@ -202,7 +202,7 @@ function SsoContent({
|
|||||||
}: Readonly<{ auth_settings: SecuritySetting | undefined }>) {
|
}: Readonly<{ auth_settings: SecuritySetting | undefined }>) {
|
||||||
const [value, setValue] = useState<string>('');
|
const [value, setValue] = useState<string>('');
|
||||||
const [currentProviders, setCurrentProviders] = useState<Provider[]>();
|
const [currentProviders, setCurrentProviders] = useState<Provider[]>();
|
||||||
const { isLoading, data } = useQuery({
|
const { isLoading, data, refetch } = useQuery({
|
||||||
queryKey: ['sso-list'],
|
queryKey: ['sso-list'],
|
||||||
queryFn: () =>
|
queryFn: () =>
|
||||||
authApi(apiUrl(ApiEndpoints.user_sso)).then((res) => res.data.data)
|
authApi(apiUrl(ApiEndpoints.user_sso)).then((res) => res.data.data)
|
||||||
@ -213,7 +213,7 @@ function SsoContent({
|
|||||||
if (data === undefined) return;
|
if (data === undefined) return;
|
||||||
|
|
||||||
const configuredProviders = data.map((item: any) => {
|
const configuredProviders = data.map((item: any) => {
|
||||||
return item.provider;
|
return item.provider.id;
|
||||||
});
|
});
|
||||||
function isAlreadyInUse(value: any) {
|
function isAlreadyInUse(value: any) {
|
||||||
return !configuredProviders.includes(value.id);
|
return !configuredProviders.includes(value.id);
|
||||||
@ -226,11 +226,15 @@ function SsoContent({
|
|||||||
}, [auth_settings, data]);
|
}, [auth_settings, data]);
|
||||||
|
|
||||||
function removeProvider() {
|
function removeProvider() {
|
||||||
authApi(apiUrl(ApiEndpoints.user_sso), undefined, 'delete')
|
const split = value.split('$');
|
||||||
|
const provider = split[split.length - 1];
|
||||||
|
const uid = split.slice(0, split.length - 1).join('$');
|
||||||
|
authApi(apiUrl(ApiEndpoints.user_sso), undefined, 'delete', {
|
||||||
|
provider: provider,
|
||||||
|
account: uid
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
queryClient.removeQueries({
|
refetch();
|
||||||
queryKey: ['sso-list']
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch((res) => console.log(res.data));
|
.catch((res) => console.log(res.data));
|
||||||
}
|
}
|
||||||
@ -262,15 +266,15 @@ function SsoContent({
|
|||||||
<Stack mt='xs'>
|
<Stack mt='xs'>
|
||||||
{data.map((link: any) => (
|
{data.map((link: any) => (
|
||||||
<Radio
|
<Radio
|
||||||
key={link.id}
|
key={link.uid}
|
||||||
value={String(link.id)}
|
value={[link.uid, link.provider.id].join('$')}
|
||||||
label={link.provider}
|
label={`${link.provider.name}: ${link.display}`}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
<Button onClick={removeProvider}>
|
<Button onClick={removeProvider}>
|
||||||
<Trans>Remove</Trans>
|
<Trans>Remove Link</Trans>
|
||||||
</Button>
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
|
Reference in New Issue
Block a user