Skip to content

Commit 336e933

Browse files
committed
Notifications page design & notification component
1 parent c36864a commit 336e933

File tree

9 files changed

+449
-211
lines changed

9 files changed

+449
-211
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"recharts": "^1.5.0",
2424
"recompose": "^0.30.0",
2525
"redux": "^4.0.1",
26-
"redux-thunk": "^2.3.0"
26+
"redux-thunk": "^2.3.0",
27+
"tinycolor2": "^1.4.1"
2728
},
2829
"scripts": {
2930
"start": "react-scripts start",

src/components/Header/HeaderView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ const Header = ({ classes, isSidebarOpened, toggleSidebar, ...props }) => (
234234
onClick={props.closeNotificationsMenu}
235235
className={classes.headerMenuItem}
236236
>
237-
<Notification {...notification} />
237+
<Notification {...notification} typographyVariant="inherit" />
238238
</MenuItem>
239239
))}
240240
</Menu>
Lines changed: 101 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,91 @@
11
import React from "react";
2-
import { Typography, withStyles } from "@material-ui/core";
2+
import { Button, withStyles } from "@material-ui/core";
33
import {
44
NotificationsNone as NotificationsIcon,
55
ThumbUp as ThumbUpIcon,
66
ShoppingCart as ShoppingCartIcon,
7-
LocalOffer as TicketIcon
7+
LocalOffer as TicketIcon,
8+
BusinessCenter as DeliveredIcon,
9+
SmsFailed as FeedbackIcon,
10+
DiscFull as DiscIcon,
11+
Email as MessageIcon,
12+
Report as ReportIcon,
13+
Error as DefenceIcon,
14+
AccountBox as CustomerIcon,
15+
Done as ShippedIcon,
16+
Publish as UploadIcon,
817
} from "@material-ui/icons";
18+
import classnames from "classnames";
19+
import tinycolor from 'tinycolor2';
20+
21+
import { Typography } from "../Wrappers";
922

1023
const typesIcons = {
1124
"e-commerce": <ShoppingCartIcon />,
1225
notification: <NotificationsIcon />,
1326
offer: <TicketIcon />,
14-
info: <ThumbUpIcon />
27+
info: <ThumbUpIcon />,
28+
message: <MessageIcon />,
29+
feedback: <FeedbackIcon />,
30+
customer: <CustomerIcon />,
31+
shipped: <ShippedIcon />,
32+
delivered: <DeliveredIcon />,
33+
defence: <DefenceIcon />,
34+
report: <ReportIcon />,
35+
upload: <UploadIcon />,
36+
disc: <DiscIcon />,
1537
};
1638

1739
const getIconByType = (type = "offer") => typesIcons[type];
1840

