Skip to content

Commit 2ff8c3e

Browse files
committed
MP-128 member location and local time
1 parent 43ecd22 commit 2ff8c3e

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"apexcharts": "^3.36.0",
3333
"axios": "^1.1.2",
3434
"browser-cookies": "^1.2.0",
35+
"city-timezones": "^1.2.1",
3536
"classnames": "^2.3.2",
3637
"contentful": "^9.2.5",
3738
"country-calling-code": "0.0.3",

src/apps/profiles/src/member-profile/local-info/MemberLocalInfo.tsx

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { FC } from 'react'
1+
import { FC, useMemo } from 'react'
2+
import cityTimezones from 'city-timezones'
23
import moment from 'moment-timezone'
34

45
import { useCountryName, UserProfile } from '~/libs/core'
@@ -12,22 +13,46 @@ interface MemberLocalInfoProps {
1213

1314
const MemberLocalInfo: FC<MemberLocalInfoProps> = (props: MemberLocalInfoProps) => {
1415

15-
const memberCountry: string | undefined = useCountryName(props.profile?.homeCountryCode)
16+
const memberCountry: string | undefined
17+
= useCountryName(props.profile?.homeCountryCode || props.profile?.competitionCountryCode)
18+
19+
const city: string | undefined = props.profile?.addresses?.[0]?.city
20+
21+
const memberCityTimezone: string | undefined = useMemo(() => {
22+
if (!city) {
23+
return undefined
24+
}
25+
26+
const cityTimezoneData: cityTimezones.CityData[] = cityTimezones.lookupViaCity(city)
27+
let memberTimezone: string | undefined
28+
29+
if (!cityTimezoneData?.length) {
30+
memberTimezone = `${memberCountry}/${city}`
31+
} else {
32+
memberTimezone = cityTimezoneData[0].timezone
33+
}
34+
35+
return moment.tz.zone(memberTimezone) ? memberTimezone : undefined
36+
}, [city, memberCountry])
1637

1738
return (
1839
<div className={styles.container}>
1940
<div className={styles.localInfo}>
2041
<IconSolid.LocationMarkerIcon />
21-
{memberCountry}
22-
</div>
23-
<div className={styles.localInfo}>
24-
<IconSolid.ClockIcon />
25-
Local time:
26-
{' '}
27-
{moment()
28-
.tz('America/New_York')
29-
.format('HH:MM')}
42+
{`${!!city ? `${city}, ` : ''}${memberCountry}`}
3043
</div>
44+
{
45+
!!memberCityTimezone && (
46+
<div className={styles.localInfo}>
47+
<IconSolid.ClockIcon />
48+
Local time:
49+
{' '}
50+
{moment()
51+
.tz(memberCityTimezone)
52+
.format('hh:mm')}
53+
</div>
54+
)
55+
}
3156
</div>
3257
)
3358
}

src/libs/core/lib/profile/user-profile.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { UserEMSISkill } from './user-skill.model'
33
export type TC_TRACKS = 'DEVELOP' | 'DESIGN' | 'DATA_SCIENCE'
44

55
export interface UserProfile {
6+
addresses?: Array<{
7+
city?: string
8+
}>
69
competitionCountryCode: string
710
createdAt: number
811
description: string

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6392,6 +6392,13 @@ ci-info@^3.6.1:
63926392
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.8.0.tgz#81408265a5380c929f0bc665d62256628ce9ef91"
63936393
integrity sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw==
63946394

6395+
city-timezones@^1.2.1:
6396+
version "1.2.1"
6397+
resolved "https://registry.yarnpkg.com/city-timezones/-/city-timezones-1.2.1.tgz#7087d1719dd599f1e88ebc2f7fb96e091201d318"
6398+
integrity sha512-hruuB611QFoUFMsan7xd9B2VPMrA8XC716O/999WW34kmaJUT1hxKF2W8TSXAWkhSqgvbu70DjcDv7/wpM6vow==
6399+
dependencies:
6400+
lodash "^4.17.21"
6401+
63956402
cjs-module-lexer@^1.0.0:
63966403
version "1.2.2"
63976404
resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-1.2.2.tgz#9f84ba3244a512f3a54e5277e8eef4c489864e40"

0 commit comments

Comments
 (0)