Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrouid committed Jun 11, 2019
1 parent 6ee9140 commit 9d2d352
Show file tree
Hide file tree
Showing 28 changed files with 710 additions and 632 deletions.
5 changes: 3 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ class App extends React.Component<any, any> {
<SContent>
<Switch>
<Route exact path="/" component={Home} />
<Route exact path="/demo/:businessName" component={Demo} />
<Route exact path="/order" component={Order} />
<Route exact path="/signup" component={SignUp} />
<Route path="/admin" component={Admin} />
<Route path="/demo/:businessName" component={Demo} />
<Route path="/demo" component={Demo} />
<Route component={NotFound} />
</Switch>
</SContent>
Expand All @@ -60,7 +61,7 @@ class App extends React.Component<any, any> {

const reduxProps = (store: any) => ({
address: store.admin.address,
businessProfile: store.admin.businessProfile
profile: store.admin.profile
});

export default withRouter(connect(
Expand Down
29 changes: 22 additions & 7 deletions src/components/EmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,43 @@ import * as PropTypes from "prop-types";
import styled from "styled-components";
import { SCenter } from "./common";
import { colors } from "../styles";
import Loader from "./Loader";

const SEmptyState = styled(SCenter)`
interface IEmptyStateStyleProps {
color: string;
}

const SEmptyState = styled(SCenter)<IEmptyStateStyleProps>`
background: rgb(${colors.white});
& h6 {
font-weight: normal;
color: rgb(${colors.grey});
color: ${({ color }) => `rgb(${colors[color]})`};
}
`;

const EmptyState = (props: any) => (
<SEmptyState>
<h6>{props.message}</h6>
{props.children}
<SEmptyState color={props.color}>
{!props.loading ? (
<React.Fragment>
<h6>{props.message}</h6>
{props.children}
</React.Fragment>
) : (
<Loader color={props.color} />
)}
</SEmptyState>
);

EmptyState.propTypes = {
message: PropTypes.string
color: PropTypes.string,
message: PropTypes.string,
loading: PropTypes.bool
};

EmptyState.defaultProps = {
message: "No Items"
color: "grey",
message: "No Items",
loading: false
};

export default EmptyState;
10 changes: 5 additions & 5 deletions src/components/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import styled from "styled-components";
import { colors, fonts, shadows, transitions } from "../styles";
import { IMenuItem, IOrderItem, IBusinessPayment } from "../helpers/types";
import { IMenuItem, IOrderItem, ISettings } from "../helpers/types";
import { formatDisplayAmount, sanitizeImgSrc } from "../helpers/utilities";
import {
SListItemImage,
Expand Down Expand Up @@ -118,15 +118,15 @@ interface IListItemAction {

interface IListItemProps {
item: IOrderItem | IMenuItem;
businessPayment: IBusinessPayment;
settings: ISettings;
actions?: IListItemAction[];
noImage?: boolean;
onClick?: any;
}

const ListItem = ({
item,
businessPayment,
settings,
actions,
noImage,
onClick,
Expand All @@ -152,14 +152,14 @@ const ListItem = ({
<SListItemSubtotal>
{formatDisplayAmount(
item.price * item.quantity,
businessPayment.currency
settings.paymentCurrency
)}
</SListItemSubtotal>
</SListItemText>
</SListItemDetails>
) : (
<SListItemPrice>
{formatDisplayAmount(item.price, businessPayment.currency)}
{formatDisplayAmount(item.price, settings.paymentCurrency)}
</SListItemPrice>
)}
</SListItemContainer>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ const SCloseButton = styled.div<ICloseButtonStyleProps>`
position: absolute;
width: ${({ size }) => `${size}px`};
height: ${({ size }) => `${size}px`};
right: ${({ size }) => `${size / 1.6667}px`};
top: ${({ size }) => `${size / 1.6667}px`};
right: ${({ size }) => `${size / 2}px`};
top: ${({ size }) => `${size / 2}px`};
opacity: 0.5;
cursor: pointer;
&:hover {
Expand All @@ -92,7 +92,7 @@ const SCard = styled.div`
position: relative;
width: 100%;
max-width: 500px;
padding: 25px;
padding: 30px;
background-color: rgb(${colors.white});
border-radius: 6px;
display: flex;
Expand Down
99 changes: 99 additions & 0 deletions src/components/MultipleChoice.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import * as React from "react";
import styled from "styled-components";
import Toggle from "./Toggle";
import Button from "./Button";
import { colors } from "../styles";

const SButton = styled(Button)`
color: rgb(${colors.dark});
text-align: left !important;
`;

const SAbsolute = styled.div`
height: 100%;
top: 0;
bottom: 0;
right: 16px;
position: absolute;
display: flex;
align-items: center;
`;

const SToggle = styled(Toggle)`
& div {
width: 26px;
height: 26px;
}
& div:after {
display: none;
}
`;

interface IMultipleChoiceProps {
choices: any[];
selected: any[];
requiredKeys: string[];
renderItem: (item: any) => any;
onChange: (selected: any[]) => void;
}

function isMatch(item: any, x: any, keys: string[]) {
let match = false;
const matches = keys.filter((key: string) => x[key] === item[key]);
if (matches && matches.length === keys.length) {
match = true;
}
return match;
}

function isActive(item: any, selected: any[], keys: string[]): boolean {
let active = false;
const matches = selected.filter(x => isMatch(item, x, keys));
if (matches && matches.length) {
active = true;
}
return active;
}

function updateSelected(
active: boolean,
item: any,
selected: any[],
keys: any[]
): any[] {
let newSelected = [...selected];
if (active) {
newSelected = selected.filter((x: any) => !isMatch(item, x, keys));
} else {
newSelected = [...selected, item];
}
return newSelected;
}

const MultipleChoice = (props: IMultipleChoiceProps) => {
const { choices, selected, renderItem, requiredKeys, onChange } = props;
return (
<React.Fragment>
{choices.map((item: any, idx: number) => {
const active = isActive(item, selected, requiredKeys);
return (
<SButton
color="white"
marginTop={12}
key={`multiple-choice-${idx}`}
onClick={() =>
onChange(updateSelected(active, item, selected, requiredKeys))
}
>
<React.Fragment>{renderItem(item)}</React.Fragment>
<SAbsolute>
<SToggle active={active} />
</SAbsolute>
</SButton>
);
})}
</React.Fragment>
);
};

export default MultipleChoice;
20 changes: 10 additions & 10 deletions src/components/ProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Input from "../components/Input";
import Button from "../components/Button";
import Dropdown from "../components/Dropdown";
import UploadToIpfs from "../components/UploadToIpfs";
import { IBusinessProfile } from "../helpers/types";
import { IProfile } from "../helpers/types";
import BUSINESS_TYPES from "../constants/businessTypes";
import COUNTRIES from "../constants/countries";

Expand All @@ -19,7 +19,7 @@ const SSubmitWrapper = styled.div`
interface IProfileFormProps {
title?: string;
noLogo?: boolean;
businessProfile: IBusinessProfile;
profile: IProfile;
onInputChange: (input: any) => void;
onInputSubmit?: () => void;
onSubmit?: () => void;
Expand All @@ -29,7 +29,7 @@ const ProfileForm = (props: IProfileFormProps) => {
const {
title,
noLogo,
businessProfile,
profile,
onInputChange,
onInputSubmit,
onSubmit
Expand All @@ -42,7 +42,7 @@ const ProfileForm = (props: IProfileFormProps) => {
<UploadToIpfs
size={200}
label={`Logo`}
image={businessProfile.logo}
image={profile.logo}
onUpload={(logo: string) => {
onInputChange({ logo });
if (onInputSubmit) {
Expand All @@ -56,7 +56,7 @@ const ProfileForm = (props: IProfileFormProps) => {
type="text"
label="Name"
placeholder="Crypto Café"
value={businessProfile.name}
value={profile.name}
onChange={(e: any) => onInputChange({ name: e.target.value })}
onSubmit={() => {
if (onInputSubmit) {
Expand All @@ -69,7 +69,7 @@ const ProfileForm = (props: IProfileFormProps) => {
type="text"
label="Description"
placeholder="Boutique Coffeeshop for Crypto Folks"
value={businessProfile.description}
value={profile.description}
onChange={(e: any) =>
onInputChange({
description: e.target.value
Expand All @@ -84,7 +84,7 @@ const ProfileForm = (props: IProfileFormProps) => {

<Dropdown
label="Type"
selected={businessProfile.type}
selected={profile.type}
options={BUSINESS_TYPES}
displayKey={"display_name"}
targetKey={"type"}
Expand All @@ -100,7 +100,7 @@ const ProfileForm = (props: IProfileFormProps) => {
type="email"
label="Email"
placeholder="contact@cryptocafe.com"
value={businessProfile.email}
value={profile.email}
onChange={(e: any) => onInputChange({ email: e.target.value })}
onSubmit={() => {
if (onInputSubmit) {
Expand All @@ -111,7 +111,7 @@ const ProfileForm = (props: IProfileFormProps) => {

<Dropdown
label="Country"
selected={businessProfile.country}
selected={profile.country}
options={COUNTRIES}
displayKey={"name"}
targetKey={"code"}
Expand All @@ -127,7 +127,7 @@ const ProfileForm = (props: IProfileFormProps) => {
type="text"
label="Phone"
placeholder="+49 03054908166"
value={businessProfile.phone}
value={profile.phone}
onChange={(e: any) => onInputChange({ phone: e.target.value })}
onSubmit={() => {
if (onInputSubmit) {
Expand Down
Loading

0 comments on commit 9d2d352

Please sign in to comment.