@nestbotics/nct_frontend_common_components
Version:
A collection of reusable React components with theme management and styling utilities
184 lines (183 loc) • 6.86 kB
JavaScript
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { useContext, useState, useEffect } from 'react';
import { useTheme } from "@mui/material";
import { tokens } from "../../theme/Theme";
import { userDataContext } from '../../context/UserDataProvider';
// Optional toast import - fallback to console if not available
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var toast;
try {
toast = require('react-hot-toast').default;
} catch (e) {
toast = {
promise: function promise(_promise, options) {
console.log('Loading...');
return _promise.then(function (result) {
console.log('Success:', (options === null || options === void 0 ? void 0 : options.success) || 'Operation completed');
return result;
}, function (error) {
console.error('Error:', (options === null || options === void 0 ? void 0 : options.error) || 'Operation failed');
throw error;
});
}
};
}
function DeleteTaskAlert(_ref) {
var handleConfirmDelete = _ref.handleConfirmDelete,
action = _ref.action,
handleConfirmSave = _ref.handleConfirmSave;
var theme = useTheme();
var colors = tokens(theme.palette.mode);
var _useState = useState(false),
_useState2 = _slicedToArray(_useState, 2),
isOpen = _useState2[0],
setIsOpen = _useState2[1];
var _useState3 = useState(false),
_useState4 = _slicedToArray(_useState3, 2),
isChecked = _useState4[0],
setIsChecked = _useState4[1];
var _useContext = useContext(userDataContext),
setDeleteTaskAlert = _useContext.setDeleteTaskAlert,
deleteTaskAlert = _useContext.deleteTaskAlert,
deleteTask = _useContext.deleteTask,
editTask = _useContext.editTask,
setDeleteTask = _useContext.setDeleteTask,
setEditTask = _useContext.setEditTask;
useEffect(function () {
if (deleteTaskAlert) {
setIsOpen(true);
} else {
setIsOpen(false);
}
}, [deleteTaskAlert]);
var handleClose = function handleClose() {
setIsOpen(false);
setDeleteTaskAlert(false);
};
var handleDelete = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
if (!deleteTask) {
_context.next = 7;
break;
}
_context.next = 4;
return toast.promise(handleConfirmDelete(deleteTask), {
loading: 'Removing...',
success: /*#__PURE__*/_jsx("b", {
children: "User removed!"
}),
error: /*#__PURE__*/_jsx("b", {
children: "Could not be removed."
})
});
case 4:
setDeleteTask(null);
_context.next = 11;
break;
case 7:
if (!editTask) {
_context.next = 11;
break;
}
_context.next = 10;
return toast.promise(handleConfirmSave(editTask), {
loading: 'Modifying...',
success: /*#__PURE__*/_jsx("b", {
children: "Change saved!"
}),
error: /*#__PURE__*/_jsx("b", {
children: "Could not be saved!."
})
});
case 10:
setEditTask(null);
case 11:
_context.next = 16;
break;
case 13:
_context.prev = 13;
_context.t0 = _context["catch"](0);
console.error("Error:", _context.t0);
case 16:
handleClose();
case 17:
case "end":
return _context.stop();
}
}, _callee, null, [[0, 13]]);
}));
return function handleDelete() {
return _ref2.apply(this, arguments);
};
}();
var handleCheckboxChange = function handleCheckboxChange(e) {
setIsChecked(e.target.checked);
};
return /*#__PURE__*/_jsx("div", {
children: isOpen && /*#__PURE__*/_jsx("div", {
className: "fixed inset-0 flex items-center justify-center bg-gray-800 bg-opacity-65 z-50",
children: /*#__PURE__*/_jsxs("div", {
className: "h-[26%] rounded-lg shadow-lg w-full max-w-md relative",
style: {
backgroundColor: colors.primary[400]
},
children: [/*#__PURE__*/_jsx("div", {
className: "bg-[#5b3a91] text-white text-center rounded-lg absolute top-[-8px] left-[21%] transform -translate-x-1/2",
style: {
clipPath: 'polygon(0 0, 100% 0, 90% 100%, 10% 100%)',
width: 'fit-content',
padding: '10px 25px'
},
children: /*#__PURE__*/_jsx("h2", {
className: "text-[14px] text-white font-semibold",
children: editandmodify[action].event_name
})
}), /*#__PURE__*/_jsxs("div", {
className: "pl-[20px] pt-[15px] h-full flex flex-col gap-[10px] justify-center items-baseline",
children: [/*#__PURE__*/_jsx("p", {
className: "text-gray-700 mb-4 text-md w-full pl-1",
style: {
color: colors.primary[100]
},
children: editandmodify[action].description
}), /*#__PURE__*/_jsxs("div", {
className: "flex items-center mb-4",
children: [/*#__PURE__*/_jsx("input", {
type: "checkbox",
id: "confirm-delete",
checked: isChecked,
onChange: handleCheckboxChange,
className: "mr-2"
}), /*#__PURE__*/_jsx("label", {
htmlFor: "confirm-delete",
className: "text-md",
style: {
color: colors.primary[100]
},
children: editandmodify[action].checkbox
})]
}), /*#__PURE__*/_jsxs("div", {
className: "flex justify-end pl-9",
children: [/*#__PURE__*/_jsx("button", {
className: "bg-gray-300 hover:bg-gray-400 text-slate-700 font-bold py-2 px-4 rounded mr-2",
onClick: handleClose,
children: "Cancel"
}), /*#__PURE__*/_jsx("button", {
className: "bg-[#5b3a91] hover:bg-[#5b3a91e0] text-white font-bold py-2 px-4 rounded ".concat(isChecked ? '' : 'opacity-50 cursor-not-allowed'),
disabled: !isChecked,
onClick: handleDelete,
children: editandmodify[action].actionbtn
})]
})]
})]
})
})
});
}
export default DeleteTaskAlert;