diff --git a/admin/src/components/admin/ServicesManager.jsx b/admin/src/components/admin/ServicesManager.jsx index a5e9b9d..bdeca2b 100644 --- a/admin/src/components/admin/ServicesManager.jsx +++ b/admin/src/components/admin/ServicesManager.jsx @@ -1,14 +1,26 @@ import React, { useState, useEffect } from 'react'; import { Plus, Edit2, Trash2, X, GripVertical, FolderPlus, Move, Loader2, RefreshCw, Trash } from 'lucide-react'; import { DragDropContext, Droppable, Draggable } from '@hello-pangea/dnd'; +import ConfirmModal from '../common/ConfirmModel.jsx'; import api from '../../utils/api'; const ServicesManager = () => { const [services, setServices] = useState([]); const [categories, setCategories] = useState([]); const [dbCategories, setDbCategories] = useState([]); + const [isServiceModalOpen, setIsServiceModalOpen] = useState(false); const [isCategoryModalOpen, setIsCategoryModalOpen] = useState(false); + const [isReorderModalOpen, setIsReorderModalOpen] = useState(false); + + const [confirmModal, setConfirmModal] = useState({ + isOpen: false, + title: "", + message: "", + onConfirm: null, + isDanger: false, + }); + const [editingService, setEditingService] = useState(null); const [editingCategory, setEditingCategory] = useState(null); @@ -25,11 +37,7 @@ const ServicesManager = () => { const [newSubcategory, setNewSubcategory] = useState(''); const [addingSubcategoryTo, setAddingSubcategoryTo] = useState(null); // categoryId const [editingSubcategory, setEditingSubcategory] = useState(null); // { catId: '...', oldName: '...', newName: '...' } - const [loading, setLoading] = useState(true); - - // Reorder Categories Modal State - const [isReorderModalOpen, setIsReorderModalOpen] = useState(false); const [reorderedCategories, setReorderedCategories] = useState([]); const [categoryFormData, setCategoryFormData] = useState({ @@ -39,8 +47,28 @@ const ServicesManager = () => { order: 0 }); + const [isCreatingSubcategory, setIsCreatingSubcategory] = useState(false); + + const closeConfirmModal = () => { + setConfirmModal({ ...confirmModal, isOpen: false }); + }; + + const initiateServiceToggle = (service) => { + if (service.isActive) { + setConfirmModal({ + isOpen: true, + title: 'Disable Service?', + message: `Are you sure you want to disable "${service.name}"? It will be hidden from the public menu.`, + isDanger: true, + onConfirm: () => handleServiceToggle(service) + }); + } else { + handleServiceToggle(service); + } + }; + // Extracted ServiceItem component for reuse - const ServiceItem = ({ service, index, openServiceModal, handleServiceToggle, formatPrice }) => ( + const ServiceItem = ({ service, index, openServiceModal, initiateServiceToggle, formatPrice }) => ( {(provided, snapshot) => (
{
- {/*
- - setCategoryFormData({ ...categoryFormData, image: e.target.value })} - required - /> -

- Use high-quality images from Unsplash or other sources -

-
*/} -
))} - {/* {(!categoryFormData.subcategories || categoryFormData.subcategories.length === 0) && ( -

No subcategories added yet

- )} */} @@ -1151,87 +1191,6 @@ const ServicesManager = () => { )} - {/* Category Modal - Simplified & Unique Design */} - {isCategoryModalOpen && ( -
-
- {/* Header */} -
-
- -

- {editingCategory ? 'Edit Category' : 'New Category'} -

-
- - {/* Form */} -
-
-
- - setCategoryFormData({ ...categoryFormData, name: e.target.value })} - required - /> -
- - {/* Image URL Input */} -
- - setCategoryFormData({ ...categoryFormData, image: e.target.value })} - required - /> - {categoryFormData.image && ( -
- Preview e.target.style.display = 'none'} - /> - -
- )} -
-
- - -
-
-
- )} {isReorderModalOpen && (
diff --git a/admin/src/components/common/ConfirmModel.jsx b/admin/src/components/common/ConfirmModel.jsx new file mode 100644 index 0000000..d1de24f --- /dev/null +++ b/admin/src/components/common/ConfirmModel.jsx @@ -0,0 +1,72 @@ +import React from "react"; +import { X, AlertTriangle } from "lucide-react"; // Optional icons for better UI + +const ConfirmModal = ({ + isOpen, + onClose, + onConfirm, + title, + message, + isDanger = false, +}) => { + if (!isOpen) return null; + + return ( +
+ {/* Modal Container */} +
e.stopPropagation()} + > + {/* Header (Optional Visual Indicator) */} +
+ +
+
+ {/* Icon */} +
+ +
+ + {/* Content */} +
+

+ {title} +

+

+ {message} +

+
+
+ + {/* Actions */} +
+ + +
+
+
+
+ ); +}; + +export default ConfirmModal; diff --git a/frontend/src/components/ui/ConfirmModel.jsx b/frontend/src/components/ui/ConfirmModel.jsx new file mode 100644 index 0000000..d1de24f --- /dev/null +++ b/frontend/src/components/ui/ConfirmModel.jsx @@ -0,0 +1,72 @@ +import React from "react"; +import { X, AlertTriangle } from "lucide-react"; // Optional icons for better UI + +const ConfirmModal = ({ + isOpen, + onClose, + onConfirm, + title, + message, + isDanger = false, +}) => { + if (!isOpen) return null; + + return ( +
+ {/* Modal Container */} +
e.stopPropagation()} + > + {/* Header (Optional Visual Indicator) */} +
+ +
+
+ {/* Icon */} +
+ +
+ + {/* Content */} +
+

+ {title} +

+

+ {message} +

+
+
+ + {/* Actions */} +
+ + +
+
+
+
+ ); +}; + +export default ConfirmModal;