19-
const Notification = ({ classes, theme, ...props }) => {
41+
const Notification = ({ classes, theme, variant, ...props }) => {
2042
const icon = getIconByType(props.type);
2143
const iconWithStyles = React.cloneElement(icon, {
2244
classes: {
2345
root: classes.notificationIcon
2446
},
2547
style: {
26-
color: theme.palette[props.color] && theme.palette[props.color].main,
48+
color: variant !== "contained" && theme.palette[props.color] && theme.palette[props.color].main
2749
}
2850
});
2951

3052
return (
31-
<div className={classes.notificationContainer}>
32-
{iconWithStyles}
33-
<Typography variant="inherit">{props.message}</Typography>
53+
<div
54+
className={classnames(classes.notificationContainer, props.className, {
55+
[classes.notificationContained]: variant === "contained",
56+
[classes.notificationContainedShadowless]: props.shadowless,
57+
})}
58+
style={{
59+
backgroundColor:
60+
variant === "contained" &&
61+
theme.palette[props.color] &&
62+
theme.palette[props.color].main
63+
}}
64+
>
65+
<div
66+
className={classnames(classes.notificationIconContainer, {
67+
[classes.notificationIconContainerContained]: variant === "contained",
68+
[classes.notificationIconContainerRounded]: variant === "rounded",
69+
}
70+
)}
71+
style={{
72+
backgroundColor: variant === "rounded" &&
73+
theme.palette[props.color] &&
74+
tinycolor(theme.palette[props.color].main).setAlpha(0.15).toRgbString()
75+
}}
76+
>{iconWithStyles}</div>
77+
<div className={classes.messageContainer}>
78+
<Typography
79+
className={classnames({
80+
[classes.containedTypography]: variant === "contained"
81+
})}
82+
variant={props.typographyVariant}
83+
size={variant !== "contained" && !props.typographyVariant && "md"}
84+
>
85+
{props.message}
86+
</Typography>
87+
{props.extraButton && props.extraButtonClick && (<Button onClick={props.extraButtonClick} disableRipple className={classes.extraButton}>{props.extraButton}</Button>)}
88+
</div>
3489
</div>
3590
);
3691
};
@@ -40,10 +95,45 @@ const styles = theme => ({
4095
display: "flex",
4196
alignItems: "center"
4297
},
43-
notificationIcon: {
98+
notificationContained: {
99+
borderRadius: 45,
100+
height: 45,
101+
boxShadow: theme.customShadows.widgetDark
102+
},
103+
notificationContainedShadowless: {
104+
boxShadow: 'none',
105+
},
106+
notificationIconContainer: {
107+
width: 45,
108+
height: 45,
109+
borderRadius: 45,
110+
display: 'flex',
111+
alignItems: 'center',
112+
justifyContent: 'center',
113+
fontSize: 24,
114+
},
115+
notificationIconContainerContained: {
44116
fontSize: 18,
45-
marginRight: theme.spacing.unit * 2
46-
}
117+
color: '#FFFFFF80',
118+
},
119+
notificationIconContainerRounded: {
120+
marginRight: theme.spacing.unit * 2,
121+
},
122+
containedTypography: {
123+
color: "white"
124+
},
125+
messageContainer: {
126+
display: 'flex',
127+
alignItems: 'center',
128+
justifyContent: 'space-between',
129+
flexGrow: 1,
130+
},
131+
extraButton: {
132+
color: 'white',
133+
'&:hover, &:focus': {
134+
background: 'transparent',
135+
}
136+
},
47137
});
48138

49139
export default withStyles(styles, { withTheme: true })(Notification);
Lines changed: 77 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,140 @@
11
import React from "react";
2-
import { withStyles, withTheme, Badge as BadgeBase, Typography as TypographyBase } from "@material-ui/core";
2+
import {
3+
withStyles,
4+
withTheme,
5+
Badge as BadgeBase,
6+
Typography as TypographyBase,
7+
Button as ButtonBase
8+
} from "@material-ui/core";
39
import classnames from "classnames";
410

5-
const getColor = (color, theme, brigtness = 'main') => {
11+
const getColor = (color, theme, brigtness = "main") => {
612
if (color && theme.palette[color] && theme.palette[color][brigtness]) {
7-
return theme.palette[color][brigtness];
13+
return theme.palette[color][brigtness];
814
}
915
};
1016

11-
const getFontWeight = (style) => {
17+
const getFontWeight = style => {
1218
switch (style) {
13-
case 'light':
19+
case "light":
1420
return 300;
15-
case 'medium':
21+
case "medium":
1622
return 500;
17-
case 'bold':
23+
case "bold":
1824
return 600;
1925
default:
2026
return 400;
2127
}
2228
};
2329

24-
const getFontSize = (size, variant = '', theme) => {
30+
const getFontSize = (size, variant = "", theme) => {
2531
let multiplier;
2632

2733
switch (size) {
28-
case 'sm':
29-
multiplier = .8;
34+
case "sm":
35+
multiplier = 0.8;
3036
break;
31-
case 'md':
37+
case "md":
3238
multiplier = 1.5;
3339
break;
34-
case 'xl':
40+
case "xl":
3541
multiplier = 2;
3642
break;
37-
case 'xxl':
43+
case "xxl":
3844
multiplier = 3;
3945
break;
4046
default:
4147
multiplier = 1;
4248
break;
4349
}
4450

45-
const defaultSize = variant && theme.typography[variant] ? theme.typography[variant].fontSize : theme.typography.fontSize + 'px';
51+
const defaultSize =
52+
variant && theme.typography[variant]
53+
? theme.typography[variant].fontSize
54+
: theme.typography.fontSize + "px";
4655

4756
return `calc(${defaultSize} * ${multiplier})`;
48-
}
57+
};
4958

5059
const createStyled = (styles, options) => {
5160
const Styled = props => {
5261
const { children, ...other } = props;
5362
return children(other);
54-
}
55-
63+
};
64+
5665
return withStyles(styles, options)(Styled);
57-
}
66+
};
5867

