From 8f2ae32e82395b96e32756f0f9715c3fedb8eed2 Mon Sep 17 00:00:00 2001 From: Nick Misasi Date: Mon, 16 Oct 2023 11:23:22 -0400 Subject: [PATCH] [CLD-6077] Changes to Country Selectors throughout Webapp (#24868) * Standardize country selectors into using a central component - don't use Country Name, use Country Code * Fix colour of placeholder * Updates * Update state selector to reflect changes from Country Name to Country Code * Fix linter" --- .../billing/company_info_edit.tsx | 11 ++--- .../components/payment_form/address_form.tsx | 23 ++-------- .../payment_form/country_selector.tsx | 43 +++++++++++++++++++ .../components/payment_form/payment_form.scss | 4 -- .../components/payment_form/payment_form.tsx | 17 ++------ .../payment_form/state_selector.tsx | 7 ++- .../self_hosted_purchases/address.tsx | 23 ++-------- .../start_trial_form_modal.test.tsx.snap | 2 +- .../start_trial_form_modal/index.tsx | 21 ++------- webapp/channels/src/i18n/en.json | 1 - 10 files changed, 62 insertions(+), 90 deletions(-) create mode 100644 webapp/channels/src/components/payment_form/country_selector.tsx diff --git a/webapp/channels/src/components/admin_console/billing/company_info_edit.tsx b/webapp/channels/src/components/admin_console/billing/company_info_edit.tsx index 1628352c65..a71e1e828d 100644 --- a/webapp/channels/src/components/admin_console/billing/company_info_edit.tsx +++ b/webapp/channels/src/components/admin_console/billing/company_info_edit.tsx @@ -12,13 +12,12 @@ import {getCloudCustomer, updateCloudCustomer, updateCloudCustomerAddress} from import {setNavigationBlocked} from 'actions/admin_actions.jsx'; import BlockableLink from 'components/admin_console/blockable_link'; -import DropdownInput from 'components/dropdown_input'; +import CountrySelector from 'components/payment_form/country_selector'; import StateSelector from 'components/payment_form/state_selector'; import SaveButton from 'components/save_button'; import AdminHeader from 'components/widgets/admin_console/admin_header'; import Input from 'components/widgets/inputs/input/input'; -import {COUNTRIES} from 'utils/countries'; import * as Utils from 'utils/utils'; import type {GlobalState} from 'types/store'; @@ -138,16 +137,12 @@ const CompanyInfoEdit: React.FC = () => { const companyAddressInput = ( <> - { setCountry(option.value); setContentChanged(true); }} - value={country ? {value: country, label: country} : undefined} - options={COUNTRIES.map((c) => ({value: c.name, label: c.name}))} - legend={Utils.localizeMessage('admin.billing.company_info.country', 'Country')} - placeholder={Utils.localizeMessage('admin.billing.company_info.country', 'Country')} - name={'country_dropdown'} + value={country || undefined} />
{ />
- ({ - value: country.name, - label: country.name, - }))} - legend={formatMessage({ - id: 'payment_form.country', - defaultMessage: 'Country', - })} - placeholder={formatMessage({ - id: 'payment_form.country', - defaultMessage: 'Country', - })} - name={'billing_dropdown'} + value={props.address.country} />
diff --git a/webapp/channels/src/components/payment_form/country_selector.tsx b/webapp/channels/src/components/payment_form/country_selector.tsx new file mode 100644 index 0000000000..8d5ba25200 --- /dev/null +++ b/webapp/channels/src/components/payment_form/country_selector.tsx @@ -0,0 +1,43 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import {getName} from 'country-list'; +import React from 'react'; +import {useIntl} from 'react-intl'; + +import DropdownInput from 'components/dropdown_input'; + +import {COUNTRIES} from 'utils/countries'; + +type CountrySelectorProps = { + onChange: (option: any) => void; + value?: string; + testId?: string; +} + +const CountrySelector = (props: CountrySelectorProps) => { + const {formatMessage} = useIntl(); + + return ( + ({ + value: country.code, + label: country.name, + }))} + legend={formatMessage({ + id: 'payment_form.country', + defaultMessage: 'Country', + })} + placeholder={formatMessage({ + id: 'payment_form.country', + defaultMessage: 'Country', + })} + name={'country_dropdown'} + /> + ); +}; + +export default CountrySelector; diff --git a/webapp/channels/src/components/payment_form/payment_form.scss b/webapp/channels/src/components/payment_form/payment_form.scss index e49b086de6..97d85d26c3 100644 --- a/webapp/channels/src/components/payment_form/payment_form.scss +++ b/webapp/channels/src/components/payment_form/payment_form.scss @@ -45,10 +45,6 @@ .DropDown__control { min-height: 0; background-color: var(--center-channel-bg) !important; - - .DropDown__value-container > div { - color: var(--center-channel-color) !important; - } } .DropDown__menu { diff --git a/webapp/channels/src/components/payment_form/payment_form.tsx b/webapp/channels/src/components/payment_form/payment_form.tsx index 146e59fdc9..650e4eebb1 100644 --- a/webapp/channels/src/components/payment_form/payment_form.tsx +++ b/webapp/channels/src/components/payment_form/payment_form.tsx @@ -11,16 +11,14 @@ import type {CloudCustomer, PaymentMethod} from '@mattermost/types/cloud'; import type {Theme} from 'mattermost-redux/selectors/entities/preferences'; -import DropdownInput from 'components/dropdown_input'; import Input from 'components/widgets/inputs/input/input'; -import {COUNTRIES} from 'utils/countries'; - import type {BillingDetails} from 'types/cloud/sku'; import CardImage from './card_image'; import CardInput from './card_input'; import type {CardInputType} from './card_input'; +import CountrySelector from './country_selector'; import {GatherIntent, GatherIntentModal} from './gather_intent'; import StateSelector from './state_selector'; @@ -165,18 +163,9 @@ const PaymentForm: React.FC = (props: Props) => { defaultMessage='Billing address' />
- ({ - value: country.name, - label: country.name, - }))} - legend={formatMessage({id: 'payment_form.country', defaultMessage: 'Country'})} - placeholder={formatMessage({id: 'payment_form.country', defaultMessage: 'Country'})} - name={'billing_dropdown'} + value={state.country} />
); } diff --git a/webapp/channels/src/components/self_hosted_purchases/address.tsx b/webapp/channels/src/components/self_hosted_purchases/address.tsx index 1e6b7dae5c..a595f29139 100644 --- a/webapp/channels/src/components/self_hosted_purchases/address.tsx +++ b/webapp/channels/src/components/self_hosted_purchases/address.tsx @@ -5,12 +5,10 @@ import classNames from 'classnames'; import React from 'react'; import {useIntl} from 'react-intl'; -import DropdownInput from 'components/dropdown_input'; +import CountrySelector from 'components/payment_form/country_selector'; import StateSelector from 'components/payment_form/state_selector'; import Input from 'components/widgets/inputs/input/input'; -import {COUNTRIES} from 'utils/countries'; - interface Props { type: 'shipping' | 'billing'; testPrefix?: string; @@ -45,25 +43,10 @@ export default function Address(props: Props) { return ( <>
- ({ - value: country.name, - label: country.name, - }))} - legend={intl.formatMessage({ - id: 'payment_form.country', - defaultMessage: 'Country', - })} - placeholder={intl.formatMessage({ - id: 'payment_form.country', - defaultMessage: 'Country', - })} - name={'billing_dropdown'} + value={props.country} />
diff --git a/webapp/channels/src/components/start_trial_form_modal/__snapshots__/start_trial_form_modal.test.tsx.snap b/webapp/channels/src/components/start_trial_form_modal/__snapshots__/start_trial_form_modal.test.tsx.snap index 641f44f0c7..6bac4edee1 100644 --- a/webapp/channels/src/components/start_trial_form_modal/__snapshots__/start_trial_form_modal.test.tsx.snap +++ b/webapp/channels/src/components/start_trial_form_modal/__snapshots__/start_trial_form_modal.test.tsx.snap @@ -225,7 +225,7 @@ Object { >