From 181e7c8c7d8143acd13033d42e6ea5af3a7e15b5 Mon Sep 17 00:00:00 2001 From: Gucheng Wang Date: Sat, 25 Feb 2023 15:25:47 +0800 Subject: [PATCH] Refactor out getCountryCodeOption() --- web/src/OrganizationEditPage.js | 17 ++++++++--------- web/src/SelectRegionBox.js | 8 +++----- web/src/Setting.js | 22 +++++++++++++++++++--- web/src/common/PhoneNumberInput.js | 18 ++---------------- 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/web/src/OrganizationEditPage.js b/web/src/OrganizationEditPage.js index d2df0a4b..860e6668 100644 --- a/web/src/OrganizationEditPage.js +++ b/web/src/OrganizationEditPage.js @@ -188,16 +188,15 @@ class OrganizationEditPage extends React.Component { diff --git a/web/src/SelectRegionBox.js b/web/src/SelectRegionBox.js index c80a2e15..eace0cec 100644 --- a/web/src/SelectRegionBox.js +++ b/web/src/SelectRegionBox.js @@ -41,17 +41,15 @@ class SelectRegionBox extends React.Component { defaultValue={this.props.defaultValue || undefined} placeholder="Please select country/region" onChange={(value => {this.onChange(value);})} - filterOption={(input, option) => - (option?.label ?? "").toLowerCase().includes(input.toLowerCase()) - } + filterOption={(input, option) => (option?.label ?? "").toLowerCase().includes(input.toLowerCase())} filterSort={(optionA, optionB) => (optionA?.label ?? "").toLowerCase().localeCompare((optionB?.label ?? "").toLowerCase()) } > { - Setting.getCountriesData().map((item) => ( + Setting.getCountryCodeData().map((item) => ( )) diff --git a/web/src/Setting.js b/web/src/Setting.js index 30066612..2a81f396 100644 --- a/web/src/Setting.js +++ b/web/src/Setting.js @@ -14,7 +14,7 @@ import React from "react"; import {Link} from "react-router-dom"; -import {Checkbox, Form, Modal, Tag, Tooltip, message, theme} from "antd"; +import {Checkbox, Form, Modal, Select, Tag, Tooltip, message, theme} from "antd"; import {QuestionCircleTwoTone} from "@ant-design/icons"; import {isMobile as isMobileDevice} from "react-device-detect"; import "./i18n"; @@ -26,6 +26,8 @@ import * as Conf from "./Conf"; import * as phoneNumber from "libphonenumber-js"; import * as path from "path-browserify"; +const {Option} = Select; + export const ServerUrl = ""; // export const StaticBaseUrl = "https://cdn.jsdelivr.net/gh/casbin/static"; @@ -206,7 +208,7 @@ export function initCountries() { return countries; } -export function getCountriesData(countryCodes = phoneNumber.getCountries()) { +export function getCountryCodeData(countryCodes = phoneNumber.getCountries()) { return countryCodes?.map((countryCode) => { if (phoneNumber.isSupportedCountry(countryCode)) { const name = initCountries().getName(countryCode, getLanguage()); @@ -220,7 +222,21 @@ export function getCountriesData(countryCodes = phoneNumber.getCountries()) { .sort((a, b) => a.phone - b.phone); } -export function countryFlag(country) { +export function getCountryCodeOption(country) { + return ( + + ); +} + +export function getCountryImage(country) { return {country.name}; } diff --git a/web/src/common/PhoneNumberInput.js b/web/src/common/PhoneNumberInput.js index 254600da..8b545f9a 100644 --- a/web/src/common/PhoneNumberInput.js +++ b/web/src/common/PhoneNumberInput.js @@ -16,8 +16,6 @@ import {Select} from "antd"; import * as Setting from "../Setting"; import React from "react"; -const {Option} = Select; - export default function PhoneNumberInput(props) { const {onChange, style, disabled} = props; const value = props.value ?? "CN"; @@ -37,22 +35,10 @@ export default function PhoneNumberInput(props) { dropdownMatchSelectWidth={false} optionLabelProp={"label"} onChange={handleOnChange} - filterOption={(input, option) => - (option?.text ?? "").toLowerCase().includes(input.toLowerCase()) - } + filterOption={(input, option) => (option?.text ?? "").toLowerCase().includes(input.toLowerCase())} > { - Setting.getCountriesData(countryCodes).map((country) => ( - - )) + Setting.getCountryCodeData(countryCodes).map((country) => Setting.getCountryCodeOption(country)) } );