Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(condo): DOMA-10627 move ant config logic to custom component #5444

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions apps/condo/domains/common/components/antd/ConfigProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ConfigProvider as BaseConfigProvider } from 'antd'
import { ConfigProviderProps } from 'antd/lib/config-provider'
import enUS from 'antd/lib/locale/en_US'
import ruRU from 'antd/lib/locale/ru_RU'

import { useIntl } from '@open-condo/next/intl'

const ANT_DEFAULT_LOCALE = enUS
const ANT_LOCALES = {
ru: ruRU,
en: enUS,
}

const ConfigProvider = (props: ConfigProviderProps) => {
const intl = useIntl()
// NOTE(pahaz): https://github.com/ant-design/ant-design/blob/4.24.12/components/locale/ru_RU.tsx
// TODO(pahaz): DOMA-10627 move this translations to locale
const locale = ANT_LOCALES[intl.locale] || ANT_DEFAULT_LOCALE
const baseConfigProviderProps: ConfigProviderProps = {
componentSize: 'large',
locale,
...props,
}
return <BaseConfigProvider {...baseConfigProviderProps} />
}

export default ConfigProvider
14 changes: 2 additions & 12 deletions apps/condo/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { CacheProvider } from '@emotion/core'
import { ConfigProvider } from 'antd'
import enUS from 'antd/lib/locale/en_US'
import ruRU from 'antd/lib/locale/ru_RU'
import dayjs from 'dayjs'
import { cache } from 'emotion'
import get from 'lodash/get'
Expand All @@ -24,6 +21,7 @@ import { useBankReportTaskUIInterface } from '@condo/domains/banking/hooks/useBa
import { useBankSyncTaskUIInterface } from '@condo/domains/banking/hooks/useBankSyncTaskUIInterface'
import { BILLING_RECEIPT_SERVICE_FIELD_NAME } from '@condo/domains/billing/constants/constants'
import { BillingIntegrationOrganizationContext as BillingContext } from '@condo/domains/billing/utils/clientSchema'
import ConfigProvider from '@condo/domains/common/components/antd/ConfigProvider'
import BaseLayout, { useLayoutContext } from '@condo/domains/common/components/containers/BaseLayout'
import { hasFeature } from '@condo/domains/common/components/containers/FeatureFlag'
import GlobalStyle from '@condo/domains/common/components/containers/GlobalStyle'
Expand Down Expand Up @@ -95,11 +93,6 @@ const { publicRuntimeConfig: { defaultLocale, sppConfig, disableSSR } } = getCon

const IS_SSR_DISABLED = Boolean(disableSSR && disableSSR === 'true')

const ANT_LOCALES = {
ru: ruRU,
en: enUS,
}

interface IMenuItemData {
id?: string
path: string
Expand All @@ -118,8 +111,6 @@ interface IMenuCategoryData {
items: Array<IMenuItemData>
}

const ANT_DEFAULT_LOCALE = enUS

const MenuItems: React.FC = () => {
const { updateContext, useFlag } = useFeatureFlags()
const isSPPOrg = useFlag(SERVICE_PROVIDER_PROFILE)
Expand Down Expand Up @@ -457,7 +448,6 @@ const MyApp = ({ Component, pageProps }) => {
const { publicRuntimeConfig: { yandexMetrikaID, popupSmartConfig, UseDeskWidgetId } } = getConfig()

const LayoutComponent = Component.container || BaseLayout
// TODO(Dimitreee): remove this mess later
const HeaderAction = Component.headerAction
let RequiredAccess: React.FC = React.Fragment

Expand All @@ -480,7 +470,7 @@ const MyApp = ({ Component, pageProps }) => {
content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'
/>
</Head>
<ConfigProvider locale={ANT_LOCALES[intl.locale] || ANT_DEFAULT_LOCALE} componentSize='large'>
<ConfigProvider>
<CacheProvider value={cache}>
<SetupTelegramNotificationsBanner />
<GlobalStyle/>
Expand Down
Loading