Skip to content

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

Fix DateFormatter

dominik-zeglen35a28de888d8
diff --git a/saleor/static/dashboard-next/components/DateFormatter/DateFormatter.tsx b/saleor/static/dashboard-next/components/DateFormatter/DateFormatter.tsx
index e62a70f714..893163984f 100644
--- a/saleor/static/dashboard-next/components/DateFormatter/DateFormatter.tsx
+++ b/saleor/static/dashboard-next/components/DateFormatter/DateFormatter.tsx
@@ -9,8 +9,7 @@ import { LocaleConsumer } from "../Locale";
import { Consumer } from "./DateContext";
interface DateFormatterProps {
- date: number;
- showTooltip?: boolean;
+ date: string;
locale?: string;
typographyProps?: TypographyProps;
}
@@ -19,7 +18,7 @@ const decorate = withStyles(theme => ({ root: { display: "inline" } }), {
name: "DateFormatter"
});
const DateFormatter = decorate<DateFormatterProps>(
- ({ classes, date, showTooltip = true, typographyProps }) => {
+ ({ classes, date, typographyProps }) => {
return (
<LocaleConsumer>
{locale => (
@@ -30,21 +29,16 @@ const DateFormatter = decorate<DateFormatterProps>(
className={classes.root}
{...typographyProps}
>
- {showTooltip ? (
- <Tooltip
- title={moment(date)
- .toDate()
- .toLocaleString()}
- >
- <ReactMoment from={dateNow} locale={locale}>
- {date}
- </ReactMoment>
- </Tooltip>
- ) : (
+ <Tooltip
+ title={moment(date)
+ .locale(locale)
+ .toDate()
+ .toLocaleString()}
+ >
<ReactMoment from={dateNow} locale={locale}>
{date}
</ReactMoment>
- )}
+ </Tooltip>
</Typography>
)}
</Consumer>
diff --git a/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx b/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx
index 60c3bee0dd..632255cc94 100644
--- a/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx
+++ b/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx
@@ -108,7 +108,7 @@ const CustomerOrders = decorate<CustomerOrdersProps>(
{order.number}
</TableCell>
<TableCell>
- <DateFormatter date={order.created} dateNow={dateNow} />
+ <DateFormatter date={order.created} />
</TableCell>
<TableCell>
<StatusLabel
diff --git a/saleor/static/dashboard-next/index.tsx b/saleor/static/dashboard-next/index.tsx
index 856eaf8ad9..ceb66b252b 100644
--- a/saleor/static/dashboard-next/index.tsx
+++ b/saleor/static/dashboard-next/index.tsx
@@ -15,6 +15,8 @@ import AppRoot from "./AppRoot";
import Auth, { getAuthToken, removeAuthToken } from "./auth";
import AuthProvider from "./auth/AuthProvider";
import CategorySection from "./categories";
+import { DateProvider } from "./components/DateFormatter";
+import { LocaleProvider } from "./components/Locale";
import { MessageManager } from "./components/messages";
import "./i18n";
import PageSection from "./pages";
@@ -64,24 +66,28 @@ render(
<ApolloProvider client={apolloClient}>
<BrowserRouter basename="/dashboard/next/">
<MuiThemeProvider theme={theme}>
- <MessageManager>
- <CssBaseline />
- <AuthProvider>
- {({ isAuthenticated }) => (
- isAuthenticated ? (
- <AppRoot>
- <Switch>
- <Route path="/categories" component={CategorySection} />
- <Route path="/pages" component={PageSection} />
- <Route path="/products" component={ProductSection} />
- </Switch>
- </AppRoot>
- ) : (
- <Route component={Auth} />
- )
- )}
- </AuthProvider>
- </MessageManager>
+ <DateProvider>
+ <LocaleProvider>
+ <MessageManager>
+ <CssBaseline />
+ <AuthProvider>
+ {({ isAuthenticated }) =>
+ isAuthenticated ? (
+ <AppRoot>
+ <Switch>
+ <Route path="/categories" component={CategorySection} />
+ <Route path="/pages" component={PageSection} />
+ <Route path="/products" component={ProductSection} />
+ </Switch>
+ </AppRoot>
+ ) : (
+ <Route component={Auth} />
+ )
+ }
+ </AuthProvider>
+ </MessageManager>
+ </LocaleProvider>
+ </DateProvider>
</MuiThemeProvider>
</BrowserRouter>
</ApolloProvider>,
diff --git a/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx b/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx
index 45ca828c42..9cfc686927 100644
--- a/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx
@@ -101,7 +101,6 @@ interface OrderDetailsPageProps {
net: MoneyType;
};
};
- dateNow?: number;
shippingMethods?: Array<{
id: string;
name: string;
@@ -225,7 +224,6 @@ class OrderDetailsPageComponent extends React.Component<
const {
classes,
countries,
- dateNow,
order,
prefixes,
shippingMethods,
@@ -282,7 +280,6 @@ class OrderDetailsPageComponent extends React.Component<
<div className={classes.orderDate}>
<DateFormatter
date={order.created}
- dateNow={dateNow}
typographyProps={{ variant: "caption" }}
/>
</div>
diff --git a/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx b/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx
index ff040af6f0..96edaf4e0a 100644
--- a/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx
@@ -37,7 +37,6 @@ interface OrderListProps extends ListProps {
currency: string;
};
}>;
- dateNow?: number;
}
const decorate = withStyles(
@@ -59,7 +58,6 @@ const decorate = withStyles(
export const OrderList = decorate<OrderListProps>(
({
classes,
- dateNow,
disabled,
orders,
pageInfo,
@@ -137,7 +135,7 @@ export const OrderList = decorate<OrderListProps>(
</TableCell>
<TableCell>{order.client.email}</TableCell>
<TableCell>
- <DateFormatter date={order.created} dateNow={dateNow} />
+ <DateFormatter date={order.created} />
</TableCell>
<TableCell>
<StatusLabel
diff --git a/saleor/static/dashboard-next/orders/components/OrderListPage/OrderListPage.tsx b/saleor/static/dashboard-next/orders/components/OrderListPage/OrderListPage.tsx
index cd52451081..fdb971d511 100644
--- a/saleor/static/dashboard-next/orders/components/OrderListPage/OrderListPage.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderListPage/OrderListPage.tsx
@@ -25,11 +25,9 @@ interface OrderListPageProps extends PageListProps {
currency: string;
};
}>;
- dateNow?: number;
}
const OrderListPage: React.StatelessComponent<OrderListPageProps> = ({
- dateNow,
disabled,
orders,
pageInfo,
@@ -58,7 +56,6 @@ const OrderListPage: React.StatelessComponent<OrderListPageProps> = ({
</Button>
</PageHeader>
<OrderList
- dateNow={dateNow}
disabled={disabled}
onRowClick={onRowClick}
orders={orderList}
diff --git a/saleor/static/dashboard-next/pages/components/PageProperties/PageProperties.tsx b/saleor/static/dashboard-next/pages/components/PageProperties/PageProperties.tsx
index 488b93fc32..99a383cb71 100644
--- a/saleor/static/dashboard-next/pages/components/PageProperties/PageProperties.tsx
+++ b/saleor/static/dashboard-next/pages/components/PageProperties/PageProperties.tsx
@@ -78,7 +78,7 @@ const PageProperties = decorate<PagePropertiesProps>(
{created && (
<div>
<Typography variant="body1">{i18n.t("Created:")} </Typography>
- <DateFormatter date={parseInt(created, 10)} />
+ <DateFormatter date={created} />
</div>
)}
<FormSpacer />