♻️ Update api endpoint authorization
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { Badge, Box, Button, Card, Group, Image, SimpleGrid, Stack, Text } from '@mantine/core';
|
||||
import { useElementSize } from '@mantine/hooks';
|
||||
import { IconDeviceGamepad, IconPlayerPlay, IconPlayerStop } from '@tabler/icons-react';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { api } from '~/utils/api';
|
||||
|
||||
import { useConfigContext } from '../../config/provider';
|
||||
import { queryClient } from '../../tools/server/configurations/tanstack/queryClient.tool';
|
||||
import { defineWidget } from '../helper';
|
||||
import { WidgetLoading } from '../loading';
|
||||
import { IWidget } from '../widgets';
|
||||
@@ -32,6 +32,8 @@ interface DnsHoleControlsWidgetProps {
|
||||
}
|
||||
|
||||
function DnsHoleControlsWidgetTile({ widget }: DnsHoleControlsWidgetProps) {
|
||||
const utils = api.useContext();
|
||||
const { data: sessionData } = useSession();
|
||||
const { isInitialLoading, data } = useDnsHoleSummeryQuery();
|
||||
const { mutateAsync } = useDnsHoleControlMutation();
|
||||
const { width, ref } = useElementSize();
|
||||
@@ -45,38 +47,46 @@ function DnsHoleControlsWidgetTile({ widget }: DnsHoleControlsWidgetProps) {
|
||||
|
||||
return (
|
||||
<Stack justify="space-between" h={'100%'} spacing="0.25rem">
|
||||
<SimpleGrid ref={ref} cols={width > 275 ? 2 : 1} verticalSpacing="0.25rem" spacing="0.25rem">
|
||||
<Button
|
||||
onClick={async () => {
|
||||
await mutateAsync({
|
||||
action: 'enable',
|
||||
configName,
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['dns-hole-summary'] });
|
||||
}}
|
||||
leftIcon={<IconPlayerPlay size={20} />}
|
||||
variant="light"
|
||||
color="green"
|
||||
h="2rem"
|
||||
{sessionData?.user?.isAdmin && (
|
||||
<SimpleGrid
|
||||
ref={ref}
|
||||
cols={width > 275 ? 2 : 1}
|
||||
verticalSpacing="0.25rem"
|
||||
spacing="0.25rem"
|
||||
>
|
||||
{t('enableAll')}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={async () => {
|
||||
await mutateAsync({
|
||||
action: 'disable',
|
||||
configName,
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['dns-hole-summary'] });
|
||||
}}
|
||||
leftIcon={<IconPlayerStop size={20} />}
|
||||
variant="light"
|
||||
color="red"
|
||||
h="2rem"
|
||||
>
|
||||
{t('disableAll')}
|
||||
</Button>
|
||||
</SimpleGrid>
|
||||
<Button
|
||||
onClick={async () => {
|
||||
await mutateAsync({
|
||||
action: 'enable',
|
||||
configName,
|
||||
});
|
||||
|
||||
await utils.dnsHole.summary.invalidate();
|
||||
}}
|
||||
leftIcon={<IconPlayerPlay size={20} />}
|
||||
variant="light"
|
||||
color="green"
|
||||
h="2rem"
|
||||
>
|
||||
{t('enableAll')}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={async () => {
|
||||
await mutateAsync({
|
||||
action: 'disable',
|
||||
configName,
|
||||
});
|
||||
await utils.dnsHole.summary.invalidate();
|
||||
}}
|
||||
leftIcon={<IconPlayerStop size={20} />}
|
||||
variant="light"
|
||||
color="red"
|
||||
h="2rem"
|
||||
>
|
||||
{t('disableAll')}
|
||||
</Button>
|
||||
</SimpleGrid>
|
||||
)}
|
||||
|
||||
<Stack spacing="0.25rem">
|
||||
{data.status.map((status, index) => {
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
} from '@mantine/core';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
import { IconCheck, IconGitPullRequest, IconThumbDown, IconThumbUp } from '@tabler/icons-react';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { useConfigContext } from '~/config/provider';
|
||||
import { api } from '~/utils/api';
|
||||
@@ -95,6 +96,7 @@ function MediaRequestListTile({ widget }: MediaRequestListWidgetProps) {
|
||||
const { data, isLoading } = useMediaRequestQuery();
|
||||
// Use mutation to approve or deny a pending request
|
||||
const decideAsync = useMediaRequestDecisionMutation();
|
||||
const { data: sessionData } = useSession();
|
||||
|
||||
if (!data || isLoading) {
|
||||
return <WidgetLoading />;
|
||||
@@ -177,7 +179,7 @@ function MediaRequestListTile({ widget }: MediaRequestListWidgetProps) {
|
||||
</Text>
|
||||
</Flex>
|
||||
|
||||
{item.status === MediaRequestStatus.PendingApproval && (
|
||||
{item.status === MediaRequestStatus.PendingApproval && sessionData?.user?.isAdmin && (
|
||||
<Group>
|
||||
<Tooltip label={t('tooltips.approve')} withArrow withinPortal>
|
||||
<ActionIcon
|
||||
|
||||
@@ -3,18 +3,19 @@ import { useElementSize } from '@mantine/hooks';
|
||||
import { IconFileDownload, IconPlayerPause, IconPlayerPlay } from '@tabler/icons-react';
|
||||
import dayjs from 'dayjs';
|
||||
import duration from 'dayjs/plugin/duration';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import { useConfigContext } from '../../config/provider';
|
||||
import { MIN_WIDTH_MOBILE } from '../../constants/constants';
|
||||
import { humanFileSize } from '../../tools/humanFileSize';
|
||||
import { AppIntegrationType } from '../../types/app';
|
||||
import {
|
||||
useGetUsenetInfo,
|
||||
usePauseUsenetQueueMutation,
|
||||
useResumeUsenetQueueMutation,
|
||||
} from '../dashDot/api';
|
||||
import { humanFileSize } from '../../tools/humanFileSize';
|
||||
import { AppIntegrationType } from '../../types/app';
|
||||
import { defineWidget } from '../helper';
|
||||
import { IWidget } from '../widgets';
|
||||
import { UsenetHistoryList } from './UsenetHistoryList';
|
||||
@@ -49,7 +50,8 @@ function UseNetTile({ widget }: UseNetTileProps) {
|
||||
const downloadApps =
|
||||
config?.apps.filter((x) => x.integration && downloadAppTypes.includes(x.integration.type)) ??
|
||||
[];
|
||||
const { ref, width, height } = useElementSize();
|
||||
const { ref, width } = useElementSize();
|
||||
const { data: sessionData } = useSession();
|
||||
|
||||
const [selectedAppId, setSelectedApp] = useState<string | null>(downloadApps[0]?.id);
|
||||
const { data } = useGetUsenetInfo({ appId: selectedAppId! });
|
||||
@@ -106,30 +108,31 @@ function UseNetTile({ widget }: UseNetTileProps) {
|
||||
)}
|
||||
<Tabs.Panel value="queue">
|
||||
<UsenetQueueList appId={selectedAppId} />
|
||||
{!data ? null : data.paused ? (
|
||||
<Button
|
||||
uppercase
|
||||
onClick={async () => resumeAsync({ appId: selectedAppId })}
|
||||
radius="xl"
|
||||
size="xs"
|
||||
fullWidth
|
||||
mt="sm"
|
||||
>
|
||||
<IconPlayerPlay size={12} style={{ marginRight: 5 }} /> {t('info.paused')}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
uppercase
|
||||
onClick={async () => pauseAsync({ appId: selectedAppId })}
|
||||
radius="xl"
|
||||
size="xs"
|
||||
fullWidth
|
||||
mt="sm"
|
||||
>
|
||||
<IconPlayerPause size={12} style={{ marginRight: 5 }} />{' '}
|
||||
{dayjs.duration(data.eta, 's').format('HH:mm')}
|
||||
</Button>
|
||||
)}
|
||||
{sessionData?.user?.isAdmin &&
|
||||
(!data ? null : data.paused ? (
|
||||
<Button
|
||||
uppercase
|
||||
onClick={async () => resumeAsync({ appId: selectedAppId })}
|
||||
radius="xl"
|
||||
size="xs"
|
||||
fullWidth
|
||||
mt="sm"
|
||||
>
|
||||
<IconPlayerPlay size={12} style={{ marginRight: 5 }} /> {t('info.paused')}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
uppercase
|
||||
onClick={async () => pauseAsync({ appId: selectedAppId })}
|
||||
radius="xl"
|
||||
size="xs"
|
||||
fullWidth
|
||||
mt="sm"
|
||||
>
|
||||
<IconPlayerPause size={12} style={{ marginRight: 5 }} />{' '}
|
||||
{dayjs.duration(data.eta, 's').format('HH:mm')}
|
||||
</Button>
|
||||
))}
|
||||
</Tabs.Panel>
|
||||
<Tabs.Panel value="history" style={{ display: 'flex', flexDirection: 'column' }}>
|
||||
<UsenetHistoryList appId={selectedAppId} />
|
||||
|
||||
Reference in New Issue
Block a user