Compare commits

..

7 Commits

4 changed files with 78 additions and 33 deletions

View File

@ -18,15 +18,15 @@ const ConfirmModal = ({ type, onSubmit, onClose, message, loading ,header}) => {
case "other":
return "md";
default:
return "sm"; // Return a default modal size
return "sm";
}
};
return (
<div className={`modal-dialog modal-${TypeofModal(type)} modal-simple modal-confirm`}>
<div className={`modal-dialog modal-${TypeofModal(type)} modal-simple modal-confirm`}>
<div className='modal-dialog modal-dialog-centered'>
<div className="modal-content">
<div className="modal-body">
<div className="modal-body py-1 px-2">
<div className="row">
<div className="text-start mb-1">
@ -43,9 +43,9 @@ const ConfirmModal = ({ type, onSubmit, onClose, message, loading ,header}) => {
<div className='row'>
<div className='col-4 col-sm-2'> {TypeofIcon(type)}</div>
<div className='col-8 col-sm-10 py-sm-2 py-1 text-sm-end'>
<div className='col-8 col-sm-10 py-sm-2 py-1 text-sm-start'>
<span className='fs-6 text'>{message}</span>
<div className='d-flex justify-content-center mt-4'>
<div className='d-flex justify-content-end mt-4'>
<button
className='btn btn-primary btn-sm'
onClick={onSubmit}

View File

@ -8,9 +8,39 @@ import EditJobRole from "./EditJobRole";
import CreateActivity from "./CreateActivity";
import EditActivity from "./EditActivity";
import ConfirmModal from "../common/ConfirmModal";
import {MasterRespository} from "../../repositories/MastersRepository";
import {cacheData, getCachedData} from "../../slices/apiDataManager";
import showToast from "../../services/toastService";
const MasterModal = ({ modaldata, closeModal }) => {
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
const [ isDeleteModalOpen, setIsDeleteModalOpen ] = useState( false );
const handleSelectedMasterDeleted = async () =>
{
const deleteFn = MasterRespository[modaldata.masterType];
if (!deleteFn) {
showToast(`No delete strategy defined for master type`,"error");
return false;
}
try
{
const response = await deleteFn( modaldata?.item?.id );
const selected_cachedData = getCachedData( modaldata?.masterType );
const updated_master = selected_cachedData?.filter(item => item.id !== modaldata?.item.id);
cacheData( modaldata?.masterType, updated_master )
showToast(`${modaldata?.masterType} is deleted successfully`, "success");
handleCloseDeleteModal()
} catch ( error )
{
const message = error.response.data.message || error.message || "Error occured api during call"
showToast(message, "success");
}
}
useEffect(() => {
if (modaldata?.modalType === "delete") {
@ -35,7 +65,8 @@ const MasterModal = ({ modaldata, closeModal }) => {
<ConfirmModal
type="delete"
header={`Delete ${modaldata.masterType}`}
message={"comming soon.."}
message={"Are you sure you want delete?"}
onSubmit={handleSelectedMasterDeleted}
onClose={handleCloseDeleteModal}
/>
</div>

View File

@ -14,6 +14,7 @@ const MasterTable = ({ data, columns, loading, handleModalData }) => {
"tenant",
"tenantId",
"checkLists",
"isSystem",
];
const safeData = Array.isArray(data) ? data : [];
@ -106,30 +107,36 @@ const MasterTable = ({ data, columns, loading, handleModalData }) => {
)}
</td>
))}
<td className={`${!hasMasterPermission && "d-none"}`}>
<button
aria-label="Modify"
type="button"
data-bs-toggle="modal"
data-bs-target="#master-modal"
className="btn p-0 dropdown-toggle hide-arrow"
onClick={() =>
handleModalData(`Edit-${selectedMaster}`, item)
}
>
<i className="bx bxs-edit me-2 text-primary"></i>
</button>
<td className={!hasMasterPermission ? "d-none" : ""}>
{selectedMaster === "Application Role" && item?.isSystem ? (
"--"
) : (
<>
<button
aria-label="Modify"
type="button"
data-bs-toggle="modal"
data-bs-target="#master-modal"
className="btn p-0 dropdown-toggle hide-arrow"
onClick={() =>
handleModalData(`Edit-${selectedMaster}`, item)
}
>
<i className="bx bxs-edit me-2 text-primary"></i>
</button>
<button
aria-label="Delete"
type="button"
className="btn p-0 dropdown-toggle hide-arrow"
data-bs-toggle="modal"
data-bs-target="#master-modal"
onClick={() => handleModalData("delete", item)}
>
<i className="bx bx-trash me-1 text-danger"></i>
</button>
<button
aria-label="Delete"
type="button"
className="btn p-0 dropdown-toggle hide-arrow"
data-bs-toggle="modal"
data-bs-target="#master-modal"
onClick={() => handleModalData("delete", item)}
>
<i className="bx bx-trash me-1 text-danger"></i>
</button>
</>
)}
</td>
</tr>
))
@ -143,7 +150,7 @@ const MasterTable = ({ data, columns, loading, handleModalData }) => {
)}
{/* Pagination */}
{!loading && safeData.length > 20 && (
{!loading && safeData.length > 20 && (
<nav aria-label="Page ">
<ul className="pagination pagination-sm justify-content-end py-1">
<li className={`page-item ${currentPage === 1 ? "disabled" : ""}`}>

View File

@ -23,15 +23,22 @@ export const MasterRespository = {
getRoles: () => api.get("/api/roles"),
createRole: (data) => api.post("/api/roles", data),
updateRoles:(id,data) => api.put(`/api/roles/${id}`,data),
getFeatures : () => api.get(`/api/feature`),
getFeatures: () => api.get( `/api/feature` ),
createJobRole:(data)=>api.post('api/roles/jobrole',data),
getJobRole :()=>api.get("/api/roles/jobrole"),
updateJobRole: ( id, data ) => api.put( `/api/roles/jobrole/${ id }`, data ),
getActivites: () => api.get( 'api/master/activities' ),
createActivity: (data) => api.post( 'api/master/activity',data ),
updateActivity:(id,data) =>api.post(`api/master/activity/edit/${id}`,data),
getIndustries:()=> api.get('api/master/industries'),
getIndustries: () => api.get( 'api/master/industries' ),
// delete
"Job Role": ( id ) => api.delete( `/api/roles/jobrole/${ id }` ),
"Activity": ( id ) => api.delete( `/api/master/activity/delete/${ id }` ),
"Application Role":(id)=>api.delete(`/api/roles/${id}`),
}