Skip to content

Commit

Permalink
trash can icon for repo and api call added
Browse files Browse the repository at this point in the history
  • Loading branch information
eviishondell committed Nov 10, 2023
1 parent a7d9684 commit 6ce53fe
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/components/Repo/RepoDetails.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// react global
import React, { useEffect, useMemo, useRef, useState } from 'react';

import { Delete as DeleteIcon } from '@mui/icons-material';
// external
import { DateTime } from 'luxon';
import { isEmpty, uniq } from 'lodash';
Expand Down Expand Up @@ -242,7 +242,29 @@ function RepoDetails() {
: `Timestamp N/A`;
return lastDate;
};

const handleDeleteRepo = () => {
const confirmed = window.confirm('Are you sure you want to delete this repo?');

Check warning on line 246 in src/components/Repo/RepoDetails.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Repo/RepoDetails.jsx#L246

Added line #L246 was not covered by tests
if (confirmed) {
const apiUrl = `http://localhost:3000/v2/${name}/manifests/`;
fetch(apiUrl, {

Check warning on line 249 in src/components/Repo/RepoDetails.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Repo/RepoDetails.jsx#L248-L249

Added lines #L248 - L249 were not covered by tests
method: 'DELETE'
})
.then((response) => {

Check warning on line 252 in src/components/Repo/RepoDetails.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Repo/RepoDetails.jsx#L252

Added line #L252 was not covered by tests
if (response.status === 202) {
// Repo deleted successfully
console.log('Repo deleted successfully');

Check warning on line 255 in src/components/Repo/RepoDetails.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Repo/RepoDetails.jsx#L255

Added line #L255 was not covered by tests
// You may want to navigate to another page or perform other actions as needed
} else {
console.log('Failed to delete the repo');

Check warning on line 258 in src/components/Repo/RepoDetails.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Repo/RepoDetails.jsx#L257-L258

Added lines #L257 - L258 were not covered by tests
// Handle the failure case here
}
})
.catch((error) => {
console.error('An error occurred:', error);

Check warning on line 263 in src/components/Repo/RepoDetails.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Repo/RepoDetails.jsx#L262-L263

Added lines #L262 - L263 were not covered by tests
// Handle any network or request error
});
}
};
return (
<>
{isLoading ? (
Expand Down Expand Up @@ -285,6 +307,11 @@ function RepoDetails() {
)}
</IconButton>
)}
{isAuthenticated() && (
<IconButton component="span" onClick={handleDeleteRepo} data-testid="delete-repo-button">
<DeleteIcon data-testid="delete-icon" />
</IconButton>
)}
</Stack>
<Typography gutterBottom className={classes.repoTitle}>
{repoDetailData?.title || 'Title not available'}
Expand Down

0 comments on commit 6ce53fe

Please sign in to comment.