From 0ad4ac31e5d1ba5f550359939b42936e6617439f Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Fri, 23 Jun 2023 16:50:03 +0200 Subject: [PATCH] change(ui): city, state, country display and tooltup (#1372) --- .../components/ui/CountryFlag/CountryFlag.js | 45 ------------ .../components/ui/CountryFlag/CountryFlag.tsx | 71 +++++++++++++++++++ 2 files changed, 71 insertions(+), 45 deletions(-) delete mode 100644 frontend/app/components/ui/CountryFlag/CountryFlag.js create mode 100644 frontend/app/components/ui/CountryFlag/CountryFlag.tsx diff --git a/frontend/app/components/ui/CountryFlag/CountryFlag.js b/frontend/app/components/ui/CountryFlag/CountryFlag.js deleted file mode 100644 index 422d5504d..000000000 --- a/frontend/app/components/ui/CountryFlag/CountryFlag.js +++ /dev/null @@ -1,45 +0,0 @@ -import React from 'react'; -import cn from 'classnames'; -import { Icon, TextEllipsis } from 'UI'; - -const CountryFlag = ({ - userCity = '', - country = '', - className = '', - style = {}, - width = 22, - height = 15, -}) => { - const knownCountry = !!country && country !== 'UN'; - const countryFlag = knownCountry ? country.toLowerCase() : ''; - - return ( -
- {knownCountry ? ( -
- ) : ( -
- -
- Unknown Country -
-
- )} - {userCity && ( - - - - )} -
- ); -}; - -CountryFlag.displayName = 'CountryFlag'; - -export default React.memo(CountryFlag); diff --git a/frontend/app/components/ui/CountryFlag/CountryFlag.tsx b/frontend/app/components/ui/CountryFlag/CountryFlag.tsx new file mode 100644 index 000000000..71cc187b8 --- /dev/null +++ b/frontend/app/components/ui/CountryFlag/CountryFlag.tsx @@ -0,0 +1,71 @@ +import React, { FC, CSSProperties, memo } from 'react'; +import cn from 'classnames'; +import { Icon, TextEllipsis } from 'UI'; +import { Tooltip } from 'antd'; +import { countries } from 'App/constants'; + +interface CountryFlagProps { + userCity?: string; + userState?: string; + country?: string; + className?: string; + style?: CSSProperties; + width?: number; + height?: number; +} + + +const CountryFlag: FC = ({ + userCity = '', + userState = '', + country = '', + className = '', + style = {}, + width = 22, + height = 15 + }) => { + const knownCountry = !!country && country !== 'UN'; + const countryFlag = knownCountry ? country.toLowerCase() : ''; + const countryName = knownCountry ? countries[country] : 'Unknown Country'; + + + const displayGeoInfo = userCity || userState || countryName; + + // display full geo info, check each part if not null, display as string + const fullGeoInfo = [userCity, userState, countryName].filter(Boolean).join(', '); + + const renderUnknownCountry = ( +
+ +
+ Unknown Country +
+
+ ); + + const renderGeoInfo = displayGeoInfo && ( + + + + ); + + return ( +
+ {knownCountry ? ( + +
+ + ) : ( + renderUnknownCountry + )} + {renderGeoInfo} +
+ ); +}; + +CountryFlag.displayName = 'CountryFlag'; + +export default memo(CountryFlag);