aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-10-10 11:26:36 +0300
committereug-vs <eug-vs@keemail.me>2020-10-10 11:26:36 +0300
commit4a8149c0c43419e29cedd5117b6441bf7e6eadcd (patch)
tree38ff8be0fa89472a017b46c3e36dd5563cc9c2af
parent4c73ebe644e7b781fee57bb295f8819bf6568628 (diff)
downloadwhich-ui-4a8149c0c43419e29cedd5117b6441bf7e6eadcd.tar.gz
fix: format 'since' date in ProfileInfo
-rw-r--r--src/containers/Profile/ProfileInfo.tsx13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/containers/Profile/ProfileInfo.tsx b/src/containers/Profile/ProfileInfo.tsx
index 1f5a103..4f2957a 100644
--- a/src/containers/Profile/ProfileInfo.tsx
+++ b/src/containers/Profile/ProfileInfo.tsx
@@ -1,4 +1,4 @@
-import React, { useState, useCallback } from 'react';
+import React, { useState, useCallback, useMemo } from 'react';
import { Badge, Typography, CircularProgress } from '@material-ui/core/';
import { CameraAlt, CheckCircleOutline } from '@material-ui/icons/';
import { makeStyles } from '@material-ui/core/styles';
@@ -92,6 +92,15 @@ const useStyles = makeStyles(theme => ({
}));
+const formatDate = (value: Date | string = ''): string => {
+ const date = new Date(value);
+ const day = ('0' + date.getDate()).slice(-2);
+ const month = ('0' + date.getMonth()).slice(-2);
+ const year = date.getFullYear();
+ return `${year}-${month}-${day}`;
+};
+
+
const ProfileInfo: React.FC<PropTypes> = ({
savedPolls, totalVotes, setUserInfo, userInfo
}) => {
@@ -99,7 +108,7 @@ const ProfileInfo: React.FC<PropTypes> = ({
const { user } = useAuth();
const [progress, setProgress] = useState<number>(0);
- const dateSince = new Date(userInfo?.createdAt || '').toLocaleDateString();
+ const dateSince = useMemo(() => formatDate(userInfo?.createdAt), [userInfo]);
const handleUpdateAvatar = useCallback(async (file: File) => {
if (user) {