Skip to content

Commit

Permalink
Fixed indentation
Browse files Browse the repository at this point in the history
Signed-off-by: Aashir Siddiqui <[email protected]>
  • Loading branch information
aashir21 committed Oct 2, 2024
1 parent fa73b0a commit 0c43d18
Showing 1 changed file with 89 additions and 89 deletions.
178 changes: 89 additions & 89 deletions galasa-ui/src/components/TokenDeleteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,106 +14,106 @@ import TokenRequestModalProps from '@/utils/interfaces/TokenRequestModalProps';

export default function TokenRequestModal({ tokens, selectedTokens, deleteTokenFromSet, updateDeleteModalState }: TokenRequestModalProps) {

const [open, setOpen] = useState(true);
const [error, setError] = useState('');
const [isLoading, setIsLoading] = useState(false);
const [open, setOpen] = useState(true);
const [error, setError] = useState('');
const [isLoading, setIsLoading] = useState(false);

const deleteTokensById = async () => {
const deleteTokensById = async () => {

try {
try {

setIsLoading(true);
//Convert set to array so we can iterate for it
const tokensArray: Token[] = Array.from(tokens);
setIsLoading(true);
//Convert set to array so we can iterate for it
const tokensArray: Token[] = Array.from(tokens);

for (const token of tokensArray) { //using loop to handle multiple token deletion at once
if (selectedTokens.has(token.tokenId)) {
for (const token of tokensArray) { //using loop to handle multiple token deletion at once
if (selectedTokens.has(token.tokenId)) {

const response = await fetch(`/auth/tokens`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ tokenId: token.tokenId }),
});
const response = await fetch(`/auth/tokens`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ tokenId: token.tokenId }),
});

if (response.status === 204) {
if (response.status === 204) {

//Update the tokens after deletion
deleteTokenFromSet(token);
setOpen(false);
//Update the tokens after deletion
deleteTokenFromSet(token);
setOpen(false);

}
}
}

} catch (err) {
let errorMessage = '';

if (err instanceof Error) {
errorMessage = err.message;
} else {
errorMessage = String(err);
}

setError(errorMessage);
console.error('Failed to delete a personal access token: %s', err);
}
finally {
setIsLoading(false);
}
}
}

};
} catch (err) {
let errorMessage = '';

if (isLoading) {
<Loading />;
}
if (err instanceof Error) {
errorMessage = err.message;
} else {
errorMessage = String(err);
}

setError(errorMessage);
console.error('Failed to delete a personal access token: %s', err);
}
finally {
setIsLoading(false);
}

return (
<>
<Modal
modalHeading="Delete Access Tokens"
primaryButtonText="Delete"
secondaryButtonText="Cancel"
danger
shouldSubmitOnEnter={true}
open={open}
onRequestClose={() => {
setOpen(false);
setError('');
updateDeleteModalState();
}}
onRequestSubmit={async () => {
await deleteTokensById();
}}
>
<h6 className='margin-top-1'>
Number of access tokens to delete: {selectedTokens.size}
</h6>

<div className='margin-top-2'>
<InlineNotification
title="Client programs using these access tokens will no longer have access to this Galasa Service."
subtitle="This operation is irreversible, though new access tokens can be created to replace the ones being deleted. Whichever client program used this token will need to be re-configured to use a replacement."
kind="warning"
lowContrast
hideCloseButton
/>
</div>
<br />

{error && (
<InlineNotification
className="margin-top-1"
title="Error deleting access token"
subtitle={error}
kind="error"
onCloseButtonClick={() => setError('')}
lowContrast
/>
)}
</Modal>
</>
);
};

if (isLoading) {
<Loading />;
}


return (
<>
<Modal
modalHeading="Delete Access Tokens"
primaryButtonText="Delete"
secondaryButtonText="Cancel"
danger
shouldSubmitOnEnter={true}
open={open}
onRequestClose={() => {
setOpen(false);
setError('');
updateDeleteModalState();
}}
onRequestSubmit={async () => {
await deleteTokensById();
}}
>
<h6 className='margin-top-1'>
Number of access tokens to delete: {selectedTokens.size}
</h6>

<div className='margin-top-2'>
<InlineNotification
title="Client programs using these access tokens will no longer have access to this Galasa Service."
subtitle="This operation is irreversible, though new access tokens can be created to replace the ones being deleted. Whichever client program used this token will need to be re-configured to use a replacement."
kind="warning"
lowContrast
hideCloseButton
/>
</div>
<br />

{error && (
<InlineNotification
className="margin-top-1"
title="Error deleting access token"
subtitle={error}
kind="error"
onCloseButtonClick={() => setError('')}
lowContrast
/>
)}
</Modal>
</>
);
};

0 comments on commit 0c43d18

Please sign in to comment.