Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Split date and datetime components

dominik-zeglena0dfe5fa99c2
diff --git a/saleor/static/dashboard-next/components/DateFormatter/DateFormatter.tsx b/saleor/static/dashboard-next/components/Date/Date.tsx
similarity index 55%
rename from saleor/static/dashboard-next/components/DateFormatter/DateFormatter.tsx
rename to saleor/static/dashboard-next/components/Date/Date.tsx
index 83f69374b7..ee17d4b40e 100644
--- a/saleor/static/dashboard-next/components/DateFormatter/DateFormatter.tsx
+++ b/saleor/static/dashboard-next/components/Date/Date.tsx
@@ -7,19 +7,18 @@ import { LocaleConsumer } from "../Locale";
import { TimezoneConsumer } from "../Timezone";
import { Consumer } from "./DateContext";
-interface DateFormatterProps {
+interface DateProps {
date: string;
+ plain?: boolean;
}
-const DateFormatter: React.StatelessComponent<DateFormatterProps> = ({
- date
-}) => {
+const Date: React.StatelessComponent<DateProps> = ({ date, plain }) => {
const getTitle = (value: string, locale?: string, tz?: string) => {
let date = moment(value).locale(locale);
if (tz !== undefined) {
date = date.tz(tz);
}
- return date.toLocaleString();
+ return date.format("LL");
};
return (
<LocaleConsumer>
@@ -27,13 +26,17 @@ const DateFormatter: React.StatelessComponent<DateFormatterProps> = ({
<TimezoneConsumer>
{tz => (
<Consumer>
- {currentDate => (
- <Tooltip title={getTitle(date, locale, tz)}>
- <ReactMoment from={currentDate} locale={locale} tz={tz}>
- {date}
- </ReactMoment>
- </Tooltip>
- )}
+ {currentDate =>
+ plain ? (
+ getTitle(date, locale, tz)
+ ) : (
+ <Tooltip title={getTitle(date, locale, tz)}>
+ <ReactMoment from={currentDate} locale={locale} tz={tz}>
+ {date}
+ </ReactMoment>
+ </Tooltip>
+ )
+ }
</Consumer>
)}
</TimezoneConsumer>
@@ -41,5 +44,5 @@ const DateFormatter: React.StatelessComponent<DateFormatterProps> = ({
</LocaleConsumer>
);
};
-DateFormatter.displayName = "DateFormatter";
-export default DateFormatter;
+Date.displayName = "Date";
+export default Date;
diff --git a/saleor/static/dashboard-next/components/DateFormatter/DateContext.tsx b/saleor/static/dashboard-next/components/Date/DateContext.tsx
similarity index 100%
rename from saleor/static/dashboard-next/components/DateFormatter/DateContext.tsx
rename to saleor/static/dashboard-next/components/Date/DateContext.tsx
diff --git a/saleor/static/dashboard-next/components/DateFormatter/DateProvider.tsx b/saleor/static/dashboard-next/components/Date/DateProvider.tsx
similarity index 100%
rename from saleor/static/dashboard-next/components/DateFormatter/DateProvider.tsx
rename to saleor/static/dashboard-next/components/Date/DateProvider.tsx
diff --git a/saleor/static/dashboard-next/components/Date/DateTime.tsx b/saleor/static/dashboard-next/components/Date/DateTime.tsx
new file mode 100644
index 0000000000..774fb40737
--- /dev/null
+++ b/saleor/static/dashboard-next/components/Date/DateTime.tsx
@@ -0,0 +1,51 @@
+import Tooltip from "@material-ui/core/Tooltip";
+import * as moment from "moment-timezone";
+import * as React from "react";
+import ReactMoment from "react-moment";
+
+import { LocaleConsumer } from "../Locale";
+import { TimezoneConsumer } from "../Timezone";
+import { Consumer } from "./DateContext";
+
+interface DateTimeProps {
+ date: string;
+ plain?: boolean;
+}
+
+export const DateTime: React.StatelessComponent<DateTimeProps> = ({
+ date,
+ plain
+}) => {
+ const getTitle = (value: string, locale?: string, tz?: string) => {
+ let date = moment(value).locale(locale);
+ if (tz !== undefined) {
+ date = date.tz(tz);
+ }
+ return date.format("lll");
+ };
+ return (
+ <LocaleConsumer>
+ {locale => (
+ <TimezoneConsumer>
+ {tz => (
+ <Consumer>
+ {currentDate =>
+ plain ? (
+ getTitle(date, locale, tz)
+ ) : (
+ <Tooltip title={getTitle(date, locale, tz)}>
+ <ReactMoment from={currentDate} locale={locale} tz={tz}>
+ {date}
+ </ReactMoment>
+ </Tooltip>
+ )
+ }
+ </Consumer>
+ )}
+ </TimezoneConsumer>
+ )}
+ </LocaleConsumer>
+ );
+};
+DateTime.displayName = "DateTime";
+export default DateTime;
diff --git a/saleor/static/dashboard-next/components/Date/index.ts b/saleor/static/dashboard-next/components/Date/index.ts
new file mode 100644
index 0000000000..a969a978fd
--- /dev/null
+++ b/saleor/static/dashboard-next/components/Date/index.ts
@@ -0,0 +1,4 @@
+export { default } from "./Date";
+export * from "./Date";
+export * from "./DateTime";
+export * from "./DateProvider";
diff --git a/saleor/static/dashboard-next/components/DateFormatter/index.ts b/saleor/static/dashboard-next/components/DateFormatter/index.ts
deleted file mode 100644
index 6d136ef6d8..0000000000
--- a/saleor/static/dashboard-next/components/DateFormatter/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export { default } from "./DateFormatter";
-export * from "./DateFormatter";
-export * from "./DateProvider";
diff --git a/saleor/static/dashboard-next/components/Timeline/TimelineEvent.tsx b/saleor/static/dashboard-next/components/Timeline/TimelineEvent.tsx
index 7a047c0966..e137085ada 100644
--- a/saleor/static/dashboard-next/components/Timeline/TimelineEvent.tsx
+++ b/saleor/static/dashboard-next/components/Timeline/TimelineEvent.tsx
@@ -12,7 +12,7 @@ import Typography from "@material-ui/core/Typography";
import ExpandMoreIcon from "@material-ui/icons/ExpandMore";
import * as React from "react";
-import DateFormatter from "../DateFormatter";
+import { DateTime } from "../Date";
const styles = (theme: Theme) =>
createStyles({
@@ -89,7 +89,7 @@ export const TimelineEvent = withStyles(styles)(
<div className={classes.noExpander}>
<Typography>{title}</Typography>
<Typography>
- <DateFormatter date={date} />
+ <DateTime date={date} />
</Typography>
</div>
)}
diff --git a/saleor/static/dashboard-next/components/Timeline/TimelineNote.tsx b/saleor/static/dashboard-next/components/Timeline/TimelineNote.tsx
index 93a8ac121f..4059a7bd6c 100644
--- a/saleor/static/dashboard-next/components/Timeline/TimelineNote.tsx
+++ b/saleor/static/dashboard-next/components/Timeline/TimelineNote.tsx
@@ -13,7 +13,7 @@ import PersonIcon from "@material-ui/icons/Person";
import * as CRC from "crc-32";
import * as React from "react";
-import DateFormatter from "../DateFormatter";
+import { DateTime } from "../Date";
import Hr from "../Hr";
const palette = [
@@ -88,7 +88,7 @@ export const TimelineNote = withStyles(styles, { name: "TimelineNote" })(
<div className={classes.title}>
<Typography>{user.email}</Typography>
<Typography>
- <DateFormatter date={date} />
+ <DateTime date={date} />
</Typography>
</div>
<Hr />
diff --git a/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx b/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx
index 69e49e1b75..75a471840f 100644
--- a/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx
+++ b/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx
@@ -9,7 +9,7 @@ import TableRow from "@material-ui/core/TableRow";
import * as React from "react";
import CardTitle from "../../../components/CardTitle";
-import DateFormatter from "../../../components/DateFormatter";
+import { DateTime } from "../../../components/Date";
import Money from "../../../components/Money";
import Skeleton from "../../../components/Skeleton";
import StatusLabel from "../../../components/StatusLabel";
@@ -95,7 +95,7 @@ const CustomerOrders = withStyles(styles, { name: "CustomerOrders" })(
</TableCell>
<TableCell padding="dense">
{maybe(() => order.created) ? (
- <DateFormatter date={order.created} />
+ <DateTime date={order.created} />
) : (
<Skeleton />
)}
diff --git a/saleor/static/dashboard-next/customers/components/CustomerStats/CustomerStats.tsx b/saleor/static/dashboard-next/customers/components/CustomerStats/CustomerStats.tsx
index f750be5a60..c8b400595a 100644
--- a/saleor/static/dashboard-next/customers/components/CustomerStats/CustomerStats.tsx
+++ b/saleor/static/dashboard-next/customers/components/CustomerStats/CustomerStats.tsx
@@ -10,7 +10,7 @@ import Typography from "@material-ui/core/Typography";
import * as React from "react";
import CardTitle from "../../../components/CardTitle";
-import DateFormatter from "../../../components/DateFormatter";
+import { DateTime } from "../../../components/Date";
import { Hr } from "../../../components/Hr";
import Skeleton from "../../../components/Skeleton";
import i18n from "../../../i18n";
@@ -46,7 +46,7 @@ const CustomerStats = withStyles(styles, { name: "CustomerStats" })(
{customer.lastLogin === null ? (
i18n.t("-")
) : (
- <DateFormatter date={customer.lastLogin} />
+ <DateTime date={customer.lastLogin} />
)}
</Typography>
),
@@ -64,7 +64,7 @@ const CustomerStats = withStyles(styles, { name: "CustomerStats" })(
{customer.lastPlacedOrder.edges.length === 0 ? (
i18n.t("-")
) : (
- <DateFormatter
+ <DateTime
date={customer.lastPlacedOrder.edges[0].node.created}
/>
)}
diff --git a/saleor/static/dashboard-next/home/components/HomeActivityCard/HomeActivityCard.tsx b/saleor/static/dashboard-next/home/components/HomeActivityCard/HomeActivityCard.tsx
index 52b3890416..daf291d838 100644
--- a/saleor/static/dashboard-next/home/components/HomeActivityCard/HomeActivityCard.tsx
+++ b/saleor/static/dashboard-next/home/components/HomeActivityCard/HomeActivityCard.tsx
@@ -7,7 +7,7 @@ import Typography from "@material-ui/core/Typography";
import * as React from "react";
import CardTitle from "../../../components/CardTitle";
-import DateFormatter from "../../../components/DateFormatter";
+import { DateTime } from "../../../components/Date";
import Skeleton from "../../../components/Skeleton";
import i18n from "../../../i18n";
import { renderCollection } from "../../../misc";
@@ -44,7 +44,7 @@ const HomeProductListCard = withStyles(styles, { name: "HomeProductListCard" })(
primary={
<Typography>{getActivityMessage(activity)}</Typography>
}
- secondary={<DateFormatter date={activity.date} />}
+ secondary={<DateTime date={activity.date} />}
/>
) : (
<ListItemText className={classes.loadingProducts}>
diff --git a/saleor/static/dashboard-next/index.tsx b/saleor/static/dashboard-next/index.tsx
index 997e772407..4b04a61bb9 100644
--- a/saleor/static/dashboard-next/index.tsx
+++ b/saleor/static/dashboard-next/index.tsx
@@ -23,7 +23,7 @@ import CategorySection from "./categories";
import CollectionSection from "./collections";
import { AppProgressProvider } from "./components/AppProgress";
// import { ConfirmFormLeaveDialog } from "./components/ConfirmFormLeaveDialog";
-import { DateProvider } from "./components/DateFormatter";
+import { DateProvider } from "./components/Date";
import { FormProvider } from "./components/Form";
import { LocaleProvider } from "./components/Locale";
import { MessageManager } from "./components/messages";
diff --git a/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx b/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx
index 8243472ff5..ca6a36f7e7 100644
--- a/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx
@@ -10,7 +10,7 @@ import * as React from "react";
import { CardMenu } from "../../../components/CardMenu/CardMenu";
import { CardSpacer } from "../../../components/CardSpacer";
import { Container } from "../../../components/Container";
-import DateFormatter from "../../../components/DateFormatter";
+import { DateTime } from "../../../components/Date";
import Grid from "../../../components/Grid";
import PageHeader from "../../../components/PageHeader";
import Skeleton from "../../../components/Skeleton";
@@ -110,7 +110,7 @@ const OrderDetailsPage = withStyles(styles, { name: "OrderDetailsPage" })(
<div className={classes.date}>
{order && order.created ? (
<Typography variant="caption">
- <DateFormatter date={order.created} />
+ <DateTime date={order.created} />
</Typography>
) : (
<Skeleton style={{ width: "10em" }} />
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx b/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx
index 2322290cc4..4190c8f5fc 100644
--- a/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx
@@ -10,7 +10,7 @@ import * as React from "react";
import { CardMenu } from "../../../components/CardMenu/CardMenu";
import { ConfirmButtonTransitionState } from "../../../components/ConfirmButton/ConfirmButton";
import { Container } from "../../../components/Container";
-import DateFormatter from "../../../components/DateFormatter";
+import { DateTime } from "../../../components/Date";
import Grid from "../../../components/Grid";
import PageHeader from "../../../components/PageHeader";
import SaveButtonBar from "../../../components/SaveButtonBar";
@@ -107,7 +107,7 @@ const OrderDraftPage = withStyles(styles, { name: "OrderDraftPage" })(
<div className={classes.date}>
{order && order.created ? (
<Typography variant="caption">
- <DateFormatter date={order.created} />
+ <DateTime date={order.created} />
</Typography>
) : (
<Skeleton style={{ width: "10em" }} />
diff --git a/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx b/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx
index 86c76629cb..d75dd30342 100644
--- a/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx
@@ -7,7 +7,7 @@ import TableHead from "@material-ui/core/TableHead";
import TableRow from "@material-ui/core/TableRow";
import * as React from "react";
-import DateFormatter from "../../../components/DateFormatter";
+import { DateTime } from "../../../components/Date";
import Money from "../../../components/Money";
import Skeleton from "../../../components/Skeleton";
import StatusLabel from "../../../components/StatusLabel";
@@ -108,7 +108,7 @@ export const OrderList = withStyles(styles, { name: "OrderList" })(
</TableCell>
<TableCell padding="dense">
{maybe(() => order.created) ? (
- <DateFormatter date={order.created} />
+ <DateTime date={order.created} />
) : (
<Skeleton />
)}
diff --git a/saleor/static/dashboard-next/pages/components/PageProperties/PageProperties.tsx b/saleor/static/dashboard-next/pages/components/PageProperties/PageProperties.tsx
index 6d9cfc10e8..2cdef903f5 100644
--- a/saleor/static/dashboard-next/pages/components/PageProperties/PageProperties.tsx
+++ b/saleor/static/dashboard-next/pages/components/PageProperties/PageProperties.tsx
@@ -5,7 +5,7 @@ import Typography from "@material-ui/core/Typography";
import * as React from "react";
import ControlledCheckbox from "../../../components/ControlledCheckbox";
-import DateFormatter from "../../../components/DateFormatter";
+import { DateTime } from "../../../components/Date";
import FormSpacer from "../../../components/FormSpacer";
import i18n from "../../../i18n";
@@ -74,7 +74,7 @@ const PageProperties: React.StatelessComponent<PagePropertiesProps> = ({
{created && (
<div>
<Typography variant="body1">
- {i18n.t("Created:")} <DateFormatter date={created} />
+ {i18n.t("Created:")} <DateTime date={created} />
</Typography>
</div>
)}
diff --git a/saleor/static/dashboard-next/storybook/Decorator.tsx b/saleor/static/dashboard-next/storybook/Decorator.tsx
index 6feb2d5c1b..a3639b16c9 100644
--- a/saleor/static/dashboard-next/storybook/Decorator.tsx
+++ b/saleor/static/dashboard-next/storybook/Decorator.tsx
@@ -2,7 +2,7 @@ import CssBaseline from "@material-ui/core/CssBaseline";
import MuiThemeProvider from "@material-ui/core/styles/MuiThemeProvider";
import * as React from "react";
-import { Provider as DateProvider } from "../components/DateFormatter/DateContext";
+import { Provider as DateProvider } from "../components/Date/DateContext";
import { FormProvider } from "../components/Form";
import { MessageManager } from "../components/messages";
import { TimezoneProvider } from "../components/Timezone";
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index b6a1b6c58f..7c8d988aa0 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -7,7 +7,8 @@ function loadStories() {
require("./stories/components/AddressEdit");
require("./stories/components/AddressFormatter");
require("./stories/components/CardMenu");
- require("./stories/components/DateFormatter");
+ require("./stories/components/Date");
+ require("./stories/components/DateTime");
require("./stories/components/EditableTableCell");
require("./stories/components/ErrorMessageCard");
require("./stories/components/ErrorPage");
diff --git a/saleor/static/dashboard-next/storybook/stories/components/Date.tsx b/saleor/static/dashboard-next/storybook/stories/components/Date.tsx
new file mode 100644
index 0000000000..560c7bb1e2
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/components/Date.tsx
@@ -0,0 +1,10 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import Date from "../../../components/Date";
+import Decorator from "../../Decorator";
+
+storiesOf("Generics / Date", module)
+ .addDecorator(Decorator)
+ .add("default", () => <Date date="2018-04-07T10:44:44+00:00" />)
+ .add("plain", () => <Date date="2018-04-07T10:44:44+00:00" plain={true} />);
diff --git a/saleor/static/dashboard-next/storybook/stories/components/DateFormatter.tsx b/saleor/static/dashboard-next/storybook/stories/components/DateFormatter.tsx
deleted file mode 100644
index 77aa7486d7..0000000000
--- a/saleor/static/dashboard-next/storybook/stories/components/DateFormatter.tsx
+++ /dev/null
@@ -1,9 +0,0 @@
-import { storiesOf } from "@storybook/react";
-import * as React from "react";
-
-import DateFormatter from "../../../components/DateFormatter";
-import Decorator from "../../Decorator";
-
-storiesOf("Generics / DateFormatter", module)
- .addDecorator(Decorator)
- .add("default", () => <DateFormatter date="2018-04-07T10:44:44+00:00" />);
diff --git a/saleor/static/dashboard-next/storybook/stories/components/DateTime.tsx b/saleor/static/dashboard-next/storybook/stories/components/DateTime.tsx
new file mode 100644
index 0000000000..ecdb248391
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/components/DateTime.tsx
@@ -0,0 +1,12 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import { DateTime } from "../../../components/Date";
+import Decorator from "../../Decorator";
+
+storiesOf("Generics / DateTime", module)
+ .addDecorator(Decorator)
+ .add("default", () => <DateTime date="2018-04-07T10:44:44+00:00" />)
+ .add("plain", () => (
+ <DateTime date="2018-04-07T10:44:44+00:00" plain={true} />
+ ));
diff --git a/saleor/static/dashboard-next/vouchers/components/VoucherList/VoucherList.tsx b/saleor/static/dashboard-next/vouchers/components/VoucherList/VoucherList.tsx
index d7b31ad19f..1a79d28b10 100644
--- a/saleor/static/dashboard-next/vouchers/components/VoucherList/VoucherList.tsx
+++ b/saleor/static/dashboard-next/vouchers/components/VoucherList/VoucherList.tsx
@@ -14,7 +14,7 @@ import TableRow from "@material-ui/core/TableRow";
import * as React from "react";
import { createVoucherName, VoucherType } from "../..";
-import DateFormatter from "../../../components/DateFormatter";
+import Date from "../../../components/Date";
import Money from "../../../components/Money";
import Percent from "../../../components/Percent";
import Skeleton from "../../../components/Skeleton";
@@ -124,7 +124,7 @@ const VoucherList = withStyles(styles, { name: "VoucherList" })(
<TableCell>
{voucher ? (
voucher.startDate !== null ? (
- <DateFormatter date={voucher.startDate} />
+ <Date date={voucher.startDate} />
) : (
"-"
)
@@ -135,7 +135,7 @@ const VoucherList = withStyles(styles, { name: "VoucherList" })(
<TableCell>
{voucher ? (
voucher.endDate !== null ? (
- <DateFormatter date={voucher.endDate} />
+ <Date date={voucher.endDate} />
) : (
"-"
)