diff options
Diffstat (limited to 'src/containers/Profile/ProfileInfo.tsx')
-rw-r--r-- | src/containers/Profile/ProfileInfo.tsx | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/containers/Profile/ProfileInfo.tsx b/src/containers/Profile/ProfileInfo.tsx index 1f5a103..da952e9 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) { |