From eddc7ac1ea082bb94f79205fb9d7df334b430b46 Mon Sep 17 00:00:00 2001 From: behnamrhp Date: Fri, 19 May 2023 16:45:27 +0300 Subject: [PATCH 01/26] [TEST]: add to call repo on usecase of get places --- .babelrc | 17 + .eslintignore | 11 + .eslintrc.json | 81 ++++ .husky/pre-push | 5 + jest.config.js | 4 +- package-lock.json | 8 + package.json | 11 +- prettierrc.json | 13 + setupTests.ts | 2 +- .../core/places/common/entity/placeEntity.ts | 4 + .../data/repository/IGetPlacesRepo.ts | 5 + .../data/response-object/getPlacesRO.ts | 13 + .../data/response-object/protocols.ts | 19 + .../usecase/__test__/getPlacesUsecase.test.ts | 25 ++ .../get-places/usecase/getPlaceUsecase.ts | 19 + .../boundaries/http-boundary/httpBoundary.ts | 13 +- .../boundaries/router-boundary/index.tsx | 7 +- .../adapters/adapter.ts | 6 +- .../state-management-boundary/index.ts | 2 +- .../slices/protocols/userSliceProtocols.ts | 2 +- .../slices/userSlice.ts | 6 +- .../state-management-boundary/store/store.ts | 4 +- .../buttons/primary-button/PrimaryButton.tsx | 11 +- .../inputs/simple-input/SimpleInput.tsx | 13 +- .../utils/components/page-title/pageTitle.tsx | 16 +- src/driven/utils/configs/appConfig.ts | 16 +- src/driven/utils/constants/assertUrls.ts | 12 +- src/driven/utils/constants/staticMessages.ts | 28 +- src/driven/utils/helpers/globalHelpers.ts | 5 +- .../protocols/globalHelpersProtocols.ts | 6 +- .../utils/protocols/serviceProtocols.ts | 6 +- .../core/common/table-row/index.tsx | 2 +- .../common/table-row/infra/TableRowInfra.tsx | 18 +- .../core/common/table-row/infra/protocols.ts | 6 +- .../core/common/table-row/view/TableRow.tsx | 21 +- .../core/common/table-row/view/protocols.ts | 6 +- .../view/table-row-item/view/RowItem.tsx | 31 +- .../common/table-row/viewmodel/protocols.ts | 2 +- .../common/table-row/viewmodel/tableRowVM.ts | 8 +- .../application/core/create-user/index.tsx | 2 +- .../core/create-user/infra/CreateUser.tsx | 6 +- .../core/create-user/view/CreateUserView.tsx | 36 +- .../application/core/places-list/index.tsx | 2 +- .../core/places-list/infra/PlacesList.tsx | 15 +- .../core/places-list/infra/protocols.ts | 4 +- .../core/places-list/view/PlacesListView.tsx | 125 +++--- .../core/places-list/view/protocols.ts | 2 +- .../places-list/viewmodel/placesListVM.ts | 8 +- .../core/places-list/viewmodel/protocols.ts | 5 +- .../application/core/users-list/index.tsx | 2 +- .../core/users-list/infra/UsersList.tsx | 15 +- .../core/users-list/infra/protocols.ts | 4 +- .../core/users-list/view/UsersListView.tsx | 100 +++-- .../core/users-list/view/protocols.ts | 2 +- .../core/users-list/viewmodel/protocols.ts | 5 +- .../core/users-list/viewmodel/usersListVM.ts | 8 +- .../application/support/sidebar/index.tsx | 2 +- .../support/sidebar/view/Sidebar.tsx | 48 ++- src/driving/main/App.tsx | 6 +- src/driving/main/Router/Router.tsx | 14 +- src/driving/main/index.tsx | 12 +- src/driving/main/pages/CreateUser.tsx | 15 +- src/driving/main/pages/index.tsx | 37 +- .../main/pages/layouts/MainPageLayout.tsx | 14 +- tsconfig.json | 3 +- vite.config.ts | 40 +- yarn.lock | 363 ++++++++++++------ 67 files changed, 915 insertions(+), 464 deletions(-) create mode 100644 .babelrc create mode 100644 .eslintignore create mode 100644 .eslintrc.json create mode 100755 .husky/pre-push create mode 100644 prettierrc.json create mode 100644 src/business-logic/core/places/common/entity/placeEntity.ts create mode 100644 src/business-logic/core/places/get-places/data/repository/IGetPlacesRepo.ts create mode 100644 src/business-logic/core/places/get-places/data/response-object/getPlacesRO.ts create mode 100644 src/business-logic/core/places/get-places/data/response-object/protocols.ts create mode 100644 src/business-logic/core/places/get-places/usecase/__test__/getPlacesUsecase.test.ts create mode 100644 src/business-logic/core/places/get-places/usecase/getPlaceUsecase.ts diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..48667da --- /dev/null +++ b/.babelrc @@ -0,0 +1,17 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "node": "current", + }, + }, + ], + ["@babel/preset-react", { + "runtime": "automatic" + }], + "@babel/preset-typescript" + ], + "plugins": ["babel-plugin-transform-import-meta"] +} diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..e0b8844 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,11 @@ +/node_modules +/public +/dist +vite.config.ts +.eslintrc.js +/build +/src/vite-env.d.ts +tailwind.config.cjs +postcss.config.cjs +fileMock.js +jest.config.js \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..948d1e3 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,81 @@ +{ + "env": { + "browser": true, + "es2021": true + }, + "settings": { + "react": { + "version": "detect" + }, + "import/resolver": { + "alias": { + "map": [["~", "./src"]], + "extensions": [".js",".ts",".tsx", ".d.ts", ".json"] + } + } + }, + "extends": [ + "airbnb", + "eslint:recommended", + "plugin:react/recommended", + "plugin:react/recommended", + "plugin:jest/recommended", + "plugin:prettier/recommended", + "plugin:@typescript-eslint/recommended" + ], + "overrides": [], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": ["react", "@typescript-eslint", "jest", "prettier"], + "rules": { + "object-curly-spacing": ["error", "always"], + "import/extensions": [ + "error", + "ignorePackages", + { + "js": "never", + "jsx": "never", + "ts": "never", + "tsx": "never" + } + ], + "import/no-extraneous-dependencies": ["error", { "devDependencies": true }], + "class-methods-use-this": "off", + "import/no-import-module-exports": "off", + "react/require-default-props": "off", + "import/prefer-default-export": "off", + "jsx-a11y/click-events-have-key-events": "off", + "jsx-a11y/no-static-element-interactions": "off", + "@typescript-eslint/no-unused-vars": "error", + "@typescript-eslint/no-shadow": "error", + "no-shadow": "off", + "no-return-await": "off", + "import/order": [ + "error", + { + "pathGroups": [ + { + "pattern": "~/**", + "group": "external" + } + ] + } + ], + "prettier/prettier": [ + "error", + {}, + { + "usePrettierrc": true, + "endOfLine": "auto" + } + ], + "jest/valid-title": "off", + "react/button-has-type": "off", + "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx", ".ts", ".tsx"] }], + "react/react-in-jsx-scope": "off", + "@typescript-eslint/no-namespace": "off" + } +} diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 0000000..fdc2655 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npm run test && npm run lint +npm run test && npm run lint diff --git a/jest.config.js b/jest.config.js index ee178f8..e84dfbe 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,5 +8,7 @@ export default { "\\.(css|less)$": "identity-obj-proxy", "^~(.*)$": "/src$1" }, - transformIgnorePatterns: ['/node_modules/'], + transformIgnorePatterns: [ + "node_modules/(?!(spacetime)/)" + ] } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 39ae599..78b9b10 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7704,6 +7704,14 @@ "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", "dev": true }, + "swr": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/swr/-/swr-2.1.5.tgz", + "integrity": "sha512-/OhfZMcEpuz77KavXST5q6XE9nrOBOVcBLWjMT+oAE/kQHyE3PASrevXCtQDZ8aamntOfFkbVJp7Il9tNBQWrw==", + "requires": { + "use-sync-external-store": "^1.2.0" + } + }, "symbol-tree": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", diff --git a/package.json b/package.json index 0dd2f09..223f7a6 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "tsc && vite build", "preview": "vite preview", "lint": "eslint --fix --ignore-path .eslintignore --ignore-pattern \"!**/.*\" .", - "prepare": "husky install", + "prepare": "husky install && husky add .husky/pre-push \"npm run test && npm run lint\"", "test": "jest", "tsc": "tsc" }, @@ -18,16 +18,17 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-redux": "^8.0.5", - "react-router-dom": "^6.9.0" + "react-router-dom": "^6.9.0", + "swr": "^2.1.5" }, "devDependencies": { - "@babel/preset-env": "^7.20.2", + "@babel/preset-env": "^7.21.5", "@babel/preset-react": "^7.18.6", - "@babel/preset-typescript": "^7.21.0", + "@babel/preset-typescript": "^7.21.5", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^14.0.0", "@testing-library/user-event": "^14.4.3", - "@types/jest": "^29.4.0", + "@types/jest": "^29.5.1", "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10", "@typescript-eslint/eslint-plugin": "^5.54.1", diff --git a/prettierrc.json b/prettierrc.json new file mode 100644 index 0000000..e54d85c --- /dev/null +++ b/prettierrc.json @@ -0,0 +1,13 @@ +{ + "printWidth": 120, + "tabWidth": 2, + "endOfLine":"auto", + "useTabs": false, + "semi": true, + "singleQuote": true, + "quoteProps": "as-needed", + "jsxSingleQuote": true, + "trailingComma": "all", + "bracketSpacing": true, + "arrowParens": "always" +} diff --git a/setupTests.ts b/setupTests.ts index 7b0828b..d0de870 100644 --- a/setupTests.ts +++ b/setupTests.ts @@ -1 +1 @@ -import '@testing-library/jest-dom'; +import "@testing-library/jest-dom"; diff --git a/src/business-logic/core/places/common/entity/placeEntity.ts b/src/business-logic/core/places/common/entity/placeEntity.ts new file mode 100644 index 0000000..6ef34f2 --- /dev/null +++ b/src/business-logic/core/places/common/entity/placeEntity.ts @@ -0,0 +1,4 @@ +type Place = { + placeType: string; + name: string; +}; diff --git a/src/business-logic/core/places/get-places/data/repository/IGetPlacesRepo.ts b/src/business-logic/core/places/get-places/data/repository/IGetPlacesRepo.ts new file mode 100644 index 0000000..a3ce9dd --- /dev/null +++ b/src/business-logic/core/places/get-places/data/repository/IGetPlacesRepo.ts @@ -0,0 +1,5 @@ +import { GetPlacesRO } from "../response-object/protocols"; + +type IGetPlacesRepo = () => Promise; + +export default IGetPlacesRepo; diff --git a/src/business-logic/core/places/get-places/data/response-object/getPlacesRO.ts b/src/business-logic/core/places/get-places/data/response-object/getPlacesRO.ts new file mode 100644 index 0000000..789c56a --- /dev/null +++ b/src/business-logic/core/places/get-places/data/response-object/getPlacesRO.ts @@ -0,0 +1,13 @@ +import { GetPlacesRO, GetPlacesResponse } from "./protocols"; + +const getPlacesRO = (placeResponse: GetPlacesResponse): GetPlacesRO => ({ + id: placeResponse._id, + placeType: placeResponse.place_type, + name: placeResponse.name, + parentId: placeResponse.place_type, + availableServices: placeResponse.available_services, + createdAt: placeResponse.createdAt, + updatedAt: placeResponse.updatedAt, +}) + +export default getPlacesRO; \ No newline at end of file diff --git a/src/business-logic/core/places/get-places/data/response-object/protocols.ts b/src/business-logic/core/places/get-places/data/response-object/protocols.ts new file mode 100644 index 0000000..94da5a9 --- /dev/null +++ b/src/business-logic/core/places/get-places/data/response-object/protocols.ts @@ -0,0 +1,19 @@ +export type GetPlacesResponse = { + _id: string; + place_type: string; + name: string; + parent_id: string | null; + createdAt: string; + updatedAt: string; + available_services: string[]; +}; + +export type GetPlacesRO = { + id: string; + placeType: string; + name: string; + parentId: string | null; + availableServices: string[]; + createdAt: string; + updatedAt: string; +}; diff --git a/src/business-logic/core/places/get-places/usecase/__test__/getPlacesUsecase.test.ts b/src/business-logic/core/places/get-places/usecase/__test__/getPlacesUsecase.test.ts new file mode 100644 index 0000000..3320fb6 --- /dev/null +++ b/src/business-logic/core/places/get-places/usecase/__test__/getPlacesUsecase.test.ts @@ -0,0 +1,25 @@ +import IGetPlacesRepo from "../../data/repository/IGetPlacesRepo"; +import { GetPlacesRO } from "../../data/response-object/protocols"; +import GettingPlacesUsecase from "../getPlaceUsecase"; + +const mockedRO: GetPlacesRO = { + availableServices: [""], + createdAt: "createdAt", + id: "id", + name: "name", + parentId: null, + placeType: "continent", + updatedAt: "updatedTime", +}; +const mockedRepo: IGetPlacesRepo = jest + .fn() + .mockImplementation(async () => mockedRO); + +describe("getting places usecase tests", () => { + it("call repository on execute usecase", async () => { + const usecase = new GettingPlacesUsecase(mockedRepo); + await usecase.execute(); + + expect(mockedRepo).toHaveBeenCalledTimes(1); + }); +}); diff --git a/src/business-logic/core/places/get-places/usecase/getPlaceUsecase.ts b/src/business-logic/core/places/get-places/usecase/getPlaceUsecase.ts new file mode 100644 index 0000000..f2e2daf --- /dev/null +++ b/src/business-logic/core/places/get-places/usecase/getPlaceUsecase.ts @@ -0,0 +1,19 @@ +import IGetPlacesRepo from "../data/repository/IGetPlacesRepo"; +import { GetPlacesRO } from "../data/response-object/protocols"; + +/** + * this usecase is responsible for calling the repo and returning the places data from the repository + */ +class GettingPlacesUsecase { + private repository: IGetPlacesRepo; + + constructor(repository: IGetPlacesRepo) { + this.repository = repository; + } + + async execute(): Promise { + // call usecase and return the repo + } +} + +export default GettingPlacesUsecase; diff --git a/src/driven/boundaries/http-boundary/httpBoundary.ts b/src/driven/boundaries/http-boundary/httpBoundary.ts index f5f5ef5..6fc8f95 100644 --- a/src/driven/boundaries/http-boundary/httpBoundary.ts +++ b/src/driven/boundaries/http-boundary/httpBoundary.ts @@ -1,8 +1,15 @@ -import axios, { AxiosRequestConfig } from 'axios'; -import { staticMessages } from '~/driven/utils/constants/staticMessages'; +import axios, { AxiosRequestConfig } from "axios"; +import { staticMessages } from "~/driven/utils/constants/staticMessages"; export class HTTPBoundary { - async request(options: AxiosRequestConfig) { + async request(customOptions: AxiosRequestConfig) { + const options: AxiosRequestConfig = { + ...customOptions, + headers: { + ...customOptions.headers, + Authorization: `Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICI4NXh0WnA5eThxVDBXVDkwUFpuUkRja3N4LWw0clVyM0tHQW5JSU9DckJNIn0.eyJleHAiOjE2ODQ1NzUyNDksImlhdCI6MTY4NDQ4ODg0OSwianRpIjoiYjI3MDUwMzYtMzMwZi00MTRkLWE2Y2QtNWRiYWUzOTRkMjczIiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwL3JlYWxtcy9kaXBhbF9kZXYiLCJhdWQiOiJhY2NvdW50Iiwic3ViIjoiY2RmYzY3YzQtZGJkOC00NGVhLWI0OWEtYjQ3MjZhMzNmOTAxIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiY29tZm9ydGVjaCIsInNlc3Npb25fc3RhdGUiOiJmMzBhYzJlOS04ZTAxLTQxYjItYmI2OS0yYmMyNGEwOGRjNGUiLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsiZGVmYXVsdC1yb2xlcy1tYXN0ZXIiLCJvZmZsaW5lX2FjY2VzcyIsInVtYV9hdXRob3JpemF0aW9uIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnsiY29tZm9ydGVjaCI6eyJyb2xlcyI6WyJ1c2VyIiwib3BlcmF0b3IiXX0sImFjY291bnQiOnsicm9sZXMiOlsibWFuYWdlLWFjY291bnQiLCJtYW5hZ2UtYWNjb3VudC1saW5rcyIsInZpZXctcHJvZmlsZSJdfX0sInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsInNpZCI6ImYzMGFjMmU5LThlMDEtNDFiMi1iYjY5LTJiYzI0YTA4ZGM0ZSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwicHJlZmVycmVkX3VzZXJuYW1lIjoiKzc3Nzc3Nzc3Nzc3In0.tzM7W8szzcN1AK3XOtgUCGbHkmWd4bnqr-jvcwBICtNbl5Dty8RxK_ONFp6g5X8wI0pVPKx4qLvWkE7jXQcg1XDZW_H1V-ucZZ_a9POffDRZ5xSNcREnjfKhw3gvjK9YSSBeMf08abDexbVSJW4rbPxtmcO9WGdZN8C1k7O-_9VHz-3NBCq7vRYBNID--xVTga_MMv3mCORzHtUdx2D7B2d7YxBAjQs5x9JCl_eXuN_IHODc2HMww-s5akquzdEKGFSfASu30NpNZucbO9XyTMkAWuV-H9Xd73eq5o-tSd0jMOfY9G1it9xLAM2Gk4xmIuUA16aLnjY7_rmm3rOypw`, + }, + }; const response = await axios(options); if (!response) throw new Error(staticMessages.service.errors[500]); diff --git a/src/driven/boundaries/router-boundary/index.tsx b/src/driven/boundaries/router-boundary/index.tsx index 8729e43..38d83c3 100644 --- a/src/driven/boundaries/router-boundary/index.tsx +++ b/src/driven/boundaries/router-boundary/index.tsx @@ -1,4 +1,9 @@ -import { NavigateFunction, Outlet, useLocation, useNavigate } from 'react-router-dom'; +import { + NavigateFunction, + Outlet, + useLocation, + useNavigate, +} from "react-router-dom"; class RouterBoundary { outletRoute = () => ; diff --git a/src/driven/boundaries/state-management-boundary/adapters/adapter.ts b/src/driven/boundaries/state-management-boundary/adapters/adapter.ts index 354c92b..3102e3f 100644 --- a/src/driven/boundaries/state-management-boundary/adapters/adapter.ts +++ b/src/driven/boundaries/state-management-boundary/adapters/adapter.ts @@ -1,6 +1,6 @@ -import store from '../store/store'; -import userSlice from '../slices/userSlice'; -import { UserState } from '../slices/protocols/userSliceProtocols'; +import store from "../store/store"; +import userSlice from "../slices/userSlice"; +import { UserState } from "../slices/protocols/userSliceProtocols"; export const userAdapter = { get: store.getState().user, diff --git a/src/driven/boundaries/state-management-boundary/index.ts b/src/driven/boundaries/state-management-boundary/index.ts index e1751e0..8399f94 100644 --- a/src/driven/boundaries/state-management-boundary/index.ts +++ b/src/driven/boundaries/state-management-boundary/index.ts @@ -1 +1 @@ -export { userAdapter } from './adapters/adapter'; +export { userAdapter } from "./adapters/adapter"; diff --git a/src/driven/boundaries/state-management-boundary/slices/protocols/userSliceProtocols.ts b/src/driven/boundaries/state-management-boundary/slices/protocols/userSliceProtocols.ts index 583c7f0..b5710df 100644 --- a/src/driven/boundaries/state-management-boundary/slices/protocols/userSliceProtocols.ts +++ b/src/driven/boundaries/state-management-boundary/slices/protocols/userSliceProtocols.ts @@ -1,3 +1,3 @@ -import { UserModel } from '~/business-logic/generic/user/common/domain/model/userModel'; +import { UserModel } from "~/business-logic/generic/user/common/domain/model/userModel"; export type UserState = UserModel; diff --git a/src/driven/boundaries/state-management-boundary/slices/userSlice.ts b/src/driven/boundaries/state-management-boundary/slices/userSlice.ts index 0f0d37d..469f00a 100644 --- a/src/driven/boundaries/state-management-boundary/slices/userSlice.ts +++ b/src/driven/boundaries/state-management-boundary/slices/userSlice.ts @@ -1,7 +1,7 @@ -import { createSlice, SliceCaseReducers } from '@reduxjs/toolkit'; -import { UserState } from './protocols/userSliceProtocols'; +import { createSlice, SliceCaseReducers } from "@reduxjs/toolkit"; +import { UserState } from "./protocols/userSliceProtocols"; -export const userStateName = 'user'; +export const userStateName = "user"; const userSlice = createSlice>({ name: userStateName, initialState: null, diff --git a/src/driven/boundaries/state-management-boundary/store/store.ts b/src/driven/boundaries/state-management-boundary/store/store.ts index ccf0b9c..f2e58e1 100644 --- a/src/driven/boundaries/state-management-boundary/store/store.ts +++ b/src/driven/boundaries/state-management-boundary/store/store.ts @@ -1,5 +1,5 @@ -import { combineReducers, configureStore } from '@reduxjs/toolkit'; -import userSlice, { userStateName } from '../slices/userSlice'; +import { combineReducers, configureStore } from "@reduxjs/toolkit"; +import userSlice, { userStateName } from "../slices/userSlice"; const combinedReducers = combineReducers({ [userStateName]: userSlice.reducer, diff --git a/src/driven/utils/components/buttons/primary-button/PrimaryButton.tsx b/src/driven/utils/components/buttons/primary-button/PrimaryButton.tsx index 967f21f..ffbbd51 100644 --- a/src/driven/utils/components/buttons/primary-button/PrimaryButton.tsx +++ b/src/driven/utils/components/buttons/primary-button/PrimaryButton.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React from "react"; interface IPrimaryButtonProps { title: string; @@ -9,6 +9,11 @@ interface IPrimaryButtonProps { export default function PrimaryButton(props: IPrimaryButtonProps) { const { onClick, title, className } = props; return ( - - ) + + ); } diff --git a/src/driven/utils/components/inputs/simple-input/SimpleInput.tsx b/src/driven/utils/components/inputs/simple-input/SimpleInput.tsx index 4fd7158..d3fe063 100644 --- a/src/driven/utils/components/inputs/simple-input/SimpleInput.tsx +++ b/src/driven/utils/components/inputs/simple-input/SimpleInput.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React from "react"; interface ISimpleInput { title: string; @@ -9,8 +9,13 @@ export default function SimpleInput(props: ISimpleInput) { const { title, className } = props; return (
- - + +
- ) + ); } diff --git a/src/driven/utils/components/page-title/pageTitle.tsx b/src/driven/utils/components/page-title/pageTitle.tsx index ca0f4d1..0126652 100644 --- a/src/driven/utils/components/page-title/pageTitle.tsx +++ b/src/driven/utils/components/page-title/pageTitle.tsx @@ -1,13 +1,17 @@ -import React from 'react' +import React from "react"; interface IPageTitleProps { - title: string; - className?: string; + title: string; + className?: string; } export default function PageTitle(props: IPageTitleProps) { - const { title, className } = props; + const { title, className } = props; return ( -
{title}
- ) +
+ {title} +
+ ); } diff --git a/src/driven/utils/configs/appConfig.ts b/src/driven/utils/configs/appConfig.ts index dac6474..bd0bc21 100644 --- a/src/driven/utils/configs/appConfig.ts +++ b/src/driven/utils/configs/appConfig.ts @@ -4,24 +4,22 @@ import { staticMessages } from "../constants/staticMessages"; export const appConfig = {}; export const routes = { - usersList: '/', - createUser: '/create-user' + usersList: "/", + createUser: "/create-user", }; export const routesData = { usersList: { path: routes.usersList, icon: icons.users, - title: staticMessages.global.users + title: staticMessages.global.users, }, createUser: { path: routes.createUser, icon: icons.createUser, - title: staticMessages.global.createUser - } -} + title: staticMessages.global.createUser, + }, +}; const baseApiUrl = import.meta.env.BASE_API_URL; -export const apiUrls = { - -}; +export const apiUrls = {}; diff --git a/src/driven/utils/constants/assertUrls.ts b/src/driven/utils/constants/assertUrls.ts index 0e1fdfa..aea74c8 100644 --- a/src/driven/utils/constants/assertUrls.ts +++ b/src/driven/utils/constants/assertUrls.ts @@ -1,7 +1,7 @@ -const baseAssetsUrl = 'assets/'; -const baseIconsUrl = baseAssetsUrl + 'icons/'; +const baseAssetsUrl = "assets/"; +const baseIconsUrl = `${baseAssetsUrl}icons/`; export const icons = { - logo: baseIconsUrl + 'logo.svg', - users: baseIconsUrl + 'users.svg', - createUser: baseIconsUrl + 'createuser.svg' -} \ No newline at end of file + logo: `${baseIconsUrl}logo.svg`, + users: `${baseIconsUrl}users.svg`, + createUser: `${baseIconsUrl}createuser.svg`, +}; diff --git a/src/driven/utils/constants/staticMessages.ts b/src/driven/utils/constants/staticMessages.ts index 4641f23..6dd125d 100644 --- a/src/driven/utils/constants/staticMessages.ts +++ b/src/driven/utils/constants/staticMessages.ts @@ -1,24 +1,24 @@ export const staticMessages = { global: { errors: { - input: 'please fill all inputs correctly', + input: "please fill all inputs correctly", }, - users: 'Users', - submit: 'Submit', - fistname: 'Firstname', - lastname: 'Lastname', - place_id: 'Place id', - title: 'title', - status: 'Status', - address: 'Address', - qrCode: 'qrCode', - createUser: 'Create user', - phoneNumber: 'Phone Number' + users: "Users", + submit: "Submit", + fistname: "Firstname", + lastname: "Lastname", + place_id: "Place id", + title: "title", + status: "Status", + address: "Address", + qrCode: "qrCode", + createUser: "Create user", + phoneNumber: "Phone Number", }, service: { errors: { - 500: 'server not respond please try again later!', - 401: 'Authentication error!', + 500: "server not respond please try again later!", + 401: "Authentication error!", }, }, }; diff --git a/src/driven/utils/helpers/globalHelpers.ts b/src/driven/utils/helpers/globalHelpers.ts index cfbe1e1..afe81f4 100644 --- a/src/driven/utils/helpers/globalHelpers.ts +++ b/src/driven/utils/helpers/globalHelpers.ts @@ -1,4 +1,7 @@ -import { errorHandlingStateTypes, UIErrorHandling } from './protocols/globalHelpersProtocols'; +import { + errorHandlingStateTypes, + UIErrorHandling, +} from "./protocols/globalHelpersProtocols"; export const UIErrorHandlingFactory = ({ state, diff --git a/src/driven/utils/helpers/protocols/globalHelpersProtocols.ts b/src/driven/utils/helpers/protocols/globalHelpersProtocols.ts index 390c86e..1143fd0 100644 --- a/src/driven/utils/helpers/protocols/globalHelpersProtocols.ts +++ b/src/driven/utils/helpers/protocols/globalHelpersProtocols.ts @@ -1,7 +1,7 @@ export enum errorHandlingStateTypes { - error = 'error', - warning = 'warning', - success = 'success', + error = "error", + warning = "warning", + success = "success", } export type UIErrorHandling = { diff --git a/src/driven/utils/protocols/serviceProtocols.ts b/src/driven/utils/protocols/serviceProtocols.ts index 3e7fd0b..c629366 100644 --- a/src/driven/utils/protocols/serviceProtocols.ts +++ b/src/driven/utils/protocols/serviceProtocols.ts @@ -1,9 +1,9 @@ -export type RequestMethods = 'get' | 'post' | 'put' | 'delete'; +export type RequestMethods = "get" | "post" | "put" | "delete"; export type apiGlobalResponseObject = { - type: 'Success' | 'client Error' | string; + type: "Success" | "client Error" | string; status: 200 | 400 | 401 | 500 | number; message: string; description: string; data: DataType; -} \ No newline at end of file +}; diff --git a/src/driving/application/core/common/table-row/index.tsx b/src/driving/application/core/common/table-row/index.tsx index e31ec56..5c44efc 100644 --- a/src/driving/application/core/common/table-row/index.tsx +++ b/src/driving/application/core/common/table-row/index.tsx @@ -1,3 +1,3 @@ import TableRow from "./infra/TableRowInfra"; -export default TableRow; \ No newline at end of file +export default TableRow; diff --git a/src/driving/application/core/common/table-row/infra/TableRowInfra.tsx b/src/driving/application/core/common/table-row/infra/TableRowInfra.tsx index cc375cb..b40752e 100644 --- a/src/driving/application/core/common/table-row/infra/TableRowInfra.tsx +++ b/src/driving/application/core/common/table-row/infra/TableRowInfra.tsx @@ -1,13 +1,19 @@ -import React from 'react' -import { ITableRowInfra } from './protocols' -import useTableRowVM from '../viewmodel/tableRowVM'; -import TableRowView from '../view/TableRow'; +import React from "react"; +import useTableRowVM from "../viewmodel/tableRowVM"; +import TableRowView from "../view/TableRow"; +import { ITableRowInfra } from "./protocols"; export default function TableRow(props: ITableRowInfra) { const { rowData, selectedRowId, setSelectedRowId } = props; const { rowId } = rowData; - const { isRowSelected } = useTableRowVM({selectedRowId, rowId}); + const { isRowSelected } = useTableRowVM({ selectedRowId, rowId }); - return + return ( + + ); } diff --git a/src/driving/application/core/common/table-row/infra/protocols.ts b/src/driving/application/core/common/table-row/infra/protocols.ts index 7f47ab5..a4c9a07 100644 --- a/src/driving/application/core/common/table-row/infra/protocols.ts +++ b/src/driving/application/core/common/table-row/infra/protocols.ts @@ -3,6 +3,6 @@ export interface ITableRowInfra { rowData: { rowItemsTitle: string[]; rowId: string; - } - setSelectedRowId: React.Dispatch> -} \ No newline at end of file + }; + setSelectedRowId: React.Dispatch>; +} diff --git a/src/driving/application/core/common/table-row/view/TableRow.tsx b/src/driving/application/core/common/table-row/view/TableRow.tsx index b84f925..78c4bca 100644 --- a/src/driving/application/core/common/table-row/view/TableRow.tsx +++ b/src/driving/application/core/common/table-row/view/TableRow.tsx @@ -1,15 +1,20 @@ -import React from 'react' -import RowItem from './table-row-item/view/RowItem'; -import { ITableRowProps } from './protocols'; +import React from "react"; +import RowItem from "./table-row-item/view/RowItem"; +import { ITableRowProps } from "./protocols"; export default function TableRowView(props: ITableRowProps) { const { isSelected, setSelectedRowId, rowData } = props; const { rowId, rowItemsTitle } = rowData; const columns = rowItemsTitle.map((rowItemTitle, index) => { - return - }) + return ( + + ); + }); - return ( - setSelectedRowId(rowId)}>{ columns } - ) + return setSelectedRowId(rowId)}>{columns}; } diff --git a/src/driving/application/core/common/table-row/view/protocols.ts b/src/driving/application/core/common/table-row/view/protocols.ts index db7d5dc..b619d17 100644 --- a/src/driving/application/core/common/table-row/view/protocols.ts +++ b/src/driving/application/core/common/table-row/view/protocols.ts @@ -3,6 +3,6 @@ export interface ITableRowProps { rowData: { rowItemsTitle: string[]; rowId: string; - } - setSelectedRowId: React.Dispatch> -} \ No newline at end of file + }; + setSelectedRowId: React.Dispatch>; +} diff --git a/src/driving/application/core/common/table-row/view/table-row-item/view/RowItem.tsx b/src/driving/application/core/common/table-row/view/table-row-item/view/RowItem.tsx index 3a98103..4d9176f 100644 --- a/src/driving/application/core/common/table-row/view/table-row-item/view/RowItem.tsx +++ b/src/driving/application/core/common/table-row/view/table-row-item/view/RowItem.tsx @@ -1,24 +1,31 @@ -import React, { useState } from 'react' +import React, { useState } from "react"; interface IRowItemProp { title: string; hasCheckbox: boolean; - isSelected: boolean; + isSelected: boolean; } export default function RowItem(props: IRowItemProp) { const { title, hasCheckbox, isSelected } = props; return ( - -
- { - hasCheckbox && - - - - } - { title } + +
+ {hasCheckbox && ( + + + ✓ + + + )} + {title}
- ) + ); } diff --git a/src/driving/application/core/common/table-row/viewmodel/protocols.ts b/src/driving/application/core/common/table-row/viewmodel/protocols.ts index ac8d8f2..a989642 100644 --- a/src/driving/application/core/common/table-row/viewmodel/protocols.ts +++ b/src/driving/application/core/common/table-row/viewmodel/protocols.ts @@ -5,4 +5,4 @@ export interface IUserTableRowVM { export type tableRowVMReturnType = { isRowSelected: boolean; -} +}; diff --git a/src/driving/application/core/common/table-row/viewmodel/tableRowVM.ts b/src/driving/application/core/common/table-row/viewmodel/tableRowVM.ts index 340c23b..34677ae 100644 --- a/src/driving/application/core/common/table-row/viewmodel/tableRowVM.ts +++ b/src/driving/application/core/common/table-row/viewmodel/tableRowVM.ts @@ -3,8 +3,8 @@ import { IUserTableRowVM, tableRowVMReturnType } from "./protocols"; const useTableRowVM = (dependencies: IUserTableRowVM): tableRowVMReturnType => { const { rowId, selectedRowId } = dependencies; return { - isRowSelected: rowId === selectedRowId - } -} + isRowSelected: rowId === selectedRowId, + }; +}; -export default useTableRowVM; \ No newline at end of file +export default useTableRowVM; diff --git a/src/driving/application/core/create-user/index.tsx b/src/driving/application/core/create-user/index.tsx index 1f35bc6..47823ac 100644 --- a/src/driving/application/core/create-user/index.tsx +++ b/src/driving/application/core/create-user/index.tsx @@ -1,3 +1,3 @@ import CreateUser from "./infra/CreateUser"; -export default CreateUser; \ No newline at end of file +export default CreateUser; diff --git a/src/driving/application/core/create-user/infra/CreateUser.tsx b/src/driving/application/core/create-user/infra/CreateUser.tsx index efb07df..eb7966c 100644 --- a/src/driving/application/core/create-user/infra/CreateUser.tsx +++ b/src/driving/application/core/create-user/infra/CreateUser.tsx @@ -1,6 +1,6 @@ -import React from 'react' -import CreateUserView from '../view/CreateUserView' +import React from "react"; +import CreateUserView from "../view/CreateUserView"; export default function CreateUser() { - return + return ; } diff --git a/src/driving/application/core/create-user/view/CreateUserView.tsx b/src/driving/application/core/create-user/view/CreateUserView.tsx index c80ba27..202e28a 100644 --- a/src/driving/application/core/create-user/view/CreateUserView.tsx +++ b/src/driving/application/core/create-user/view/CreateUserView.tsx @@ -1,19 +1,31 @@ -import React from 'react' -import PrimaryButton from '~/driven/utils/components/buttons/primary-button/PrimaryButton' -import SimpleInput from '~/driven/utils/components/inputs/simple-input/SimpleInput' -import { staticMessages } from '~/driven/utils/constants/staticMessages' +import React from "react"; +import PrimaryButton from "~/driven/utils/components/buttons/primary-button/PrimaryButton"; +import SimpleInput from "~/driven/utils/components/inputs/simple-input/SimpleInput"; +import { staticMessages } from "~/driven/utils/constants/staticMessages"; export default function CreateUserView() { return ( -
-
- - - +
+
+ + +
-
- {}} title={staticMessages.global.submit} /> +
+ {}} + title={staticMessages.global.submit} + />
- ) + ); } diff --git a/src/driving/application/core/places-list/index.tsx b/src/driving/application/core/places-list/index.tsx index 2834742..43082d5 100644 --- a/src/driving/application/core/places-list/index.tsx +++ b/src/driving/application/core/places-list/index.tsx @@ -1,3 +1,3 @@ import PlacesList from "./infra/PlacesList"; -export default PlacesList; \ No newline at end of file +export default PlacesList; diff --git a/src/driving/application/core/places-list/infra/PlacesList.tsx b/src/driving/application/core/places-list/infra/PlacesList.tsx index 6ec5cf6..b586eb0 100644 --- a/src/driving/application/core/places-list/infra/PlacesList.tsx +++ b/src/driving/application/core/places-list/infra/PlacesList.tsx @@ -1,8 +1,13 @@ -import React from 'react' -import PlacesListView from '../view/PlacesListView' -import usePlacesListVM from '../viewmodel/placesListVM' +import React from "react"; +import PlacesListView from "../view/PlacesListView"; +import usePlacesListVM from "../viewmodel/placesListVM"; export default function PlacessList() { - const { selectedRowId, setSelectedRowId } = usePlacesListVM() - return + const { selectedRowId, setSelectedRowId } = usePlacesListVM(); + return ( + + ); } diff --git a/src/driving/application/core/places-list/infra/protocols.ts b/src/driving/application/core/places-list/infra/protocols.ts index 6abdb94..3e5b02a 100644 --- a/src/driving/application/core/places-list/infra/protocols.ts +++ b/src/driving/application/core/places-list/infra/protocols.ts @@ -1,3 +1 @@ -export interface IPlacesListInfraProps { - -} \ No newline at end of file +export interface IPlacesListInfraProps {} diff --git a/src/driving/application/core/places-list/view/PlacesListView.tsx b/src/driving/application/core/places-list/view/PlacesListView.tsx index 336da1d..0c4dd83 100644 --- a/src/driving/application/core/places-list/view/PlacesListView.tsx +++ b/src/driving/application/core/places-list/view/PlacesListView.tsx @@ -1,72 +1,71 @@ -import React from 'react' -import RowItem from '../../common/table-row/view/table-row-item/view/RowItem' -import TableRow from '../../common/table-row' -import { IPlacesListProps } from './protocols' -import { staticMessages } from '~/driven/utils/constants/staticMessages'; - +import React from "react"; +import { staticMessages } from "~/driven/utils/constants/staticMessages"; +import RowItem from "../../common/table-row/view/table-row-item/view/RowItem"; +import TableRow from "../../common/table-row"; +import { IPlacesListProps } from "./protocols"; export default function UsersListView(props: IPlacesListProps) { - const { selectedRowId, setSelectedRowId } = props; + const { selectedRowId, setSelectedRowId } = props; - const rows = () => { - const placesdata = [ - { - id: '1', - place_id: '6440020b89366fdcaf15a8c2', - title: 'flat demoplace ', - status: 'demo', - address: 'demoplace' - }, - { - id: '2', - place_id: '6440020b89366fdcaf15asdfa', - title: 'flat demoplace second ', - status: 'demo second', - address: 'demoplace second' - } - ] + const rows = () => { + const placesdata = [ + { + id: "1", + place_id: "6440020b89366fdcaf15a8c2", + title: "flat demoplace ", + status: "demo", + address: "demoplace", + }, + { + id: "2", + place_id: "6440020b89366fdcaf15asdfa", + title: "flat demoplace second ", + status: "demo second", + address: "demoplace second", + }, + ]; - const rowData = { - rowItemsTitle: placesdata.map(places => { - return [ - places.id, - places.title, - places.status, - places.address, - ] - }), - rowId: placesdata[0].id - } + const rowData = { + rowItemsTitle: placesdata.map((places) => { + return [places.id, places.title, places.status, places.address]; + }), + rowId: placesdata[0].id, + }; - return placesdata.map(places => { - const rowData = { - rowItemsTitle: [ - places.id, - places.title, - places.status, - places.address, - '' - ], - rowId: places.id, - } - return - }) - } + return placesdata.map((places) => { + const rowData = { + rowItemsTitle: [ + places.id, + places.title, + places.status, + places.address, + "", + ], + rowId: places.id, + }; + return ( + + ); + }); + }; return ( - - - - - - - - - - - - { rows() } - +
{staticMessages.global.place_id}{staticMessages.global.title}{staticMessages.global.status}{staticMessages.global.address}{staticMessages.global.qrCode}
+ + + + + + + + + + {rows()}
{staticMessages.global.place_id}{staticMessages.global.title}{staticMessages.global.status}{staticMessages.global.address}{staticMessages.global.qrCode}
- ) + ); } diff --git a/src/driving/application/core/places-list/view/protocols.ts b/src/driving/application/core/places-list/view/protocols.ts index 90a210f..d4b4e7f 100644 --- a/src/driving/application/core/places-list/view/protocols.ts +++ b/src/driving/application/core/places-list/view/protocols.ts @@ -1,4 +1,4 @@ export interface IPlacesListProps { selectedRowId: string; setSelectedRowId: React.Dispatch>; -} \ No newline at end of file +} diff --git a/src/driving/application/core/places-list/viewmodel/placesListVM.ts b/src/driving/application/core/places-list/viewmodel/placesListVM.ts index 9c197f8..391d5f6 100644 --- a/src/driving/application/core/places-list/viewmodel/placesListVM.ts +++ b/src/driving/application/core/places-list/viewmodel/placesListVM.ts @@ -2,12 +2,12 @@ import { useState } from "react"; import { placesListReturnType } from "./protocols"; const usePlacesListVM = (): placesListReturnType => { - const [ selectedRowId, setSelectedRowId ] = useState(''); + const [selectedRowId, setSelectedRowId] = useState(""); return { selectedRowId, setSelectedRowId, - } -} + }; +}; -export default usePlacesListVM; \ No newline at end of file +export default usePlacesListVM; diff --git a/src/driving/application/core/places-list/viewmodel/protocols.ts b/src/driving/application/core/places-list/viewmodel/protocols.ts index a84f296..4b09fe7 100644 --- a/src/driving/application/core/places-list/viewmodel/protocols.ts +++ b/src/driving/application/core/places-list/viewmodel/protocols.ts @@ -1,9 +1,8 @@ import React from "react"; -export interface IPlacesListVM { -} +export interface IPlacesListVM {} export type placesListReturnType = { selectedRowId: string; setSelectedRowId: React.Dispatch>; -} \ No newline at end of file +}; diff --git a/src/driving/application/core/users-list/index.tsx b/src/driving/application/core/users-list/index.tsx index b029efe..74d8163 100644 --- a/src/driving/application/core/users-list/index.tsx +++ b/src/driving/application/core/users-list/index.tsx @@ -1,3 +1,3 @@ import UsersList from "./infra/UsersList"; -export default UsersList; \ No newline at end of file +export default UsersList; diff --git a/src/driving/application/core/users-list/infra/UsersList.tsx b/src/driving/application/core/users-list/infra/UsersList.tsx index 505975d..01eb05b 100644 --- a/src/driving/application/core/users-list/infra/UsersList.tsx +++ b/src/driving/application/core/users-list/infra/UsersList.tsx @@ -1,8 +1,13 @@ -import React from 'react' -import useUsersListVM from '../viewmodel/usersListVM' -import UsersListView from '../view/UsersListView' +import React from "react"; +import useUsersListVM from "../viewmodel/usersListVM"; +import UsersListView from "../view/UsersListView"; export default function UsersList() { - const { selectedRowId, setSelectedRowId } = useUsersListVM() - return + const { selectedRowId, setSelectedRowId } = useUsersListVM(); + return ( + + ); } diff --git a/src/driving/application/core/users-list/infra/protocols.ts b/src/driving/application/core/users-list/infra/protocols.ts index 88b4866..d59a83d 100644 --- a/src/driving/application/core/users-list/infra/protocols.ts +++ b/src/driving/application/core/users-list/infra/protocols.ts @@ -1,3 +1 @@ -export interface IUsersListInfraProps { - -} \ No newline at end of file +export interface IUsersListInfraProps {} diff --git a/src/driving/application/core/users-list/view/UsersListView.tsx b/src/driving/application/core/users-list/view/UsersListView.tsx index ad8bb9c..f4360ec 100644 --- a/src/driving/application/core/users-list/view/UsersListView.tsx +++ b/src/driving/application/core/users-list/view/UsersListView.tsx @@ -1,60 +1,58 @@ -import React from 'react' -import RowItem from '../../common/table-row/view/table-row-item/view/RowItem' -import TableRow from '../../common/table-row' -import { IUserListProps } from './protocols' -import { staticMessages } from '~/driven/utils/constants/staticMessages'; - +import React from "react"; +import { staticMessages } from "~/driven/utils/constants/staticMessages"; +import RowItem from "../../common/table-row/view/table-row-item/view/RowItem"; +import TableRow from "../../common/table-row"; +import { IUserListProps } from "./protocols"; export default function UsersListView(props: IUserListProps) { - const { selectedRowId, setSelectedRowId } = props; + const { selectedRowId, setSelectedRowId } = props; - const rows = () => { - const userdata = [ - { - id: '1', - firstname: 'behnam', - lastname: 'rahimpour' - }, - { - id: '2', - firstname: 'Salar', - lastname: 'Sali' - } - ] + const rows = () => { + const userdata = [ + { + id: "1", + firstname: "behnam", + lastname: "rahimpour", + }, + { + id: "2", + firstname: "Salar", + lastname: "Sali", + }, + ]; - const rowData = { - rowItemsTitle: userdata.map(user => { - return [ - user.firstname, - user.lastname - ] - }), - rowId: userdata[0].id - } + const rowData = { + rowItemsTitle: userdata.map((user) => { + return [user.firstname, user.lastname]; + }), + rowId: userdata[0].id, + }; - return userdata.map(user => { - const rowData = { - rowItemsTitle: [ - user.firstname, - user.lastname - ], - rowId: user.id, - } - return - }) - } + return userdata.map((user) => { + const rowData = { + rowItemsTitle: [user.firstname, user.lastname], + rowId: user.id, + }; + return ( + + ); + }); + }; return ( - - - - - - - - - { rows() } - +
{staticMessages.global.fistname}{staticMessages.global.lastname}
+ + + + + + + {rows()}
{staticMessages.global.fistname}{staticMessages.global.lastname}
- ) + ); } diff --git a/src/driving/application/core/users-list/view/protocols.ts b/src/driving/application/core/users-list/view/protocols.ts index 1690a6c..05e98a1 100644 --- a/src/driving/application/core/users-list/view/protocols.ts +++ b/src/driving/application/core/users-list/view/protocols.ts @@ -1,4 +1,4 @@ export interface IUserListProps { selectedRowId: string; setSelectedRowId: React.Dispatch>; -} \ No newline at end of file +} diff --git a/src/driving/application/core/users-list/viewmodel/protocols.ts b/src/driving/application/core/users-list/viewmodel/protocols.ts index 86df5aa..ca70183 100644 --- a/src/driving/application/core/users-list/viewmodel/protocols.ts +++ b/src/driving/application/core/users-list/viewmodel/protocols.ts @@ -1,9 +1,8 @@ import React from "react"; -export interface IUsersListVM { -} +export interface IUsersListVM {} export type userListReturnType = { selectedRowId: string; setSelectedRowId: React.Dispatch>; -} \ No newline at end of file +}; diff --git a/src/driving/application/core/users-list/viewmodel/usersListVM.ts b/src/driving/application/core/users-list/viewmodel/usersListVM.ts index 6cdbfb8..d411f83 100644 --- a/src/driving/application/core/users-list/viewmodel/usersListVM.ts +++ b/src/driving/application/core/users-list/viewmodel/usersListVM.ts @@ -2,12 +2,12 @@ import { useState } from "react"; import { userListReturnType } from "./protocols"; const useUsersListVM = (): userListReturnType => { - const [ selectedRowId, setSelectedRowId ] = useState(''); + const [selectedRowId, setSelectedRowId] = useState(""); return { selectedRowId, setSelectedRowId, - } -} + }; +}; -export default useUsersListVM; \ No newline at end of file +export default useUsersListVM; diff --git a/src/driving/application/support/sidebar/index.tsx b/src/driving/application/support/sidebar/index.tsx index c6910ce..9bd6051 100644 --- a/src/driving/application/support/sidebar/index.tsx +++ b/src/driving/application/support/sidebar/index.tsx @@ -1,3 +1,3 @@ import Sidebar from "./view/Sidebar"; -export default Sidebar; \ No newline at end of file +export default Sidebar; diff --git a/src/driving/application/support/sidebar/view/Sidebar.tsx b/src/driving/application/support/sidebar/view/Sidebar.tsx index 0af298d..395673f 100644 --- a/src/driving/application/support/sidebar/view/Sidebar.tsx +++ b/src/driving/application/support/sidebar/view/Sidebar.tsx @@ -1,29 +1,35 @@ -import React from 'react' -import { Link, useLocation } from 'react-router-dom' -import { routesData } from '~/driven/utils/configs/appConfig' -import { icons } from '~/driven/utils/constants/assertUrls' +import React from "react"; +import { Link, useLocation } from "react-router-dom"; +import { routesData } from "~/driven/utils/configs/appConfig"; +import { icons } from "~/driven/utils/constants/assertUrls"; export default function Sidebar() { - const isCurrentPage = useLocation() + const isCurrentPage = useLocation(); - const pages = Object.keys(routesData).map(routeKey => { - const key = routeKey as keyof typeof routesData + const pages = Object.keys(routesData).map((routeKey) => { + const key = routeKey as keyof typeof routesData; return ( - - -
{routesData[key].title}
- - ) - }) + + +
{routesData[key].title}
+ + ); + }); return ( - ); } diff --git a/src/driving/main/pages/index.tsx b/src/driving/main/pages/index.tsx index a0baa8e..2d51079 100644 --- a/src/driving/main/pages/index.tsx +++ b/src/driving/main/pages/index.tsx @@ -1,21 +1,73 @@ -import React from 'react'; +import { AxiosError } from 'axios'; +import React, { useState } from 'react'; +import { HTTPPovider } from '~/driven/boundaries/http-boundary/httpBoundary'; +import { HttpOptionsType } from '~/driven/boundaries/http-boundary/protocols'; +import Notification from '~/driven/utils/components/Notification/Notification'; import PrimaryButton from '~/driven/utils/components/buttons/primary-button/PrimaryButton'; import PageTitle from '~/driven/utils/components/page-title/pageTitle'; +import { apiUrls } from '~/driven/utils/configs/appConfig'; import { staticMessages } from '~/driven/utils/constants/staticMessages'; +import useGetNavigatorAndTokenUpdater from '~/driven/utils/helpers/hooks/getNavigatorAndAccessTokenUpdator'; import PlacesList from '~/driving/application/core/places-list'; import UsersList from '~/driving/application/core/users-list'; export default function index() { + const [selectedUserRowId, setSelectedUserRowId] = useState(''); + const [selectedPlaceRowId, setSelectedPlaceRowId] = useState(''); + const { accessTokenUpdateHandler, notLoginAuth, userData } = useGetNavigatorAndTokenUpdater(); + const [error, setError] = useState<{ message: string; type: 'error' | 'success' }>({ message: '', type: 'error' }); + + const onSubmitMember = async (e: React.FormEvent) => { + e.preventDefault(); + try { + const url = apiUrls.core.createMember; + const data = { + place_id: selectedPlaceRowId, + account_id: selectedUserRowId, + }; + + const options: HttpOptionsType = { + url, + data, + headers: { + 'Content-Type': 'application/json', + }, + method: 'POST', + }; + + const userTokens = { + accessToken: userData.user?.adminUserData.accessToken || null, + refreshToken: userData.user?.adminUserData.refreshToken || null, + }; + const httpProvider = new HTTPPovider(userTokens, accessTokenUpdateHandler, notLoginAuth); + + await httpProvider.request(options); + setError({ message: staticMessages.global.success.createMember, type: 'success' }); + } catch (errorExc) { + if (errorExc instanceof AxiosError) { + setError({ message: errorExc.response?.data?.description, type: 'error' }); + } else if (errorExc instanceof Error) { + setError({ message: errorExc.message, type: 'error' }); + } + } + }; return ( <> + {Boolean(error.message) && ( + setError({ message: '', type: 'error' })} + /> + )}
-
+ null} /> -
+
- - + +
diff --git a/src/driving/main/pages/layouts/MainPageLayout.tsx b/src/driving/main/pages/layouts/MainPageLayout.tsx index bc004c9..9447647 100644 --- a/src/driving/main/pages/layouts/MainPageLayout.tsx +++ b/src/driving/main/pages/layouts/MainPageLayout.tsx @@ -11,7 +11,6 @@ import Sidebar from '~/driving/application/support/sidebar'; */ export default function MainPageLayout() { const { user, setUser } = useUser(); - console.log('hi'); useEffect(() => { const storage = StorageService.localStorage(); const currentUser = storage.getData(appConfig.adminUserStorageKey); @@ -22,7 +21,7 @@ export default function MainPageLayout() { return (
-
+
diff --git a/src/driving/main/pages/layouts/UserLoginLayout.tsx b/src/driving/main/pages/layouts/UserLoginLayout.tsx index 33683f2..dfeee28 100644 --- a/src/driving/main/pages/layouts/UserLoginLayout.tsx +++ b/src/driving/main/pages/layouts/UserLoginLayout.tsx @@ -5,7 +5,6 @@ import { useUser } from '~/driven/utils/helpers/contexts/userContext'; export default function UserLoginLayout() { const { user } = useUser(); - console.log('hhhh'); if (user && user.adminUserData.accessToken) return ; return ; } From d9bfa52188658027c18dccd56362fe54bec63d46 Mon Sep 17 00:00:00 2001 From: behnamrhp Date: Tue, 23 May 2023 12:15:15 +0300 Subject: [PATCH 26/26] [FEAT]: add disabled button feature --- .../buttons/primary-button/PrimaryButton.tsx | 4 +++- src/driving/main/pages/index.tsx | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/driven/utils/components/buttons/primary-button/PrimaryButton.tsx b/src/driven/utils/components/buttons/primary-button/PrimaryButton.tsx index e9bf840..d2da017 100644 --- a/src/driven/utils/components/buttons/primary-button/PrimaryButton.tsx +++ b/src/driven/utils/components/buttons/primary-button/PrimaryButton.tsx @@ -4,12 +4,14 @@ interface IPrimaryButtonProps { title: string; onClick: (e: React.MouseEvent) => void; className?: string; + isDisabled?: boolean; } export default function PrimaryButton(props: IPrimaryButtonProps) { - const { onClick, title, className } = props; + const { onClick, title, className, isDisabled = false } = props; return (