Added additional precuations for users that do not exist and verified auth access.
This commit is contained in:
46
src/components/atoms/delete-job/delete-job.atom.jsx
Normal file
46
src/components/atoms/delete-job/delete-job.atom.jsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import { DeleteFilled } from "@ant-design/icons";
|
||||
import { useMutation } from "@apollo/client";
|
||||
import { Button, message, Popconfirm } from "antd";
|
||||
import React, { useState } from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { DELETE_JOB } from "../../../graphql/jobs.queries";
|
||||
import { setSelectedJobId } from "../../../redux/application/application.actions";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setSelectedJobId: (id) => dispatch(setSelectedJobId(id)),
|
||||
});
|
||||
export function DeleteJobAtom({ setSelectedJobId, jobId }) {
|
||||
const [deleteJob] = useMutation(DELETE_JOB);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const handleDelete = async () => {
|
||||
setLoading(true);
|
||||
const result = await deleteJob({
|
||||
variables: { jobId: jobId },
|
||||
});
|
||||
|
||||
if (result.errors) {
|
||||
message.error(result.errors.toString());
|
||||
} else {
|
||||
message.success("Job deleted.");
|
||||
setSelectedJobId(null);
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Popconfirm
|
||||
title="Are you sure you want to delete this job? This cannot be undone."
|
||||
onConfirm={handleDelete}
|
||||
>
|
||||
<Button loading={loading}>
|
||||
<DeleteFilled />
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(DeleteJobAtom);
|
||||
Reference in New Issue
Block a user