-
-
+
+
+
+
-
- {{ t('category.create.buttonTitle') }}
+ {{ t('categories.create.buttonTitle') }}
-
+
diff --git a/src/mocks/handlers/category.handler.ts b/src/mocks/handlers/category.handler.ts
index 7abea35..3ab5423 100644
--- a/src/mocks/handlers/category.handler.ts
+++ b/src/mocks/handlers/category.handler.ts
@@ -2,9 +2,9 @@ import { rest } from 'msw'
import _ from 'lodash'
import { faker } from '@faker-js/faker'
import { CreatePagedResponse } from '../handlers.utility'
-import type { Category } from '~/models/Category'
+import type { Category, CategoryCreateModel } from '~/models/Category'
-const categories = _.times(77, createFakeCategory)
+const categories = _.times(7, createFakeCategory)
const handlers = [
rest.get('/api/Category', (req, res, ctx) => {
const response = CreatePagedResponse
(req, categories)
@@ -14,6 +14,22 @@ const handlers = [
ctx.json(response),
)
}),
+ rest.post('/api/Category', async (req, res, ctx) => {
+ const newItem = await req.json()
+ const category: Category = {
+ id: faker.datatype.number({ max: 2000 }),
+ name: newItem.name,
+ productsCount: 0,
+ subItems: [],
+ }
+ categories.push(category)
+ return res(
+ ctx.status(200),
+ ctx.delay(200),
+ ctx.json(category),
+ )
+ }),
+
]
function createFakeCategory(): Category {
diff --git a/src/models/Category.ts b/src/models/Category.ts
index 4ead569..c110950 100644
--- a/src/models/Category.ts
+++ b/src/models/Category.ts
@@ -4,3 +4,8 @@ export interface Category {
productsCount: number
subItems?: Category[]
}
+
+export interface CategoryCreateModel {
+ name: string
+ parentId: number
+}
diff --git a/src/pages/Categories/index.vue b/src/pages/Categories/index.vue
index dd3b933..1e5aacd 100644
--- a/src/pages/Categories/index.vue
+++ b/src/pages/Categories/index.vue
@@ -1,133 +1,14 @@
-
-
-
-
-
-
- {{ t('category.title') }}
-
-
-
-
-
-
-
- Create
-
-
-
-
-
-
-
-
+
+meta:
+ title: Category Management
+
-
-
-
-
-
-
+
+
diff --git a/src/services/category.service.ts b/src/services/category.service.ts
index ea0e45c..b31455d 100644
--- a/src/services/category.service.ts
+++ b/src/services/category.service.ts
@@ -1,5 +1,5 @@
import { ApiService } from '~/common/api/api-service'
-import type { Category } from '~/models/Category'
+import type { Category, CategoryCreateModel } from '~/models/Category'
import type { PagedAndSortedRequest } from '~/models/PagedAndSortedRequest'
import type { PagedListResult } from '~/models/PagedListResult'
@@ -11,7 +11,7 @@ class CategoryService {
return response
}
- async createCategory(categoryItem: Category): Promise {
+ async createCategory(categoryItem: CategoryCreateModel): Promise {
return apiService.post('', categoryItem)
}
}
diff --git a/src/store/category.store.ts b/src/store/category.store.ts
index 16650d3..0ff1832 100644
--- a/src/store/category.store.ts
+++ b/src/store/category.store.ts
@@ -1,5 +1,5 @@
import { acceptHMRUpdate, defineStore } from 'pinia'
-import type { Category } from '~/models/Category'
+import type { Category, CategoryCreateModel } from '~/models/Category'
import type { PagedAndSortedRequest } from '~/models/PagedAndSortedRequest'
import categoryService from '~/services/category.service'
@@ -29,11 +29,12 @@ export const useCategoryStore = defineStore('Category', () => {
}
- async function createCategory(categoryItem: Category) {
+ async function createCategory(categoryItem: CategoryCreateModel) {
isLoading.value = true
try {
const response = await categoryService.createCategory(categoryItem)
- categories.value.push(response)
+ getCategories(options.value)
+ // categories.value.push(response)
}
finally {
isLoading.value = false
diff --git a/src/styles/main.scss b/src/styles/main.scss
index 6bef6d6..ee0c38c 100644
--- a/src/styles/main.scss
+++ b/src/styles/main.scss
@@ -55,7 +55,6 @@ body {
.page-title {
font-size: 1.1rem;
- padding-bottom: 1.2rem;
}
@import 'dark';
@import 'utils/override';