admin
This commit is contained in:
@@ -40,12 +40,12 @@ const AdminEquipment = () => {
|
|||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const [equipmentResponse, typesResponse] = await Promise.all([
|
const [equipmentResponse, typesResponse] = await Promise.all([
|
||||||
equipmentAPI.getEquipment(),
|
equipmentAPI.getAll(),
|
||||||
equipmentAPI.getEquipmentTypes()
|
equipmentAPI.getTypes()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
setEquipment(equipmentResponse.data.data.equipment || []);
|
setEquipment(equipmentResponse.data.data.equipment || []);
|
||||||
setEquipmentTypes(typesResponse.data.data.types || []);
|
setEquipmentTypes(typesResponse.data.data.equipmentTypes || []);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch equipment:', error);
|
console.error('Failed to fetch equipment:', error);
|
||||||
toast.error('Failed to load equipment');
|
toast.error('Failed to load equipment');
|
||||||
@@ -57,7 +57,7 @@ const AdminEquipment = () => {
|
|||||||
const handleCreate = async (e) => {
|
const handleCreate = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
await equipmentAPI.createEquipment(formData);
|
await equipmentAPI.create(formData);
|
||||||
toast.success('Equipment created successfully');
|
toast.success('Equipment created successfully');
|
||||||
setShowCreateModal(false);
|
setShowCreateModal(false);
|
||||||
resetForm();
|
resetForm();
|
||||||
@@ -71,7 +71,7 @@ const AdminEquipment = () => {
|
|||||||
const handleUpdate = async (e) => {
|
const handleUpdate = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
await equipmentAPI.updateEquipment(selectedEquipment.id, formData);
|
await equipmentAPI.update(selectedEquipment.id, formData);
|
||||||
toast.success('Equipment updated successfully');
|
toast.success('Equipment updated successfully');
|
||||||
setShowEditModal(false);
|
setShowEditModal(false);
|
||||||
resetForm();
|
resetForm();
|
||||||
@@ -84,7 +84,7 @@ const AdminEquipment = () => {
|
|||||||
|
|
||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
try {
|
try {
|
||||||
await equipmentAPI.deleteEquipment(selectedEquipment.id);
|
await equipmentAPI.delete(selectedEquipment.id);
|
||||||
toast.success('Equipment deleted successfully');
|
toast.success('Equipment deleted successfully');
|
||||||
setShowDeleteModal(false);
|
setShowDeleteModal(false);
|
||||||
setSelectedEquipment(null);
|
setSelectedEquipment(null);
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ const AdminProducts = () => {
|
|||||||
const [searchTerm, setSearchTerm] = useState('');
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
const [categoryFilter, setCategoryFilter] = useState('all');
|
const [categoryFilter, setCategoryFilter] = useState('all');
|
||||||
const [typeFilter, setTypeFilter] = useState('all');
|
const [typeFilter, setTypeFilter] = useState('all');
|
||||||
const [productTypeFilter, setProductTypeFilter] = useState('all'); // shared vs custom
|
|
||||||
const [selectedProduct, setSelectedProduct] = useState(null);
|
const [selectedProduct, setSelectedProduct] = useState(null);
|
||||||
const [showCreateModal, setShowCreateModal] = useState(false);
|
const [showCreateModal, setShowCreateModal] = useState(false);
|
||||||
const [showEditModal, setShowEditModal] = useState(false);
|
const [showEditModal, setShowEditModal] = useState(false);
|
||||||
@@ -43,7 +42,7 @@ const AdminProducts = () => {
|
|||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const [productsResponse, categoriesResponse] = await Promise.all([
|
const [productsResponse, categoriesResponse] = await Promise.all([
|
||||||
productsAPI.getProducts({
|
adminAPI.getProducts({
|
||||||
search: searchTerm,
|
search: searchTerm,
|
||||||
category: categoryFilter !== 'all' ? categoryFilter : '',
|
category: categoryFilter !== 'all' ? categoryFilter : '',
|
||||||
type: typeFilter !== 'all' ? typeFilter : ''
|
type: typeFilter !== 'all' ? typeFilter : ''
|
||||||
@@ -51,8 +50,8 @@ const AdminProducts = () => {
|
|||||||
productsAPI.getCategories()
|
productsAPI.getCategories()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
setProducts(productsResponse.data.data.sharedProducts || []);
|
setProducts(productsResponse.data.data.products || []);
|
||||||
setUserProducts(productsResponse.data.data.userProducts || []);
|
setUserProducts([]); // Admin can only manage shared products for now
|
||||||
setCategories(categoriesResponse.data.data.categories || []);
|
setCategories(categoriesResponse.data.data.categories || []);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch products:', error);
|
console.error('Failed to fetch products:', error);
|
||||||
@@ -162,11 +161,8 @@ const AdminProducts = () => {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Filter products based on shared/custom filter
|
// Only show shared products for admin management
|
||||||
const allProducts = [
|
const allProducts = products.map(p => ({ ...p, isShared: true }));
|
||||||
...(productTypeFilter === 'custom' ? [] : products.map(p => ({ ...p, isShared: true }))),
|
|
||||||
...(productTypeFilter === 'shared' ? [] : userProducts.map(p => ({ ...p, isShared: false })))
|
|
||||||
];
|
|
||||||
|
|
||||||
const ProductForm = ({ onSubmit, submitText }) => (
|
const ProductForm = ({ onSubmit, submitText }) => (
|
||||||
<form onSubmit={onSubmit} className="space-y-4">
|
<form onSubmit={onSubmit} className="space-y-4">
|
||||||
@@ -381,15 +377,6 @@ const AdminProducts = () => {
|
|||||||
<option value="seed">Seed</option>
|
<option value="seed">Seed</option>
|
||||||
<option value="powder">Powder</option>
|
<option value="powder">Powder</option>
|
||||||
</select>
|
</select>
|
||||||
<select
|
|
||||||
value={productTypeFilter}
|
|
||||||
onChange={(e) => setProductTypeFilter(e.target.value)}
|
|
||||||
className="px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
||||||
>
|
|
||||||
<option value="all">Shared & Custom</option>
|
|
||||||
<option value="shared">Shared Only</option>
|
|
||||||
<option value="custom">Custom Only</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user