5968
const BadgeExtended = ({ classes, theme, children, ...props }) => {
6069
const Styled = createStyled({
6170
badge: {
62-
backgroundColor: getColor(props.color, theme, props.colorBrightness)
63-
},
71+
backgroundColor: getColor(props.color, theme, props.colorBrightness)
72+
}
6473
});
6574

6675
return (
6776
<Styled>
68-
{(styledProps) => <BadgeBase
69-
classes={{ badge: classnames(classes.badge, styledProps.classes.badge) }}
70-
{...props}
71-
>
72-
{children}
73-
</BadgeBase>}
77+
{styledProps => (
78+
<BadgeBase
79+
classes={{
80+
badge: classnames(classes.badge, styledProps.classes.badge)
81+
}}
82+
{...props}
83+
>
84+
{children}
85+
</BadgeBase>
86+
)}
7487
</Styled>
7588
);
76-
}
89+
};
7790

78-
export const Badge = withStyles(theme => ({
79-
badge: {
80-
fontWeight: 600,
81-
height: 16,
82-
minWidth: 16,
83-
},
84-
}), { withTheme: true })(BadgeExtended);
91+
export const Badge = withStyles(
92+
theme => ({
93+
badge: {
94+
fontWeight: 600,
95+
height: 16,
96+
minWidth: 16
97+
}
98+
}),
99+
{ withTheme: true }
100+
)(BadgeExtended);
85101

86102
const TypographyExtended = ({ theme, children, weight, size, ...props }) => (
87103
<TypographyBase
88104
style={{
89105
color: getColor(props.color, theme, props.colorBrightness),
90106
fontWeight: getFontWeight(weight),
91-
fontSize: getFontSize(size, props.variant, theme),
107+
fontSize: getFontSize(size, props.variant, theme)
92108
}}
93109
{...props}
94110
>
95111
{children}
96112
</TypographyBase>
97113
);
98114

99-
export const Typography = withTheme()(TypographyExtended);
115+
export const Typography = withTheme()(TypographyExtended);
116+
117+
const ButtonExtended = ({ theme, children, ...props }) => {
118+
const Styled = createStyled({
119+
button: {
120+
backgroundColor: getColor(props.color, theme),
121+
boxShadow: theme.customShadows.widget,
122+
'&:hover': {
123+
backgroundColor: getColor(props.color, theme, 'light'),
124+
boxShadow: theme.customShadows.widgetWide,
125+
}
126+
}
127+
});
128+
129+
return (
130+
<Styled>
131+
{({ classes }) => (
132+
<ButtonBase classes={{ root: classes.button }} {...props}>
133+
{children}
134+
</ButtonBase>
135+
)}
136+
</Styled>
137+
);
138+
};
139+
140+
export const Button = withTheme()(ButtonExtended);

src/pages/login/LoginState.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const initialState = {
22
isLoading: false,
3-
isAuthenticated: false,
3+
isAuthenticated: !!localStorage.getItem("id_token"),
44
error: null
55
};
66

0 commit comments

Comments
 (0)