From 2e76f8afd8684df296a46ca52d51ca8f30a58007 Mon Sep 17 00:00:00 2001 From: ironslee Date: Mon, 20 May 2024 18:15:41 +0600 Subject: [PATCH 1/2] enum introduction --- backend/controllers/customers.controller.ts | 5 +- backend/controllers/dashboard.controller.ts | 30 ++++++------ backend/controllers/orders.controller.ts | 47 ++++++++++--------- backend/controllers/paidOuts.controller.ts | 18 +++---- backend/controllers/tgBot.controller.ts | 13 ++--- backend/controllers/user.controller.ts | 5 +- backend/utils/checkAvailableStatuses.ts | 10 ++-- frontend/src/App.tsx | 4 +- frontend/src/components/Appbar/Appbar.tsx | 4 +- .../OrdersSearchPanel/OrdersSearchPanel.tsx | 9 ++-- frontend/src/models/orderModel.ts | 9 ++++ frontend/src/models/userModel.ts | 6 +++ frontend/src/pages/Customers/Customers.tsx | 5 +- frontend/src/pages/PaidOuts/PaidOuts.tsx | 5 +- frontend/src/pages/Users/Users.tsx | 10 ++-- .../src/pages/administration/Cash/Cash.tsx | 7 +-- .../DictBoilers/DictBoilers.tsx | 10 ++-- .../DictJobTypes/DictJobTypes.tsx | 10 ++-- .../DictOrderStatuses/DictOrderStatuses.tsx | 6 +-- .../administration/DictParts/DictParts.tsx | 10 ++-- .../administration/DictRoles/DictRoles.tsx | 6 +-- .../pages/orders/CreateOrder/CreateOrder.tsx | 5 +- .../src/pages/orders/OrderEdit/OrderEdit.tsx | 26 ++++++---- .../src/pages/orders/OrderView/OrderView.tsx | 11 +++-- .../pages/orders/OrdersList/OrdersList.tsx | 13 ++--- 25 files changed, 170 insertions(+), 114 deletions(-) diff --git a/backend/controllers/customers.controller.ts b/backend/controllers/customers.controller.ts index bc1d5f7..361e7ff 100644 --- a/backend/controllers/customers.controller.ts +++ b/backend/controllers/customers.controller.ts @@ -4,6 +4,7 @@ import dotenv from 'dotenv'; import format from 'pg-format'; import moment from 'moment'; import { UserRequest } from '../../global'; +import { UserRolesEnum } from '../../frontend/src/models/userModel'; dotenv.config(); @@ -171,8 +172,8 @@ const updateCustomer = async ( try { if ( request.user && - request.user.roleCode !== 'ADMIN' && - request.user.roleCode !== 'SUPER_ADMIN' + request.user.roleCode !== UserRolesEnum.ADMIN && + request.user.roleCode !== UserRolesEnum.SUPER_ADMIN ) { return response.status(401).json({ message: `Current user don't have permission to this request`, diff --git a/backend/controllers/dashboard.controller.ts b/backend/controllers/dashboard.controller.ts index a915a72..c2a453f 100644 --- a/backend/controllers/dashboard.controller.ts +++ b/backend/controllers/dashboard.controller.ts @@ -2,6 +2,8 @@ import { NextFunction, Response } from 'express'; import db from '../config/db'; import dotenv from 'dotenv'; import { UserRequest } from '../../global'; +import { UserRolesEnum } from '../../frontend/src/models/userModel'; +import { OrderStatusEnum } from '../../frontend/src/models/orderModel'; dotenv.config(); @@ -15,8 +17,8 @@ const getOrdersInfo = async ( ) => { try { const isAdmin = - request.user?.roleCode === 'ADMIN' || - request.user?.roleCode === 'SUPER_ADMIN'; + request.user?.roleCode === UserRolesEnum.ADMIN || + request.user?.roleCode === UserRolesEnum.SUPER_ADMIN; const ordersCount = isAdmin ? await db.query( @@ -52,7 +54,7 @@ const getOrdersInfo = async ( "${process.env.DB_NAME}".orders WHERE orders."isActive" = true AND - orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = 'SERVICE_DONE'); + orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = '${OrderStatusEnum.SERVICE_DONE}'); ; `, [] @@ -66,7 +68,7 @@ const getOrdersInfo = async ( WHERE orders."isActive" = true AND orders."serviceManId" = $1 AND - orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = 'SERVICE_DONE'); + orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = '${OrderStatusEnum.SERVICE_DONE}'); `, [request.user?.id] ); @@ -80,7 +82,7 @@ const getOrdersInfo = async ( "${process.env.DB_NAME}".orders WHERE orders."isActive" = true AND - orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = 'IN_PROGRESS'); + orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = '${OrderStatusEnum.IN_PROGRESS}'); ; `, [] @@ -94,7 +96,7 @@ const getOrdersInfo = async ( WHERE orders."isActive" = true AND orders."serviceManId" = $1 AND - orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = 'IN_PROGRESS'); + orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = '${OrderStatusEnum.IN_PROGRESS}'); `, [request.user?.id] ); @@ -108,7 +110,7 @@ const getOrdersInfo = async ( "${process.env.DB_NAME}".orders WHERE orders."isActive" = true AND - orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = 'CREATED'); + orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = '${OrderStatusEnum.CREATED}'); ; `, [] @@ -122,7 +124,7 @@ const getOrdersInfo = async ( WHERE orders."isActive" = true AND orders."serviceManId" = $1 AND - orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = 'CREATED'); + orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = '${OrderStatusEnum.CREATED}'); `, [request.user?.id] ); @@ -136,7 +138,7 @@ const getOrdersInfo = async ( "${process.env.DB_NAME}".orders WHERE orders."isActive" = true AND - orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = 'CANCELED'); + orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = '${OrderStatusEnum.CANCELED}'); ; `, [] @@ -150,7 +152,7 @@ const getOrdersInfo = async ( WHERE orders."isActive" = true AND orders."serviceManId" = $1 AND - orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = 'CANCELED'); + orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = '${OrderStatusEnum.CANCELED}'); `, [request.user?.id] ); @@ -164,7 +166,7 @@ const getOrdersInfo = async ( "${process.env.DB_NAME}".orders WHERE orders."isActive" = true AND - orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = 'ON_HOLD'); + orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = '${OrderStatusEnum.ON_HOLD}'); ; `, [] @@ -178,7 +180,7 @@ const getOrdersInfo = async ( WHERE orders."isActive" = true AND orders."serviceManId" = $1 AND - orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = 'ON_HOLD'); + orders.status = (SELECT id FROM "${process.env.DB_NAME}"."dictOrderStatuses" WHERE code = '${OrderStatusEnum.ON_HOLD}'); `, [request.user?.id] ); @@ -209,8 +211,8 @@ const getCashInfo = async ( ) => { try { const isAdmin = - request.user?.roleCode === 'ADMIN' || - request.user?.roleCode === 'SUPER_ADMIN'; + request.user?.roleCode === UserRolesEnum.ADMIN || + request.user?.roleCode === UserRolesEnum.SUPER_ADMIN; if (isAdmin) { const readySum = await db.query( diff --git a/backend/controllers/orders.controller.ts b/backend/controllers/orders.controller.ts index 52f5436..472506b 100644 --- a/backend/controllers/orders.controller.ts +++ b/backend/controllers/orders.controller.ts @@ -4,6 +4,8 @@ import dotenv from 'dotenv'; import format from 'pg-format'; import moment from 'moment'; import { UserRequest } from '../../global'; +import { UserRolesEnum } from '../../frontend/src/models/userModel'; +import { OrderStatusEnum } from '../../frontend/src/models/orderModel'; dotenv.config(); @@ -81,7 +83,7 @@ const createOrder = async ( RETURNING *; `, - [insertOrder.rows[0].id, 'CREATED', comment, createdBy] + [insertOrder.rows[0].id, OrderStatusEnum.CREATED, comment, createdBy] ); let partsTotal: number = 0; @@ -268,8 +270,8 @@ const updateOrder = async ( for (let i = 0; i < checkStatus.rows.length; i += 1) { if ( - request.user?.roleCode !== 'SUPER_ADMIN' && - request.user?.roleCode !== 'ADMIN' && + request.user?.roleCode !== UserRolesEnum.SUPER_ADMIN && + request.user?.roleCode !== UserRolesEnum.ADMIN && checkStatus.rows[i].serviceManId !== request.user?.id ) { return response.status(400).json({ @@ -278,8 +280,8 @@ const updateOrder = async ( } if ( - checkStatus.rows[i].code === 'DONE' || - checkStatus.rows[i].code === 'CANCELED' + checkStatus.rows[i].code === OrderStatusEnum.DONE || + checkStatus.rows[i].code === OrderStatusEnum.CANCELED ) { return response.status(400).json({ message: `Order cannot be edit on status DONE or CANCELED`, @@ -532,8 +534,8 @@ const getOrderById = async ( if ( getOrderById.rows[0]?.serviceManId !== user?.id && - user?.roleCode !== 'SUPER_ADMIN' && - user?.roleCode !== 'ADMIN' + user?.roleCode !== UserRolesEnum.SUPER_ADMIN && + user?.roleCode !== UserRolesEnum.ADMIN ) { return response.status(401).json({ message: 'Нет доступа к заказу', @@ -819,7 +821,10 @@ const getOrders = async ( let orders = []; let total = null; - if (roleCode === 'ADMIN' || roleCode === 'SUPER_ADMIN') { + if ( + roleCode === UserRolesEnum.ADMIN || + roleCode === UserRolesEnum.SUPER_ADMIN + ) { const query = ` SELECT orders.id, @@ -1199,14 +1204,14 @@ const getOrderActions = async ( [id] ); - if (order.rows[0]?.statusCode === 'DONE') { + if (order.rows[0]?.statusCode === OrderStatusEnum.DONE) { return response.json([]); } if ( order.rows[0]?.serviceManId !== user?.id && - user?.roleCode !== 'SUPER_ADMIN' && - user?.roleCode !== 'ADMIN' + user?.roleCode !== UserRolesEnum.SUPER_ADMIN && + user?.roleCode !== UserRolesEnum.ADMIN ) { return response.status(401).json({ message: 'Нет доступа к изменению статуса', @@ -1230,9 +1235,9 @@ const getOrderActions = async ( ); if ( - availableStatuses.rows[0]?.availableOn === 'SERVICE_DONE' && - user?.roleCode !== 'SUPER_ADMIN' && - user?.roleCode !== 'ADMIN' + availableStatuses.rows[0]?.availableOn === OrderStatusEnum.SERVICE_DONE && + user?.roleCode !== UserRolesEnum.SUPER_ADMIN && + user?.roleCode !== UserRolesEnum.ADMIN ) { return response.json([]); } @@ -1287,8 +1292,8 @@ const executeAction = async ( if ( order.rows[0]?.serviceManId !== user?.id && - user?.roleCode !== 'SUPER_ADMIN' && - user?.roleCode !== 'ADMIN' + user?.roleCode !== UserRolesEnum.SUPER_ADMIN && + user?.roleCode !== UserRolesEnum.ADMIN ) { return response.status(401).json({ message: 'Нет доступа к изменению статуса', @@ -1302,7 +1307,7 @@ const executeAction = async ( SET status = $1, "updatedDate" = NOW() - ${code === 'DONE' ? ', "doneDate" = NOW()' : ''} + ${code === OrderStatusEnum.DONE ? ', "doneDate" = NOW()' : ''} WHERE orders.id = $2 RETURNING @@ -1311,8 +1316,8 @@ const executeAction = async ( [getStatusInfo.rows[0].id, orderId] ); - // UPDATE CASH TABLE IF ORDER STATUS === 'DONE' - if (code === 'DONE') { + // UPDATE CASH TABLE IF ORDER STATUS === OrderStatusEnum.DONE + if (code === OrderStatusEnum.DONE) { const paidOutSum = await db.query( ` SELECT @@ -1388,8 +1393,8 @@ const executeAction = async ( [orderId, getStatusInfo.rows[0].id, comment, user?.id || 1] ); - // Return quantity, if code === 'CANCELED' - if (code === 'CANCELED') { + // Return quantity, if code === OrderStatusEnum.CANCELED + if (code === OrderStatusEnum.CANCELED) { const disableOldSoldParts = await db.query( ` SELECT diff --git a/backend/controllers/paidOuts.controller.ts b/backend/controllers/paidOuts.controller.ts index abe13be..710c7c5 100644 --- a/backend/controllers/paidOuts.controller.ts +++ b/backend/controllers/paidOuts.controller.ts @@ -3,6 +3,8 @@ import db from '../config/db'; import dotenv from 'dotenv'; import moment from 'moment'; import { UserRequest } from '../../global'; +import { UserRolesEnum } from '../../frontend/src/models/userModel'; +import { OrderStatusEnum } from '../../frontend/src/models/orderModel'; dotenv.config(); @@ -37,8 +39,8 @@ const getPaidsByUser = async ( let getPaidsByUser = null; if ( - request.user?.roleCode === 'ADMIN' || - request.user?.roleCode === 'SUPER_ADMIN' + request.user?.roleCode === UserRolesEnum.ADMIN || + request.user?.roleCode === UserRolesEnum.SUPER_ADMIN ) { getPaidsByUser = await db.query( ` @@ -63,7 +65,7 @@ const getPaidsByUser = async ( FROM "${process.env.DB_NAME}"."dictOrderStatuses" as status WHERE - status.code = 'DONE' + status.code = '${OrderStatusEnum.DONE}' ) ${ searchValue @@ -104,7 +106,7 @@ const getPaidsByUser = async ( FROM "${process.env.DB_NAME}"."dictOrderStatuses" as status WHERE - status.code = 'DONE' + status.code = '${OrderStatusEnum.DONE}' ) ${ searchValue @@ -160,8 +162,8 @@ const getPaidsByUser = async ( let total = null; if ( - request.user?.roleCode === 'ADMIN' || - request.user?.roleCode === 'SUPER_ADMIN' + request.user?.roleCode === UserRolesEnum.ADMIN || + request.user?.roleCode === UserRolesEnum.SUPER_ADMIN ) { total = await db.query( ` @@ -180,7 +182,7 @@ const getPaidsByUser = async ( FROM "${process.env.DB_NAME}"."dictOrderStatuses" as status WHERE - status.code = 'DONE' + status.code = '${OrderStatusEnum.DONE}' ); ` ); @@ -204,7 +206,7 @@ const getPaidsByUser = async ( FROM "${process.env.DB_NAME}"."dictOrderStatuses" as status WHERE - status.code = 'DONE' + status.code = '${OrderStatusEnum.DONE}' ); `, [userId] diff --git a/backend/controllers/tgBot.controller.ts b/backend/controllers/tgBot.controller.ts index cbe91ce..94d5983 100644 --- a/backend/controllers/tgBot.controller.ts +++ b/backend/controllers/tgBot.controller.ts @@ -4,6 +4,7 @@ import db from '../config/db'; import dotenv from 'dotenv'; import axios from 'axios'; import { UserRequest } from '../../global'; +import { UserRolesEnum } from '../../frontend/src/models/userModel'; dotenv.config(); @@ -50,8 +51,8 @@ const sendUpdateOrderStatusMessage = async ( "${process.env.DB_NAME}"."users" as users WHERE users.id = $1 OR - users."roleId" = (SELECT id FROM "service-crm"."dictRoles" WHERE code = 'ADMIN') OR - users."roleId" = (SELECT id FROM "service-crm"."dictRoles" WHERE code = 'SUPER_ADMIN'); + users."roleId" = (SELECT id FROM "service-crm"."dictRoles" WHERE code = '${UserRolesEnum.ADMIN}') OR + users."roleId" = (SELECT id FROM "service-crm"."dictRoles" WHERE code = '${UserRolesEnum.SUPER_ADMIN}'); `, [serviceManId.rows[0].serviceManId] ); @@ -157,8 +158,8 @@ const sendCreateOrderMessage = async ( "${process.env.DB_NAME}"."users" as users WHERE users.id = $1 OR - users."roleId" = (SELECT id FROM "service-crm"."dictRoles" WHERE code = 'ADMIN') OR - users."roleId" = (SELECT id FROM "service-crm"."dictRoles" WHERE code = 'SUPER_ADMIN'); + users."roleId" = (SELECT id FROM "service-crm"."dictRoles" WHERE code = '${UserRolesEnum.ADMIN}') OR + users."roleId" = (SELECT id FROM "service-crm"."dictRoles" WHERE code = '${UserRolesEnum.SUPER_ADMIN}'); `, [serviceManId.rows[0].serviceManId] ); @@ -266,8 +267,8 @@ const sendUpdateOrderMessage = async ( "${process.env.DB_NAME}"."users" as users WHERE users.id = $1 OR - users."roleId" = (SELECT id FROM "service-crm"."dictRoles" WHERE code = 'ADMIN') OR - users."roleId" = (SELECT id FROM "service-crm"."dictRoles" WHERE code = 'SUPER_ADMIN'); + users."roleId" = (SELECT id FROM "service-crm"."dictRoles" WHERE code = '${UserRolesEnum.ADMIN}') OR + users."roleId" = (SELECT id FROM "service-crm"."dictRoles" WHERE code = '${UserRolesEnum.SUPER_ADMIN}'); `, [serviceManId.rows[0].serviceManId] ); diff --git a/backend/controllers/user.controller.ts b/backend/controllers/user.controller.ts index be7d1c1..c95fc55 100644 --- a/backend/controllers/user.controller.ts +++ b/backend/controllers/user.controller.ts @@ -6,6 +6,7 @@ import getSetString from '../utils/queryBuilders'; import dotenv from 'dotenv'; import format from 'pg-format'; import { UserRequest } from '../../global'; +import { UserRolesEnum } from '../../frontend/src/models/userModel'; dotenv.config(); @@ -254,8 +255,8 @@ const updateUser = async ( if ( request.user && - request.user.roleCode !== 'ADMIN' && - request.user.roleCode !== 'SUPER_ADMIN' + request.user.roleCode !== UserRolesEnum.ADMIN && + request.user.roleCode !== UserRolesEnum.SUPER_ADMIN ) { return response.status(401).json({ message: `Current user don't have permission to this request`, diff --git a/backend/utils/checkAvailableStatuses.ts b/backend/utils/checkAvailableStatuses.ts index 1ee29e0..2582512 100644 --- a/backend/utils/checkAvailableStatuses.ts +++ b/backend/utils/checkAvailableStatuses.ts @@ -1,15 +1,17 @@ +import { OrderStatusEnum } from "../../frontend/src/models/orderModel"; + export const checkAvailableStatuses = (currentStatus: string) => { if (!checkAvailableStatuses) { return []; } switch (currentStatus) { - case 'CREATED': { - return ['IN_PROGRESS']; + case OrderStatusEnum.CREATED: { + return [OrderStatusEnum.IN_PROGRESS]; } - case 'IN_PROGRESS': { - return ['CANCELED', 'DONE']; + case OrderStatusEnum.IN_PROGRESS: { + return [OrderStatusEnum.CANCELED, OrderStatusEnum.DONE]; } default: { diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 715b667..274294c 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -24,6 +24,7 @@ import OrderEdit from './pages/orders/OrderEdit'; import PaidOuts from './pages/PaidOuts'; import Settings from './pages/administration/Settings'; import Cash from './pages/administration/Cash'; +import { UserRolesEnum } from './models/userModel'; const App = () => { const dispatch = useDispatch(); @@ -98,7 +99,8 @@ const App = () => { - {(userRole === 'ADMIN' || userRole === 'SUPER_ADMIN') && ( + {(userRole === UserRolesEnum.ADMIN || + userRole === UserRolesEnum.SUPER_ADMIN) && ( <> diff --git a/frontend/src/components/Appbar/Appbar.tsx b/frontend/src/components/Appbar/Appbar.tsx index 0e9b099..a231c8c 100644 --- a/frontend/src/components/Appbar/Appbar.tsx +++ b/frontend/src/components/Appbar/Appbar.tsx @@ -35,6 +35,7 @@ import PlaylistAddCheckIcon from '@material-ui/icons/PlaylistAddCheck'; import EmojiPeopleIcon from '@material-ui/icons/EmojiPeople'; import AttachMoneyIcon from '@material-ui/icons/AttachMoney'; import PointOfSaleIcon from '@mui/icons-material/PointOfSale'; +import { UserRolesEnum } from '../../models/userModel'; const Appbar = () => { const open = useSelector((state: StoreModel) => state.mainStore.isDrawerOpen); @@ -127,7 +128,8 @@ const Appbar = () => { ))} - {(userRoleCode === 'ADMIN' || userRoleCode === 'SUPER_ADMIN') && ( + {(userRoleCode === UserRolesEnum.ADMIN || + userRoleCode === UserRolesEnum.SUPER_ADMIN) && ( <> diff --git a/frontend/src/components/OrdersSearchPanel/OrdersSearchPanel.tsx b/frontend/src/components/OrdersSearchPanel/OrdersSearchPanel.tsx index 05e8827..a55ba76 100644 --- a/frontend/src/components/OrdersSearchPanel/OrdersSearchPanel.tsx +++ b/frontend/src/components/OrdersSearchPanel/OrdersSearchPanel.tsx @@ -17,6 +17,7 @@ import { Stack } from '@mui/material'; import { getUsers } from '../../store/actions/usersPageActions'; import ReactInputMask from 'react-input-mask'; import { ArrowDownward } from '@material-ui/icons'; +import { UserRolesEnum } from '../../models/userModel'; export interface OrdersSearchPanelProps { label?: string; @@ -69,7 +70,7 @@ export const OrdersSearchPanel = ({ useEffect(() => { onSearch(); - dispatch(getUsers(0, 50, undefined, '', 'SERVICE_MAN')); + dispatch(getUsers(0, 50, undefined, '', UserRolesEnum.SERVICE_MAN)); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -95,7 +96,8 @@ export const OrdersSearchPanel = ({ inputProps={{ 'aria-label': label }} /> - {(userRoleCode === 'SUPER_ADMIN' || userRoleCode === 'ADMIN') && ( + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN) && ( Добавить @@ -136,7 +138,8 @@ export const OrdersSearchPanel = ({ - {(userRole === 'ADMIN' || userRole === 'SUPER_ADMIN') && ( + {(userRole === UserRolesEnum.ADMIN || + userRole === UserRolesEnum.SUPER_ADMIN) && ( { const dispatch = useDispatch(); @@ -285,8 +286,8 @@ const Customers = () => { {customer.comment} - {(userRoleCode === 'SUPER_ADMIN' || - userRoleCode === 'ADMIN') && ( + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN) && ( { const dispatch = useDispatch(); @@ -224,8 +225,8 @@ const PaidOuts = () => { > - {(userRoleCode === 'ADMIN' || - userRoleCode === 'SUPER_ADMIN') && + {(userRoleCode === UserRolesEnum.ADMIN || + userRoleCode === UserRolesEnum.SUPER_ADMIN) && paidOut.canBePaid && !paidOut.isPaid && ( { const dispatch = useDispatch(); @@ -128,9 +129,8 @@ const Users = () => { inputProps={{ 'aria-label': 'Введите параметры поиска' }} /> - {(userRoleCode === 'SUPER_ADMIN' || userRoleCode === 'ADMIN') && ( - - )} + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN) && } @@ -202,8 +202,8 @@ const Users = () => { {formatDate(user.updatedDate || '', true)} - {(userRoleCode === 'SUPER_ADMIN' || - userRoleCode === 'ADMIN') && ( + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN) && ( { const dispatch = useDispatch(); @@ -298,8 +299,8 @@ const Cash = () => { {formatDate(cash.updatedDate || '', true)} - {(userRoleCode === 'ADMIN' || - userRoleCode === 'SUPER_ADMIN') && ( + {(userRoleCode === UserRolesEnum.ADMIN || + userRoleCode === UserRolesEnum.SUPER_ADMIN) && ( { )} - {userRoleCode === 'SUPER_ADMIN' && ( + {userRoleCode === UserRolesEnum.SUPER_ADMIN && ( { const dispatch = useDispatch(); @@ -137,9 +138,8 @@ const DictBoilers = () => {

Отопительные котлы

- {(userRoleCode === 'SUPER_ADMIN' || userRoleCode === 'ADMIN') && ( - - )} + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN) && }
@@ -175,8 +175,8 @@ const DictBoilers = () => { {formatDate(boiler.updatedDate || '', true)}
- {(userRoleCode === 'SUPER_ADMIN' || - userRoleCode === 'ADMIN') && ( + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN) && ( { const dispatch = useDispatch(); @@ -143,9 +144,8 @@ const DictBoilers = () => {

Виды работ

- {(userRoleCode === 'SUPER_ADMIN' || userRoleCode === 'ADMIN') && ( - - )} + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN) && }
@@ -176,8 +176,8 @@ const DictBoilers = () => { {job.daysOfGuarantee} {formatDate(job.updatedDate || '', true)} - {(userRoleCode === 'SUPER_ADMIN' || - userRoleCode === 'ADMIN') && ( + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN) && ( { const statuses = useSelector( @@ -25,9 +26,8 @@ const DictOrderStatuses = () => {

Статусы заказов

- {(userRoleCode === 'SUPER_ADMIN' || userRoleCode === 'ADMIN') && ( - - )} + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN) && }
diff --git a/frontend/src/pages/administration/DictParts/DictParts.tsx b/frontend/src/pages/administration/DictParts/DictParts.tsx index bc202e1..bdf049b 100644 --- a/frontend/src/pages/administration/DictParts/DictParts.tsx +++ b/frontend/src/pages/administration/DictParts/DictParts.tsx @@ -28,6 +28,7 @@ import { ADD_NOTIFY } from '../../../store/storeConstants/snackbarConstants'; import api from '../../../utils/axiosMiddleware'; import CreatePartModal from '../../../components/modals/CreatePartModal'; import { Stack } from '@mui/material'; +import { UserRolesEnum } from '../../../models/userModel'; const DictParts = () => { const dispatch = useDispatch(); @@ -143,9 +144,8 @@ const DictParts = () => {

Запчасти

- {(userRoleCode === 'SUPER_ADMIN' || userRoleCode === 'ADMIN') && ( - - )} + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN) && }
@@ -180,8 +180,8 @@ const DictParts = () => { {formatDate(part.updatedDate || '', true)}
- {(userRoleCode === 'SUPER_ADMIN' || - userRoleCode === 'ADMIN') && ( + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN) && ( { const roles = useSelector( @@ -25,9 +26,8 @@ const DictRoles = () => {

Роли

- {(userRoleCode === 'SUPER_ADMIN' || userRoleCode === 'ADMIN') && ( - - )} + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN) && }
diff --git a/frontend/src/pages/orders/CreateOrder/CreateOrder.tsx b/frontend/src/pages/orders/CreateOrder/CreateOrder.tsx index 79ad19b..5acc9dd 100644 --- a/frontend/src/pages/orders/CreateOrder/CreateOrder.tsx +++ b/frontend/src/pages/orders/CreateOrder/CreateOrder.tsx @@ -33,6 +33,7 @@ import { formatSum } from '../../../utils/formatSum'; import { getTotalSum } from '../../../utils/getOrderSum'; import { SET_ORDER_DATA } from '../../../store/storeConstants/ordersConstants'; import ReactInputMask from 'react-input-mask'; +import { UserRolesEnum } from '../../../models/userModel'; const CreateOrder = () => { const [fetchFunction, setFetchFunction] = React.useState(() => () => {}); @@ -194,7 +195,9 @@ const CreateOrder = () => { }; const getServiceMan = (searchValue: string) => { - dispatch(getUsers(0, 20, undefined, searchValue, 'SERVICE_MAN')); + dispatch( + getUsers(0, 20, undefined, searchValue, UserRolesEnum.SERVICE_MAN) + ); setCurrentSearch('serviceMan'); }; diff --git a/frontend/src/pages/orders/OrderEdit/OrderEdit.tsx b/frontend/src/pages/orders/OrderEdit/OrderEdit.tsx index 7fbb623..e20d5f0 100644 --- a/frontend/src/pages/orders/OrderEdit/OrderEdit.tsx +++ b/frontend/src/pages/orders/OrderEdit/OrderEdit.tsx @@ -36,6 +36,7 @@ import { ADD_NOTIFY } from '../../../store/storeConstants/snackbarConstants'; import { formatSum } from '../../../utils/formatSum'; import { getTotalSum } from '../../../utils/getOrderSum'; import ReactInputMask from 'react-input-mask'; +import { UserRolesEnum } from '../../../models/userModel'; const OrderEdit = () => { const userRoleCode = useSelector( @@ -209,7 +210,9 @@ const OrderEdit = () => { }; const getServiceMan = (searchValue: string) => { - dispatch(getUsers(0, 20, undefined, searchValue, 'SERVICE_MAN')); + dispatch( + getUsers(0, 20, undefined, searchValue, UserRolesEnum.SERVICE_MAN) + ); setCurrentSearch('serviceMan'); }; @@ -330,7 +333,8 @@ const OrderEdit = () => { value={orderData.customer?.fullName || ''} required disabled={ - userRoleCode !== 'SUPER_ADMIN' && userRoleCode !== 'ADMIN' + userRoleCode !== UserRolesEnum.SUPER_ADMIN && + userRoleCode !== UserRolesEnum.ADMIN } /> @@ -359,7 +363,8 @@ const OrderEdit = () => { onChange={handleChange('address')} required disabled={ - userRoleCode !== 'SUPER_ADMIN' && userRoleCode !== 'ADMIN' + userRoleCode !== UserRolesEnum.SUPER_ADMIN && + userRoleCode !== UserRolesEnum.ADMIN } /> @@ -368,7 +373,8 @@ const OrderEdit = () => { onChange={handleChange('phone')} value={orderData.phone} disabled={ - userRoleCode !== 'SUPER_ADMIN' && userRoleCode !== 'ADMIN' + userRoleCode !== UserRolesEnum.SUPER_ADMIN && + userRoleCode !== UserRolesEnum.ADMIN } > { value={orderData.customer?.boiler?.name || ''} required disabled={ - userRoleCode !== 'SUPER_ADMIN' && userRoleCode !== 'ADMIN' + userRoleCode !== UserRolesEnum.SUPER_ADMIN && + userRoleCode !== UserRolesEnum.ADMIN } /> @@ -404,7 +411,8 @@ const OrderEdit = () => { type="number" onChange={handleChange('visitPrice')} disabled={ - userRoleCode !== 'SUPER_ADMIN' && userRoleCode !== 'ADMIN' + userRoleCode !== UserRolesEnum.SUPER_ADMIN && + userRoleCode !== UserRolesEnum.ADMIN } /> @@ -415,7 +423,8 @@ const OrderEdit = () => { value={orderData.comment} onChange={handleChange('comment')} disabled={ - userRoleCode !== 'SUPER_ADMIN' && userRoleCode !== 'ADMIN' + userRoleCode !== UserRolesEnum.SUPER_ADMIN && + userRoleCode !== UserRolesEnum.ADMIN } /> @@ -438,7 +447,8 @@ const OrderEdit = () => { value={orderData.serviceMan?.fullName || ''} required disabled={ - userRoleCode !== 'SUPER_ADMIN' && userRoleCode !== 'ADMIN' + userRoleCode !== UserRolesEnum.SUPER_ADMIN && + userRoleCode !== UserRolesEnum.ADMIN } /> diff --git a/frontend/src/pages/orders/OrderView/OrderView.tsx b/frontend/src/pages/orders/OrderView/OrderView.tsx index 75c84a0..f69b1a4 100644 --- a/frontend/src/pages/orders/OrderView/OrderView.tsx +++ b/frontend/src/pages/orders/OrderView/OrderView.tsx @@ -40,6 +40,8 @@ import { OrderActionModel } from '../../../models/orderActionModel'; import Btn from '../../../components/Btn'; import Transition from '../../../components/Transition'; import UpdateCustomerModal from '../../../components/UpdateCustomerModal'; +import { UserRolesEnum } from '../../../models/userModel'; +import { OrderStatusEnum } from '../../../models/orderModel'; const OrderView = () => { const dispatch = useDispatch(); @@ -167,15 +169,15 @@ const OrderView = () => { const getButtonClass = (code: string) => { switch (code) { - case 'DONE': { + case OrderStatusEnum.DONE: { return 'btn btn_success'; } - case 'CANCELED': { + case OrderStatusEnum.CANCELED: { return 'btn btn_danger'; } - case 'IN_PROGRESS': { + case OrderStatusEnum.IN_PROGRESS: { return 'btn btn_success'; } @@ -334,7 +336,8 @@ const OrderView = () => { { const dispatch = useDispatch(); @@ -363,11 +364,11 @@ const OrdersList = () => {
- {(userRoleCode === 'SUPER_ADMIN' || - userRoleCode === 'ADMIN' || - userRoleCode === 'SERVICE_MAN') && - order.statusCode !== 'DONE' && - order.statusCode !== 'CANCELED' && ( + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN || + userRoleCode === UserRolesEnum.SERVICE_MAN) && + order.statusCode !== OrderStatusEnum.DONE && + order.statusCode !== OrderStatusEnum.CANCELED && ( editOrder(order)} From d05ca9f421615d668502d8bc8fe7c8d20504928f Mon Sep 17 00:00:00 2001 From: ironslee Date: Mon, 27 May 2024 00:59:25 +0600 Subject: [PATCH 2/2] feat: added searchByBoilerSerial button on Customers page --- frontend/src/pages/Customers/Customers.tsx | 56 +++++++++++++++------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/frontend/src/pages/Customers/Customers.tsx b/frontend/src/pages/Customers/Customers.tsx index 50852f1..a283f1e 100644 --- a/frontend/src/pages/Customers/Customers.tsx +++ b/frontend/src/pages/Customers/Customers.tsx @@ -25,11 +25,13 @@ import { import { getCustomersList } from '../../store/actions/customersActions'; import ShoppingCartIcon from '@material-ui/icons/ShoppingCart'; import history from '../../utils/history'; -import { SET_ORDER_DATA } from '../../store/storeConstants/ordersConstants'; +import { SET_ORDERS_SEARCH_FIELD, SET_ORDER_DATA } from '../../store/storeConstants/ordersConstants'; import TableSort from '../../components/TableSort'; import UpdateCustomerModal from '../../components/UpdateCustomerModal'; import { Stack } from '@mui/material'; import { UserRolesEnum } from '../../models/userModel'; +import FormatListNumberedIcon from '@mui/icons-material/FormatListNumbered'; +import { Link } from 'react-router-dom'; const Customers = () => { const dispatch = useDispatch(); @@ -286,24 +288,42 @@ const Customers = () => {
{customer.comment} - {(userRoleCode === UserRolesEnum.SUPER_ADMIN || - userRoleCode === UserRolesEnum.ADMIN) && ( - - + + + { + dispatch({ + type: SET_ORDERS_SEARCH_FIELD, + payload: customer.boilerSerial, + }); + }} + > + + + - createOrder(customer)} - > - - - - )} + {(userRoleCode === UserRolesEnum.SUPER_ADMIN || + userRoleCode === UserRolesEnum.ADMIN) && ( + + + + createOrder(customer)} + > + + + + )} + ))}