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);