Skip to content

Commit

Permalink
delete admin
Browse files Browse the repository at this point in the history
  • Loading branch information
NwinNwin committed Sep 25, 2023
1 parent 9ea09a8 commit 6db9b81
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions src/components/InfoModal/InfoModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import DataContext from "../../context/DataContext";
import ImageContainer from "../ImageContainer/ImageContainer";
import FeedbackModal from "../FeedbackModal/FeedbackModal";
import { LinkIcon, CheckIcon, EmailIcon } from "@chakra-ui/icons";
import axios from "axios";

export default function InfoModal({
setData,
Expand All @@ -28,22 +29,39 @@ export default function InfoModal({
}) {
const [showEmail, setShowEmail] = useState(false);
const [isShared, setIsShared] = useState(false);
const { onLoginModalOpen } = useContext(DataContext);
const { onLoginModalOpen, token, setLoading } = useContext(DataContext);
const { user } = UserAuth();
const navigate = useNavigate();
const feedbackModalDisclosure = useDisclosure();
const currentEmail = user?.email;

// function viewEmail() {
// if (user) {
// setShowEmail(true);
// }
// }

async function handleResolve() {
feedbackModalDisclosure.onOpen();
}

async function handleDelete() {
onClose();
setLoading(false);
if (!currentEmail) {
return;
}
axios
.delete(`${process.env.REACT_APP_AWS_BACKEND_URL}/items/${props.id}`, {
headers: {
Authorization: `Bearer ${token}`, // verify auth
},
})
.then(() => console.log("Success"))
.catch((err) => console.log(err));
setData((prevItems) => {
if (prevItems && prevItems.length > 0) {
return prevItems.filter((item) => item.id !== props.id);
}
return prevItems;
});
setLoading(true);
}

const formattedDate = formatDate(new Date(props.date));
return (
<>
Expand Down Expand Up @@ -170,6 +188,21 @@ export default function InfoModal({
<CheckIcon /> Resolve
</Button>
)}

{[
"[email protected]",
"[email protected]",
"[email protected]",
].includes(currentEmail) && (
<Button
colorScheme="red"
size={"lg"}
gap={2}
onClick={handleDelete}
>
<CheckIcon /> Delete
</Button>
)}
<Button
colorScheme="blue"
size={"lg"}
Expand Down

0 comments on commit 6db9b81

Please sign in to comment.