diff --git a/src/api/CategoriesApi.js b/src/api/CategoriesApi.js index a61128e..af98bcc 100644 --- a/src/api/CategoriesApi.js +++ b/src/api/CategoriesApi.js @@ -1,7 +1,8 @@ // src/api/CategoriesApi.js export default class CategoriesApi { constructor(token) { - this.baseUrl = 'https://inventory-bff.dream-views.com/api/v1/Tags'; + this.tagUrl = 'https://inventory-bff.dream-views.com/api/v1/Tag'; // <— singular + this.tagTypeUrl = 'https://inventory-bff.dream-views.com/api/v1/TagType'; this.token = token; } @@ -13,8 +14,9 @@ export default class CategoriesApi { }; } + // TAGS async getAll() { - const res = await fetch(`${this.baseUrl}/GetAll`, { + const res = await fetch(`${this.tagUrl}/GetAll`, { method: 'GET', headers: this.headers(false), }); @@ -22,8 +24,8 @@ export default class CategoriesApi { return res.json(); } - async create(payload) { - const res = await fetch(`${this.baseUrl}/Create`, { + async create(payload) { // CreateTagRequest + const res = await fetch(`${this.tagUrl}/Create`, { method: 'POST', headers: this.headers(), body: JSON.stringify(payload), @@ -32,8 +34,8 @@ export default class CategoriesApi { return res.json(); } - async update(payload) { - const res = await fetch(`${this.baseUrl}/Update`, { + async update(payload) { // UpdateTagRequest + const res = await fetch(`${this.tagUrl}/Update`, { method: 'PUT', headers: this.headers(), body: JSON.stringify(payload), @@ -42,8 +44,18 @@ export default class CategoriesApi { return res.json(); } + async changeStatus(payload) { // { id, status } + const res = await fetch(`${this.tagUrl}/ChangeStatus`, { + method: 'PATCH', + headers: this.headers(), + body: JSON.stringify(payload), + }); + if (!res.ok) throw new Error(`ChangeStatus error ${res.status}: ${await res.text()}`); + return res.json(); + } + async delete(payload) { - const res = await fetch(`${this.baseUrl}/Delete`, { + const res = await fetch(`${this.tagUrl}/Delete`, { method: 'DELETE', headers: this.headers(), body: JSON.stringify(payload), @@ -51,4 +63,14 @@ export default class CategoriesApi { if (!res.ok) throw new Error(`Delete error ${res.status}: ${await res.text()}`); return res.json(); } + + // TAG TYPES (para updateField('typeId', e.target.value)} + > + {typeOptions.map((opt) => ( + {opt.label} + ))} + + + + + Parent Categories + + + + updateField('displayOrder', e.target.value)} + fullWidth + sx={{ mb: 2 }} + /> + + updateField('icon', e.target.value)} + fullWidth + /> + + {category._Id && ( + + Status + + + )} + diff --git a/src/private/categories/Categories.jsx b/src/private/categories/Categories.jsx index 41feccb..e6db26f 100644 --- a/src/private/categories/Categories.jsx +++ b/src/private/categories/Categories.jsx @@ -47,8 +47,12 @@ export default function Categories() { setEditingCategory({ _Id: r._id || r._Id || '', id: r.id || r.Id || '', - name: r.name ?? '', - description: r.description ?? '', + name: r.tagName ?? r.name ?? '', + slug: r.slug ?? '', + typeId: r.typeId ?? '', + parentTagId: Array.isArray(r.parentTagId) ? r.parentTagId : [], + displayOrder: Number.isFinite(r.displayOrder) ? r.displayOrder : 0, + icon: r.icon ?? '', status: r.status ?? 'Active', }); setOpen(true); @@ -62,14 +66,10 @@ export default function Categories() { const confirmDelete = async () => { try { if (!rowToDelete) return; - const payload = { - _Id: rowToDelete._id || rowToDelete._Id, - id: rowToDelete.id || rowToDelete.Id || '', - name: rowToDelete.name, - description: rowToDelete.description, - status: 'Inactive', // soft-delete - }; - await api.update(payload); + await api.changeStatus({ + id: rowToDelete.id || rowToDelete.Id || rowToDelete._id || rowToDelete._Id, + status: 'Inactive', + }); await loadData(); } catch (e) { console.error('Delete failed:', e); @@ -86,8 +86,9 @@ export default function Categories() { }; const columns = [ - { field: 'name', headerName: 'Name', flex: 1, minWidth: 200 }, - { field: 'description', headerName: 'Description', flex: 1, minWidth: 250 }, + { field: 'tagName', headerName: 'Name', flex: 1, minWidth: 200, valueGetter: (p) => p.row?.tagName ?? p.row?.name }, + { field: 'slug', headerName: 'Slug', width: 220 }, + { field: 'displayOrder', headerName: 'Display', width: 120, valueGetter: (p) => p.row?.displayOrder ?? 0 }, { field: 'status', headerName: 'Status', width: 140, valueGetter: (p) => p.row?.status ?? 'Active' }, { field: 'actions',