@rtbjs/use-state
Version:
`@rtbjs/use-state` is a state management tool that can act as a local state and be easily turned into a global redux state. It is an innovative approach to state management that combines the advantages of both React's useState and Redux's state management
51 lines • 2.39 kB
JavaScript
import { __assign } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect } from 'react';
import { toast } from 'react-toastify';
import { useDeleteProjectMutation } from '../../redux/api/project-api';
import { useNavigate } from 'react-router-dom';
import { UpdateProjectModal } from './update-project';
import { Button, List, Typography } from 'antd';
import { DeleteOutlined, EditOutlined } from '@ant-design/icons';
var ProjectItem = function (_a) {
var project = _a.project;
var navigate = useNavigate();
var _b = useDeleteProjectMutation(), deleteProject = _b[0], _c = _b[1], isLoading = _c.isLoading, error = _c.error, isSuccess = _c.isSuccess, isError = _c.isError;
useEffect(function () {
if (isSuccess) {
toast.success('Post deleted successfully');
}
if (isError) {
if (Array.isArray(error.data.error)) {
error.data.error.forEach(function (el) {
return toast.error(el.message, {
position: 'top-right'
});
});
}
else {
toast.error(error.data.message, {
position: 'top-right'
});
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isLoading]);
var onDeleteHandler = function () {
if (window.confirm('Are you sure')) {
deleteProject(project.id);
}
};
var handleOnProjectClick = function () {
navigate("/project/".concat(project.id, "/reduxHistory/").concat(project.reduxHistoryRoot));
};
return (_jsx(List.Item, __assign({ actions: [
_jsx(UpdateProjectModal, { Trigger: function (_a) {
var onClick = _a.onClick;
return (_jsx(Button, { type: "primary", shape: "circle", icon: _jsx(EditOutlined, {}), onClick: onClick }));
}, project: project }, "edit"),
_jsx(Button, { type: "primary", shape: "circle", icon: _jsx(DeleteOutlined, {}), onClick: onDeleteHandler }, "delete"),
] }, { children: _jsx(List.Item.Meta, { title: _jsx(Typography.Link, __assign({ onClick: handleOnProjectClick }, { children: project.name })), description: project.description }) })));
};
export { ProjectItem };
//# sourceMappingURL=project.component.js.map