Skip to content

Commit

Permalink
Add progress and delivery assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
mrafei committed Jul 9, 2020
1 parent 9c1a84c commit ad94794
Show file tree
Hide file tree
Showing 38 changed files with 406 additions and 1,598 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
35 changes: 18 additions & 17 deletions src/components/Layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" }],
[],
[],
[
Expand 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 (
Expand Down Expand Up @@ -122,6 +112,17 @@ function Layout({ children, location, title }) {
})}
</div>
) : null}
{loading ? (
<div className="overflow-hidden" style={{ height: 6 }}>
<div className="progress">
<div className="line" />
<div className="subline inc" />
<div className="subline dec" />
</div>
</div>
) : (
<div style={{ height: 6, width: "100%" }} />
)}
{children}
</div>
);
Expand Down
77 changes: 20 additions & 57 deletions src/components/Select/index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 && <div className="u-absolute w-100 h-100 top-0 right-0" />}
<div className="u-relative" style={containerStyle}>
<TextField
variant="filled"
disabled={disabled}
style={{ background: "white", width: "100%", ...inputStyle }}
label={label}
value={value}
className={className}
placeholder={placeholder}
onChange={(name, v) => {
onChange(name, v);
}}
autoComplete="off"
onClick={(e) => {
setIsOpen(!isOpen);
}}
{...props}
/>
<Icon
icon={ICONS.CONTROL_DOWN}
size={25}
color="#949C9F"
className="position-absolute left-0 u-top-50-percent u-pointer-events-none"
/>
{isOpen && (
<div className="d-flex flex-column w-100 z-index-1000 c-input-result-search">
{options.map((option) => (
<div
onKeyDown={() => {}}
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 && (
<Icon icon={ICONS.PLUS} size={12} color="#168fd4" className="ml-2 mr-2" />
)}
<span>{option.text}</span>
</div>
))}
</div>
)}
</div>
</>
<FormControl className="w-100" style={{ marginTop: 8}}>
<InputLabel id="select-label">{label}</InputLabel>
<MaterialSelect
labelId="select-label"
className="w-100"
value={value}
onChange={(e) => selectOption(e.target.value)}>
{options.map((o) => (
<MenuItem key={o.id} value={o.text}>
{o.text}
</MenuItem>
))}
</MaterialSelect>
</FormControl>
);
};
Select.propTypes = {
Expand Down
27 changes: 25 additions & 2 deletions src/containers/App/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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 },
});
Expand Down
37 changes: 20 additions & 17 deletions src/containers/App/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
14 changes: 9 additions & 5 deletions src/containers/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -38,6 +38,7 @@ const App = function ({
snackBarMessage,
_getAdminOrders,
businessTitle,
progressLoading,
}) {
useInjectReducer({ key: "app", reducer });
useInjectSaga({ key: "app", saga });
Expand Down Expand Up @@ -70,11 +71,12 @@ const App = function ({
return (
<>
<div className="u-height-100vh w-100 u-background-melo-grey d-flex h-100">
<Layout location={location} title={businessTitle}>
<Layout location={location} title={businessTitle} loading={progressLoading}>
<Switch>
<Route exact path="/login" component={Login} />
<Route exact path="/online-orders/:id" component={OnlineOrder} />
<Route exact path="/online-orders" component={OnlineOrders} />

<Route exact path="/orders/all" component={OnlineOrders} />
<Route exact path="/orders/:id" component={OnlineOrder} />

<Route exact path="/delivery/deliverers/new" component={CreateDeliverer} />
<Route exact path="/delivery/deliverers/:id" component={EditDeliverer} />
Expand All @@ -84,9 +86,10 @@ const App = function ({

<Route exact path="/settings/printer" component={PrinterSettings} />

<Redirect path="/orders" to="/orders/all" />
<Redirect path="/settings" to="/settings/printer" />
<Redirect path="/delivery" to="/delivery/assign" />
<Redirect path="/" to="/online-orders" />
<Redirect path="/" to="/orders" />
</Switch>
</Layout>
</div>
Expand Down Expand Up @@ -116,6 +119,7 @@ const mapStateToProps = createStructuredSelector({
siteDomain: makeSelectSubDomain(),
businessTitle: makeSelectBusinessTitle(),
snackBarMessage: makeSelectSnackBarMessage(),
progressLoading: makeSelectProgressLoading(),
});

function mapDispatchToProps(dispatch) {
Expand Down
17 changes: 13 additions & 4 deletions src/containers/App/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
*/

import produce from 'immer';
import produce from "immer";
import {
FILE_UPLOADED,
REMOVE_FILE,
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Loading

0 comments on commit ad94794

Please sign in to comment.