mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 21:24:23 +08:00
Add Flow types for notifications [SCI-1865]
This commit is contained in:
parent
ea63864b33
commit
6986d11cfe
5 changed files with 34 additions and 27 deletions
|
@ -1,8 +1,15 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Image } from "react-bootstrap";
|
import { Image } from "react-bootstrap";
|
||||||
import PropTypes from "prop-types";
|
|
||||||
|
|
||||||
const NotificationImage = ({className, type, avatar}) => {
|
type Props = {
|
||||||
|
className: string,
|
||||||
|
type: string,
|
||||||
|
avatar: string
|
||||||
|
};
|
||||||
|
|
||||||
|
const NotificationImage = ({className, type, avatar}: Props) => {
|
||||||
const delegator = {
|
const delegator = {
|
||||||
recent_changes: (
|
recent_changes: (
|
||||||
<Image
|
<Image
|
||||||
|
@ -38,10 +45,4 @@ NotificationImage.defaultProps = {
|
||||||
avatar: ''
|
avatar: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
NotificationImage.propTypes = {
|
|
||||||
className: PropTypes.string.isRequired,
|
|
||||||
type: PropTypes.string.isRequired,
|
|
||||||
avatar: PropTypes.string
|
|
||||||
};
|
|
||||||
|
|
||||||
export default NotificationImage;
|
export default NotificationImage;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import PropTypes from "prop-types";
|
|
||||||
import { Col, Row } from "react-bootstrap";
|
import { Col, Row } from "react-bootstrap";
|
||||||
import { FormattedTime } from "react-intl";
|
import { FormattedTime } from "react-intl";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
|
@ -8,13 +9,14 @@ import CustomNavItem from "./CustomNavItem";
|
||||||
import NotificationImage from "./NotificationImage";
|
import NotificationImage from "./NotificationImage";
|
||||||
import {
|
import {
|
||||||
MAIN_COLOR_BLUE,
|
MAIN_COLOR_BLUE,
|
||||||
|
BORDER_GRAY_COLOR,
|
||||||
COLOR_ORANGE,
|
COLOR_ORANGE,
|
||||||
ICON_GREEN_COLOR,
|
ICON_GREEN_COLOR,
|
||||||
WILD_SAND_COLOR
|
WILD_SAND_COLOR
|
||||||
} from "../../../config/constants/colors";
|
} from "../../../config/constants/colors";
|
||||||
|
|
||||||
const StyledListItem = styled(CustomNavItem)`
|
const StyledListItem = styled(CustomNavItem)`
|
||||||
border-bottom: 1px solid #d2d2d2;
|
border-bottom: 1px solid ${BORDER_GRAY_COLOR};
|
||||||
padding-bottom: 10px;
|
padding-bottom: 10px;
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
`;
|
`;
|
||||||
|
@ -63,21 +65,25 @@ const StyledNotificationImage = styled(NotificationImage)`
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const NotificationItem = ({ notification }) => {
|
type Props = {
|
||||||
const { title, message, created_at, type_of, avatarThumb } = notification;
|
notification: Notification,
|
||||||
|
};
|
||||||
|
|
||||||
|
const NotificationItem = ({ notification }: Props) => {
|
||||||
|
const { title, message, createdAt, typeOf, avatarThumb } = notification;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledListItem>
|
<StyledListItem>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={2}>
|
<Col xs={2}>
|
||||||
<StyledNotificationImage type={type_of} avatar={avatarThumb} />
|
<StyledNotificationImage type={typeOf} avatar={avatarThumb} />
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col xs={10}>
|
<Col xs={10}>
|
||||||
<strong dangerouslySetInnerHTML={{ __html: title }} />
|
<strong dangerouslySetInnerHTML={{ __html: title }} />
|
||||||
<br />
|
<br />
|
||||||
<FormattedTime
|
<FormattedTime
|
||||||
value={created_at}
|
value={createdAt}
|
||||||
day="numeric"
|
day="numeric"
|
||||||
month="numeric"
|
month="numeric"
|
||||||
year="numeric"
|
year="numeric"
|
||||||
|
@ -90,14 +96,4 @@ const NotificationItem = ({ notification }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
NotificationItem.propTypes = {
|
|
||||||
notification: PropTypes.shape({
|
|
||||||
id: PropTypes.number.isRequired,
|
|
||||||
title: PropTypes.string.isRequired,
|
|
||||||
message: PropTypes.string.isRequired,
|
|
||||||
type_of: PropTypes.string.isRequired,
|
|
||||||
created_at: PropTypes.string.isRequired
|
|
||||||
}).isRequired
|
|
||||||
};
|
|
||||||
|
|
||||||
export default NotificationItem;
|
export default NotificationItem;
|
||||||
|
|
|
@ -2,8 +2,8 @@ json.array! notifications do |notification|
|
||||||
json.id notification.id
|
json.id notification.id
|
||||||
json.title notification.title
|
json.title notification.title
|
||||||
json.message notification.message
|
json.message notification.message
|
||||||
json.type_of notification.type_of
|
json.typeOf notification.type_of
|
||||||
json.created_at notification.created_at
|
json.createdAt notification.created_at
|
||||||
if notification.type_of == 'recent_changes'
|
if notification.type_of == 'recent_changes'
|
||||||
json.avatarThumb avatar_path(notification.generator_user, :icon_small)
|
json.avatarThumb avatar_path(notification.generator_user, :icon_small)
|
||||||
end
|
end
|
||||||
|
|
9
flow-typed/types.js
vendored
9
flow-typed/types.js
vendored
|
@ -36,6 +36,15 @@ export type Activity = {
|
||||||
created_at: string
|
created_at: string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Notification = {
|
||||||
|
id: number,
|
||||||
|
title: string,
|
||||||
|
message: string,
|
||||||
|
typeOf: string,
|
||||||
|
createdAt: string,
|
||||||
|
avatarThumb: ?string
|
||||||
|
};
|
||||||
|
|
||||||
export type State = {
|
export type State = {
|
||||||
current_team: Teams$Team,
|
current_team: Teams$Team,
|
||||||
all_teams: Array<Teams$Team>,
|
all_teams: Array<Teams$Team>,
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
".eslintrc.json"
|
".eslintrc.json"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"flow": "flow",
|
||||||
"lint": "eslint ."
|
"lint": "eslint ."
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -96,4 +97,4 @@
|
||||||
"webpack-manifest-plugin": "^1.1.2",
|
"webpack-manifest-plugin": "^1.1.2",
|
||||||
"webpack-merge": "^4.1.0"
|
"webpack-merge": "^4.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue