|
| 1 | +import { v1 } from "@docker/extension-api-client-types"; |
| 2 | +import useOAuthProvider from "../../queries/useOAuthProvider"; |
| 3 | +import { Alert, Box, Button, Card, CardContent, CardHeader, Chip, CircularProgress, Collapse, Link, Stack, Typography } from "@mui/material"; |
| 4 | +import { useState } from "react"; |
| 5 | +import { OAuthProvider } from "../../types/oauth/Provider"; |
| 6 | + |
| 7 | +const OAuthProviders = ({ client }: { client: v1.DockerDesktopClient }) => { |
| 8 | + const { data, isLoading, error, authorizeOAuthProvider, unauthorizeOAuthProvider } = useOAuthProvider(client); |
| 9 | + const [collapsed, setCollapsed] = useState<Record<string, boolean>>({}); |
| 10 | + if (isLoading) { |
| 11 | + return <Box sx={{ display: 'flex', justifyContent: 'center', p: 4 }}> |
| 12 | + <Typography>Loading OAuth Providers...</Typography> |
| 13 | + <CircularProgress /> |
| 14 | + </Box>; |
| 15 | + } |
| 16 | + if (error) { |
| 17 | + return <Box sx={{ display: 'flex', justifyContent: 'center', p: 4 }}> |
| 18 | + <Alert severity="error">Error: {error.message || JSON.stringify(error, null, 2)}</Alert> |
| 19 | + </Box>; |
| 20 | + } |
| 21 | + if (!data) { |
| 22 | + return <Box sx={{ display: 'flex', justifyContent: 'center', p: 4 }}> |
| 23 | + <Alert severity="info">No supported OAuth Providers detected</Alert> |
| 24 | + </Box>; |
| 25 | + } |
| 26 | + if (data.length > 0) { |
| 27 | + return <> |
| 28 | + {data.map((provider: OAuthProvider) => { |
| 29 | + return <Card> |
| 30 | + <CardHeader title={provider.app} action={provider.authorized ? <Button variant="contained" color="error" onClick={() => { |
| 31 | + unauthorizeOAuthProvider.mutateAsync(provider.app); |
| 32 | + }}>Unauthorize</Button> : <Button variant="contained" color="success" onClick={() => { |
| 33 | + authorizeOAuthProvider.mutateAsync(provider.app); |
| 34 | + }}>Authorize</Button>} /> |
| 35 | + <CardContent> |
| 36 | + <Stack direction="row" alignItems="center" spacing={1}> |
| 37 | + <Typography>{provider.provider}</Typography> |
| 38 | + {provider.authorized ? <Chip label="Authorized" color="success" size="small" /> : <Chip label="Unauthorized" color="error" size="small" />} |
| 39 | + </Stack> |
| 40 | + </CardContent> |
| 41 | + </Card> |
| 42 | + })} |
| 43 | + </> |
| 44 | + } |
| 45 | + return <Box sx={{ display: 'flex', justifyContent: 'center', p: 4 }}> |
| 46 | + <Alert severity="info">No supported OAuth Providers detected</Alert> |
| 47 | + </Box>; |
| 48 | +}; |
| 49 | + |
| 50 | +export default OAuthProviders; |
| 51 | + |
0 commit comments