/******************************************************************************** * Copyright (c) 2025 Precies. Software OU and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ import { FunctionComponent, useContext, useState } from 'react'; import { Box, Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle } from '@mui/material'; import { ButtonWithProgress } from '../../components/button-with-progress'; import { PublisherInfo } from '../../extension-registry-types'; import { MainContext } from '../../context'; import { UpdateContext } from './publisher-admin'; import { useRevokeAccessTokens } from './use-publisher-admin'; const dangerButtonSx = { textTransform: 'none', '&:hover': { bgcolor: 'error.main', color: 'common.white' } } as const; export const PublisherRevokeTokensButton: FunctionComponent = props => { const { handleError } = useContext(MainContext); const updateContext = useContext(UpdateContext); const { mutateAsync: revokeTokens, isPending: working } = useRevokeAccessTokens(); const [dialogOpen, setDialogOpen] = useState(false); const { user } = props.publisherInfo; const tokenCount = props.publisherInfo.activeAccessTokenNum; const doRevoke = async () => { try { await revokeTokens({ provider: user.provider as string, login: user.loginName }); updateContext.handleUpdate(); setDialogOpen(false); } catch (err) { handleError(err); } }; return ( <> setDialogOpen(false)}> Revoke access tokens Deactivate {tokenCount} active access token{tokenCount === 1 ? '' : 's'} of {user.loginName}? This cannot be undone. Revoke tokens ); }; export interface PublisherRevokeTokensButtonProps { publisherInfo: PublisherInfo; }