chore: clean code, add delete

This commit is contained in:
Rodolfo Ruiz
2025-09-06 20:45:56 -06:00
parent b3209a4019
commit f7adaf1b18
5 changed files with 24 additions and 26 deletions

View File

@@ -1,7 +1,7 @@
export default class ProductsApi {
constructor(token) {
this.baseUrl = 'https://inventory-bff.dream-views.com/api/v1/FurnitureVariant';
this.token = token;
this.token = token;
}
headers(json = true) {
@@ -53,7 +53,7 @@ export default class ProductsApi {
return res.json();
}
async changeStatusVariant(payload) {
async changeStatusVariant(payload) {
// If your API is change status, reuse updateVariant.
const res = await fetch(`${this.baseUrl}/ChangeStatus`, {
method: 'PATCH',

View File

@@ -52,14 +52,14 @@ export default function AddOrEditCategoryForm({ onAdd, initialData, onCancel, ma
const [types, setTypes] = useState([]);
const [allTags, setAllTags] = useState([]);
const tagLabelById = useMemo(() => {
const map = {};
for (const t of allTags) {
const key = t._id;
map[key] = t.tagName || t.name || key;
}
return map;
}, [allTags]);
const tagLabelById = useMemo(() => {
const map = {};
for (const t of allTags) {
const key = t._id;
map[key] = t.tagName || t.name || key;
}
return map;
}, [allTags]);
const [form, setForm] = useState({
_id: '',

View File

@@ -149,7 +149,7 @@ export default function Categories() {
{
field: 'actions',
headerName: '',
width: 130,
width: 150,
sortable: false,
filterable: false,
disableExport: true,

View File

@@ -43,7 +43,7 @@ export default function ProductCollections() {
const tagTypeApi = useMemo(() => new TagTypeApi(token), [token]);
const categoriesApi = useMemo(() => new CategoriesApi(token), [token]);
const toast = useApiToast();
const { handleError } = useApiToast();
const [rows, setRows] = useState([]);
const [rawRows, setRawRows] = useState([]);
@@ -85,7 +85,7 @@ export default function ProductCollections() {
return found?.tagName || String(value);
};
};
// Cargar TagTypes + Tags
useEffect(() => {
let mounted = true;
@@ -153,7 +153,7 @@ export default function ProductCollections() {
setRawRows(normalized);
} catch (err) {
console.error(err);
toast.error(err?.message || 'Error loading variants');
handleError(err, 'Error loading product collections');
} finally {
setLoading(false);
}
@@ -177,12 +177,10 @@ export default function ProductCollections() {
const confirmDelete = async () => {
try {
if (!editRow?.id) return;
await api.changeStatusVariant({ mongoId: editRow.id, status: 'Inactive' });
await api.changeStatusVariant({ mongoId: editRow._Id, status: 'Inactive' });
await load();
toast.success('Deleted successfully');
} catch (err) {
console.error(err);
toast.error(err?.message || 'Delete failed');
} finally {
setConfirmOpen(false);
setEditRow(null);
@@ -361,13 +359,13 @@ export default function ProductCollections() {
</Box>
<Dialog open={open} onClose={() => setOpen(false)} maxWidth="md" fullWidth>
<DialogTitle>
{viewOnly
? 'View Product Collection'
: editRow
? 'Edit Product Collection'
: 'Add Product Collection'}
</DialogTitle>
<DialogTitle>
{viewOnly
? 'View Product Collection'
: editRow
? 'Edit Product Collection'
: 'Add Product Collection'}
</DialogTitle>
<DialogContent>
<AddOrEditProductCollectionForm
initialData={editRow}
@@ -384,7 +382,7 @@ export default function ProductCollections() {
/>
</DialogContent>
</Dialog>
<Dialog open={confirmOpen} onClose={() => setConfirmOpen(false)}>
<DialogTitle>Delete Product Collection</DialogTitle>
<DialogContent>

View File

@@ -102,7 +102,7 @@ export default function UserManagement() {
status: r.status ?? 'Active',
companies: Array.isArray(r.companies) ? r.companies : [],
projects: Array.isArray(r.projects) ? r.projects : [],
};
};
setEditingData(normalized);
setOpen(true);
};