From ad947945c6d5fd8bb48d5050af57f2ad1e67081c Mon Sep 17 00:00:00 2001 From: mrafei Date: Thu, 9 Jul 2020 18:36:49 +0430 Subject: [PATCH] Add progress and delivery assignment --- package.json | 2 +- src/components/Layout/index.js | 35 +- src/components/Select/index.js | 77 ++--- src/containers/App/actions.js | 27 +- src/containers/App/constants.js | 37 ++- src/containers/App/index.js | 14 +- src/containers/App/reducer.js | 17 +- src/containers/App/selectors.js | 59 +--- src/containers/AssignDeliverer/actions.js | 4 +- src/containers/AssignDeliverer/index.js | 38 ++- src/containers/AssignDeliverer/saga.js | 33 +- src/containers/CreateDeliverer/index.js | 2 +- src/containers/DeliverersList/index.js | 2 +- src/containers/DeliveriesList/index.js | 6 +- src/containers/EditDeliverer/index.js | 2 +- src/containers/OnlineOrder/actions.js | 283 +--------------- .../OnlineOrder/components/DeliverySection.js | 2 +- .../OnlineOrder/components/PriceSection.js | 6 +- src/containers/OnlineOrder/constants.js | 181 ----------- src/containers/OnlineOrder/index.js | 22 +- src/containers/OnlineOrder/reducer.js | 69 +--- src/containers/OnlineOrder/saga.js | 93 ++---- src/containers/OnlineOrder/selectors.js | 75 ----- src/containers/OnlineOrders/actions.js | 303 +----------------- src/containers/OnlineOrders/constants.js | 190 +---------- src/containers/OnlineOrders/index.js | 6 +- src/containers/OnlineOrders/reducer.js | 67 +--- src/containers/OnlineOrders/saga.js | 54 +--- src/containers/OnlineOrders/selectors.js | 96 +----- src/containers/PrinterSettings/index.js | 6 +- src/containers/pushNotification.js | 2 +- stores/business/reducer.js | 2 +- stores/business/saga.js | 14 +- stores/user/saga.js | 6 +- styles/_main.scss | 1 + styles/input.scss | 25 +- styles/progress.scss | 47 +++ utils/api.js | 99 +++--- 38 files changed, 406 insertions(+), 1598 deletions(-) create mode 100644 styles/progress.scss diff --git a/package.json b/package.json index 797e0eb..0a8d886 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vitrin-pos", "productName": "vitrin-pos", - "version": "0.3.2", + "version": "0.4.0", "description": "Application for vitrin POS", "license": "Vitrin", "private": false, diff --git a/src/components/Layout/index.js b/src/components/Layout/index.js index b91eab0..21dbdca 100644 --- a/src/components/Layout/index.js +++ b/src/components/Layout/index.js @@ -6,24 +6,14 @@ import logo from "../../../assets/images/vitrin-blue.png"; import { remote } from "electron"; const routes = [ - { id: 1, disabled: false, title: "سفارش آنلاین", path: "/online-orders", icon: ICONS.GLOBAL }, - { id: 2, disabled: true, title: "سفارش تلفنی", path: "/phone-orders", icon: ICONS.PHONE }, - { - id: 3, - disabled: true, - title: "سفارش سالن و بیرون‌بر", - path: "/takeout-orders", - icon: ICONS.ORDER, - }, - { id: 4, disabled: true, title: "مدیریت منو رستوران", path: "products", icon: ICONS.LIST }, - { id: 5, disabled: true, title: "لیست مشترکین", path: "/users", icon: ICONS.PROFILE }, - { id: 6, disabled: false, title: "مدیریت پیک‌ها", path: "/delivery", icon: ICONS.DELIVERY }, - { id: 7, disabled: false, title: "تنظیمات", path: "/settings", icon: ICONS.SETTING }, + { id: 1, disabled: false, title: "مدیریت سفارش‌ها", path: "/orders", icon: ICONS.LIST }, + { id: 2, disabled: true, title: "مدیریت منو رستوران", path: "products", icon: ICONS.GRID }, + { id: 3, disabled: true, title: "لیست مشترکین", path: "/users", icon: ICONS.PROFILE }, + { id: 4, disabled: false, title: "مدیریت پیک‌ها", path: "/delivery", icon: ICONS.DELIVERY }, + { id: 5, disabled: false, title: "تنظیمات", path: "/settings", icon: ICONS.SETTING }, ]; const subRoutes = [ - [], - [], - [], + [{ id: 1, title: "همه سفارش‌ها", path: "/orders/all" }], [], [], [ @@ -38,7 +28,7 @@ const subRoutes = [ [{ id: 1, title: "تنظیمات چاپگر", path: "settings/printer", icon: ICONS.PRINT }], ]; -function Layout({ children, location, title }) { +function Layout({ children, location, title, loading }) { if (location.pathname === "/login") return children; const activeRouteIndex = routes.findIndex((route) => location.pathname.includes(route.path)); return ( @@ -122,6 +112,17 @@ function Layout({ children, location, title }) { })} ) : null} + {loading ? ( +
+
+
+
+
+
+
+ ) : ( +
+ )} {children}
); diff --git a/src/components/Select/index.js b/src/components/Select/index.js index 8f1ac6f..17d3434 100644 --- a/src/components/Select/index.js +++ b/src/components/Select/index.js @@ -1,8 +1,9 @@ -import React, { useState } from "react"; +import React from "react"; import PropTypes from "prop-types"; -import Icon from "../Icon"; -import TextField from "@material-ui/core/TextField"; -import { ICONS } from "../../../assets/images/icons"; +import MaterialSelect from "@material-ui/core/Select"; +import MenuItem from "@material-ui/core/MenuItem"; +import InputLabel from "@material-ui/core/InputLabel"; +import FormControl from "@material-ui/core/FormControl"; const Select = ({ options, @@ -17,60 +18,22 @@ const Select = ({ disabled, ...props }) => { - const [isOpen, setIsOpen] = useState(false); - const { label, value, className, placeholder } = inputData; - + const { label, value = "", className, placeholder } = inputData; return ( - <> - {isOpen &&
} -
- { - onChange(name, v); - }} - autoComplete="off" - onClick={(e) => { - setIsOpen(!isOpen); - }} - {...props} - /> - - {isOpen && ( -
- {options.map((option) => ( -
{}} - role="button" - tabIndex="0" - style={itemStyle} - key={option.id} - onClick={() => { - setIsOpen(false); - selectOption(option); - }} - className="d-flex flex-row align-items-center u-cursor-pointer px-2 u-text-dark-grey u-fontMedium c-input-result-search-item"> - {!noIcon && ( - - )} - {option.text} -
- ))} -
- )} -
- + + {label} + selectOption(e.target.value)}> + {options.map((o) => ( + + {o.text} + + ))} + + ); }; Select.propTypes = { diff --git a/src/containers/App/actions.js b/src/containers/App/actions.js index 26f77ad..e0edbe9 100644 --- a/src/containers/App/actions.js +++ b/src/containers/App/actions.js @@ -33,7 +33,10 @@ import { UPLOAD_SUCCESS, UPLOAD_FAILURE, UPLOAD_REQUEST_FINISHED, -} from './constants'; + START_PROGRESS_LOADING, + STOP_PROGRESS_LOADING, + SET_PRINTER_OPTIONS, +} from "./constants"; export function init() { return { @@ -60,6 +63,26 @@ export function stopLoading() { }; } +export function startProgressLoading() { + return { + type: START_PROGRESS_LOADING, + }; +} + +export function stopProgressLoading() { + return { + type: STOP_PROGRESS_LOADING, + }; +} + +export function setPrinterOptions(data) { + localStorage.setItem("printerOptions", JSON.stringify(data)); + return { + type: SET_PRINTER_OPTIONS, + data, + }; +} + export function startInitLoading() { return { type: START_INIT_LOADING, @@ -123,7 +146,7 @@ export const uploadProgress = (file, progress) => ({ payload: progress, meta: { file }, }); -export const uploadSuccess = file => ({ +export const uploadSuccess = (file) => ({ type: UPLOAD_SUCCESS, meta: { file }, }); diff --git a/src/containers/App/constants.js b/src/containers/App/constants.js index 3b7edac..97e2db0 100644 --- a/src/containers/App/constants.js +++ b/src/containers/App/constants.js @@ -9,20 +9,23 @@ * export const YOUR_ACTION_CONSTANT = 'yourproject/YourContainer/YOUR_ACTION_CONSTANT'; */ -export const INIT = 'vitrin/App/INIT'; -export const START_LOADING = 'vitrin/App/START_LOADING'; -export const STOP_LOADING = 'vitrin/App/STOP_LOADING'; -export const START_INIT_LOADING = 'vitrin/App/START_INIT_LOADING'; -export const STOP_INIT_LOADING = 'vitrin/App/STOP_INIT_LOADING'; -export const CLEAR_UPLOADED_FILES = 'vitrin/App/CLEAR_UPLOADED_FILES'; -export const UPLOAD_FILE = 'vitrin/App/UPLOAD_FILE'; -export const FILE_UPLOADED = 'vitrin/App/FILE_UPLOADED'; -export const REMOVE_FILE = 'vitrin/App/REMOVE_FILE'; -export const SET_SITE_DOMAIN = 'vitrin/App/SET_SITE_DOMAIN'; -export const MANY_ACTIONS = 'vitrin/App/MANY_ACTIONS'; -export const SEND_EMAIL = 'vitrin/App/SEND_EMAIL'; -export const UPLOAD_REQUEST = 'vitrin/App/UPLOAD_REQUEST'; -export const UPLOAD_REQUEST_FINISHED = 'vitrin/App/UPLOAD_REQUEST_FINISHED'; -export const UPLOAD_PROGRESS = 'vitrin/App/UPLOAD_PROGRESS'; -export const UPLOAD_SUCCESS = 'vitrin/App/UPLOAD_SUCCESS'; -export const UPLOAD_FAILURE = 'vitrin/App/UPLOAD_FAILURE'; +export const INIT = "vitrin/App/INIT"; +export const START_LOADING = "vitrin/App/START_LOADING"; +export const STOP_LOADING = "vitrin/App/STOP_LOADING"; +export const START_PROGRESS_LOADING = "vitrin/App/START_PROGRESS_LOADING"; +export const STOP_PROGRESS_LOADING = "vitrin/App/STOP_PROGRESS_LOADING"; +export const START_INIT_LOADING = "vitrin/App/START_INIT_LOADING"; +export const STOP_INIT_LOADING = "vitrin/App/STOP_INIT_LOADING"; +export const CLEAR_UPLOADED_FILES = "vitrin/App/CLEAR_UPLOADED_FILES"; +export const UPLOAD_FILE = "vitrin/App/UPLOAD_FILE"; +export const FILE_UPLOADED = "vitrin/App/FILE_UPLOADED"; +export const REMOVE_FILE = "vitrin/App/REMOVE_FILE"; +export const SET_SITE_DOMAIN = "vitrin/App/SET_SITE_DOMAIN"; +export const MANY_ACTIONS = "vitrin/App/MANY_ACTIONS"; +export const SEND_EMAIL = "vitrin/App/SEND_EMAIL"; +export const UPLOAD_REQUEST = "vitrin/App/UPLOAD_REQUEST"; +export const UPLOAD_REQUEST_FINISHED = "vitrin/App/UPLOAD_REQUEST_FINISHED"; +export const UPLOAD_PROGRESS = "vitrin/App/UPLOAD_PROGRESS"; +export const UPLOAD_SUCCESS = "vitrin/App/UPLOAD_SUCCESS"; +export const UPLOAD_FAILURE = "vitrin/App/UPLOAD_FAILURE"; +export const SET_PRINTER_OPTIONS = 'app/AdminPanelApp/SET_PRINTER_OPTIONS'; diff --git a/src/containers/App/index.js b/src/containers/App/index.js index 476364f..1101301 100644 --- a/src/containers/App/index.js +++ b/src/containers/App/index.js @@ -15,7 +15,7 @@ import Axios from "axios"; import { getBusinesses } from "../../../stores/user/actions"; import Layout from "../../components/Layout"; import OnlineOrder from "../OnlineOrder"; -import { makeSelectSubDomain } from "./selectors"; +import { makeSelectProgressLoading, makeSelectSubDomain } from "./selectors"; import LoadingIndicator from "../../components/LoadingIndicator"; import { setSnackBarMessage } from "../../../stores/ui/actions"; import { makeSelectSnackBarMessage } from "../../../stores/ui/selector"; @@ -38,6 +38,7 @@ const App = function ({ snackBarMessage, _getAdminOrders, businessTitle, + progressLoading, }) { useInjectReducer({ key: "app", reducer }); useInjectSaga({ key: "app", saga }); @@ -70,11 +71,12 @@ const App = function ({ return ( <>
- + - - + + + @@ -84,9 +86,10 @@ const App = function ({ + - +
@@ -116,6 +119,7 @@ const mapStateToProps = createStructuredSelector({ siteDomain: makeSelectSubDomain(), businessTitle: makeSelectBusinessTitle(), snackBarMessage: makeSelectSnackBarMessage(), + progressLoading: makeSelectProgressLoading(), }); function mapDispatchToProps(dispatch) { diff --git a/src/containers/App/reducer.js b/src/containers/App/reducer.js index d7b1c62..0c84fa3 100644 --- a/src/containers/App/reducer.js +++ b/src/containers/App/reducer.js @@ -7,7 +7,7 @@ * */ -import produce from 'immer'; +import produce from "immer"; import { FILE_UPLOADED, REMOVE_FILE, @@ -20,24 +20,27 @@ import { UPLOAD_PROGRESS, UPLOAD_REQUEST, UPLOAD_REQUEST_FINISHED, -} from './constants'; + START_PROGRESS_LOADING, + STOP_PROGRESS_LOADING, +} from "./constants"; // The initial state of the App export const initialState = { loading: false, + progressLoading: false, initLoading: true, error: false, user: null, uploadedFile: null, uploadProgress: null, uploadStarted: false, - subdomain: '', + subdomain: "", multipleUploadedFiles: [], }; /* eslint-disable default-case, no-param-reassign */ const appReducer = (state = initialState, action) => - produce(state, draft => { + produce(state, (draft) => { switch (action.type) { case START_LOADING: draft.loading = true; @@ -46,7 +49,13 @@ const appReducer = (state = initialState, action) => case STOP_LOADING: draft.loading = false; break; + case START_PROGRESS_LOADING: + draft.progressLoading = true; + break; + case STOP_PROGRESS_LOADING: + draft.progressLoading = false; + break; case START_INIT_LOADING: draft.initLoading = true; break; diff --git a/src/containers/App/selectors.js b/src/containers/App/selectors.js index b1706b6..947fc96 100644 --- a/src/containers/App/selectors.js +++ b/src/containers/App/selectors.js @@ -2,66 +2,40 @@ * The global state selectors */ -import { createSelector } from 'reselect'; -import { initialState } from './reducer'; +import { createSelector } from "reselect"; +import { initialState } from "./reducer"; -const selectGlobal = state => state.global || initialState; +const selectGlobal = (state) => state.global || initialState; -const selectRouter = state => state.router; +const selectRouter = (state) => state.router; -const makeSelectLoading = () => - createSelector( - selectGlobal, - globalState => globalState.loading, - ); +const makeSelectLoading = () => createSelector(selectGlobal, (globalState) => globalState.loading); + +const makeSelectProgressLoading = () => + createSelector(selectGlobal, (globalState) => globalState.progressLoading); const makeSelectUploadProgress = () => - createSelector( - selectGlobal, - globalState => globalState.uploadProgress, - ); + createSelector(selectGlobal, (globalState) => globalState.uploadProgress); const makeSelectUploadStarted = () => - createSelector( - selectGlobal, - globalState => globalState.uploadStarted, - ); + createSelector(selectGlobal, (globalState) => globalState.uploadStarted); const makeSelectInitLoading = () => - createSelector( - selectGlobal, - globalState => globalState.initLoading, - ); + createSelector(selectGlobal, (globalState) => globalState.initLoading); const makeSelectUploadedFile = () => - createSelector( - selectGlobal, - globalState => globalState.uploadedFile, - ); + createSelector(selectGlobal, (globalState) => globalState.uploadedFile); const makeSelectUploadedFiles = () => - createSelector( - selectGlobal, - globalState => globalState.multipleUploadedFiles, - ); + createSelector(selectGlobal, (globalState) => globalState.multipleUploadedFiles); -const makeSelectError = () => - createSelector( - selectGlobal, - globalState => globalState.error, - ); +const makeSelectError = () => createSelector(selectGlobal, (globalState) => globalState.error); const makeSelectSubDomain = () => - createSelector( - selectGlobal, - globalState => globalState.subdomain, - ); + createSelector(selectGlobal, (globalState) => globalState.subdomain); const makeSelectLocation = () => - createSelector( - selectRouter, - routerState => routerState.location, - ); + createSelector(selectRouter, (routerState) => routerState.location); export { makeSelectInitLoading, @@ -74,4 +48,5 @@ export { makeSelectUploadedFile, makeSelectUploadProgress, makeSelectUploadStarted, + makeSelectProgressLoading, }; diff --git a/src/containers/AssignDeliverer/actions.js b/src/containers/AssignDeliverer/actions.js index 91340ca..9455a49 100644 --- a/src/containers/AssignDeliverer/actions.js +++ b/src/containers/AssignDeliverer/actions.js @@ -17,10 +17,10 @@ export function defaultAction() { }; } -export function getFoodAdminOrders(page) { +export function getFoodAdminOrders(page, hasDeliverer) { return { type: GET_FOOD_ADMIN_ORDERS, - data: page, + data: { page, hasDeliverer }, }; } diff --git a/src/containers/AssignDeliverer/index.js b/src/containers/AssignDeliverer/index.js index a2574f5..5940028 100644 --- a/src/containers/AssignDeliverer/index.js +++ b/src/containers/AssignDeliverer/index.js @@ -19,7 +19,12 @@ import Icon from "../../components/Icon"; import { ICONS } from "../../../assets/images/icons"; import { makeSelectPlugin } from "../../../stores/business/selector"; import { makeSelectLoading } from "../App/selectors"; - +import Select from "../../components/Select"; +const filterOptions = [ + { id: 1, text: "همه سفارش‌ها", value: "" }, + { id: 2, text: "سفارش جدید", value: "False" }, + { id: 3, text: "پیک تخصیص داده شده", value: "True" }, +]; const AssignDeliverer = function ({ _getAdminOrders, orders, @@ -35,11 +40,14 @@ const AssignDeliverer = function ({ const [selected, setSelected] = useState([]); const [sendSms, setSendSms] = useState(true); const [deliverer, setDeliverer] = useState(""); + const [filter, setFilter] = useState(filterOptions[1].text); const page = getQueryParams("page", location.search) || 1; useEffect(() => { - _getAdminOrders(page); - }, [location]); + const hasDeliverer = filterOptions.find((fo) => fo.text === filter).value; + _getAdminOrders(page, hasDeliverer); + }, [location, filter]); + useEffect(() => { setSelected(orders.map(() => false)); }, [orders]); @@ -54,17 +62,19 @@ const AssignDeliverer = function ({ if (isSelected) return orderIds.push(orders[index].id); }); if (!orderIds.length) return; + const hasDeliverer = filterOptions.find((fo) => fo.text === filter).value; _setDeliverers({ deliverer, + hasDeliverer, sendSms, orders: orderIds, page, }); }, - [selected, sendSms] + [selected, sendSms, filter] ); return ( -
+
setSelected(orders.map(() => checked))} label={`defaultCheck`} /> +
+