add: backend api auth by apikey/apikey gen/apikey revoke
This commit is contained in:
63
src/components/Modals/ApiKeyRevokeModal.js
Normal file
63
src/components/Modals/ApiKeyRevokeModal.js
Normal file
@@ -0,0 +1,63 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useRevokeApiKey } from '../../utils/queries/apikey-queries';
|
||||
|
||||
const ApiKeyRevokeModal = ({ isOpen, onClose }) => {
|
||||
const [apiKey, setApiKey] = useState('');
|
||||
const revokeApiKeyMutation = useRevokeApiKey();
|
||||
|
||||
const handleRevoke = async () => {
|
||||
if (!apiKey.trim()) {
|
||||
alert('Please enter an API key');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await revokeApiKeyMutation.mutateAsync(apiKey);
|
||||
alert('API key revoked successfully');
|
||||
onClose();
|
||||
} catch (error) {
|
||||
console.error('Failed to revoke API key:', error);
|
||||
alert('Failed to revoke API key');
|
||||
}
|
||||
};
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
return (
|
||||
<div className="modal is-active">
|
||||
<div className="modal-background" onClick={onClose}></div>
|
||||
<div className="modal-card">
|
||||
<header className="modal-card-head">
|
||||
<p className="modal-card-title">Revoke API Key</p>
|
||||
<button className="delete" aria-label="close" onClick={onClose}></button>
|
||||
</header>
|
||||
<section className="modal-card-body">
|
||||
<div className="field">
|
||||
<label className="label">API Key</label>
|
||||
<div className="control">
|
||||
<input
|
||||
className="input"
|
||||
type="text"
|
||||
placeholder="Enter API key to revoke"
|
||||
value={apiKey}
|
||||
onChange={(e) => setApiKey(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<footer className="modal-card-foot">
|
||||
<button
|
||||
className="button is-danger"
|
||||
onClick={handleRevoke}
|
||||
disabled={revokeApiKeyMutation.isLoading}
|
||||
>
|
||||
Revoke
|
||||
</button>
|
||||
<button className="button" onClick={onClose}>Cancel</button>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ApiKeyRevokeModal;
|
||||
Reference in New Issue
Block a user