From d819a62c0c0fa811cb5f148217305bd2b6d2742c Mon Sep 17 00:00:00 2001 From: Saeid Doroudi Date: Fri, 17 Nov 2023 17:12:50 +0330 Subject: [PATCH] Implement Add Category Fixes #17 --- locales/en.yml | 6 +- src/components.d.ts | 4 + .../Category/CategoryManagement.vue | 134 ++++++++++++++++++ src/components/Category/CreateCategory.vue | 74 +++++++--- src/mocks/handlers/category.handler.ts | 20 ++- src/models/Category.ts | 5 + src/pages/Categories/index.vue | 131 +---------------- src/services/category.service.ts | 4 +- src/store/category.store.ts | 7 +- src/styles/main.scss | 1 - 10 files changed, 234 insertions(+), 152 deletions(-) create mode 100644 src/components/Category/CategoryManagement.vue diff --git a/locales/en.yml b/locales/en.yml index 865cd3c..1679e49 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -58,11 +58,15 @@ forgot: dashboard: summary: Summary transactions: Transactions -category: +categories: title: Categories + createButton: Create create: buttonTitle: Create title: Create New Category categoryName: Name parent: Parent + validations: + nameRequired: Name is required + parentRequired: Parent Not Selected not-found: Not found diff --git a/src/components.d.ts b/src/components.d.ts index 6486a9f..8c21fc2 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -9,6 +9,7 @@ declare module 'vue' { export interface GlobalComponents { BarChart: typeof import('./components/BarChart.vue')['default'] Card: typeof import('./components/Card.vue')['default'] + CategoryManagement: typeof import('./components/Category/CategoryManagement.vue')['default'] CategoryStatics: typeof import('./components/Category/CategoryStatics.vue')['default'] CreateCategory: typeof import('./components/Category/CreateCategory.vue')['default'] DashboardCard: typeof import('./components/DashboardCard.vue')['default'] @@ -23,6 +24,8 @@ declare module 'vue' { NDialogProvider: typeof import('naive-ui')['NDialogProvider'] NDrawer: typeof import('naive-ui')['NDrawer'] NDrawerContent: typeof import('naive-ui')['NDrawerContent'] + NForm: typeof import('naive-ui')['NForm'] + NFormItem: typeof import('naive-ui')['NFormItem'] NIcon: typeof import('naive-ui')['NIcon'] NInput: typeof import('naive-ui')['NInput'] NLayout: typeof import('naive-ui')['NLayout'] @@ -33,6 +36,7 @@ declare module 'vue' { NNotificationProvider: typeof import('naive-ui')['NNotificationProvider'] NPageHeader: typeof import('naive-ui')['NPageHeader'] NPopselect: typeof import('naive-ui')['NPopselect'] + NSelect: typeof import('naive-ui')['NSelect'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] Sidebar: typeof import('./components/Sidebar.vue')['default'] diff --git a/src/components/Category/CategoryManagement.vue b/src/components/Category/CategoryManagement.vue new file mode 100644 index 0000000..eda90c9 --- /dev/null +++ b/src/components/Category/CategoryManagement.vue @@ -0,0 +1,134 @@ + + + + + diff --git a/src/components/Category/CreateCategory.vue b/src/components/Category/CreateCategory.vue index 393d39e..b7b2a9e 100644 --- a/src/components/Category/CreateCategory.vue +++ b/src/components/Category/CreateCategory.vue @@ -1,37 +1,75 @@ 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 @@ -