Skip to content

Commit

Permalink
fix(payment-widget): translation and emotion
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelfimov committed Dec 10, 2024
1 parent 3cfca40 commit b611a2e
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 29 deletions.
2 changes: 1 addition & 1 deletion packages/payment-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "0.1.1",
"license": "BSD-3-Clause",
"type": "module",
"main": "src/index.ts",
"exports": {
".": "./src/index.ts"
},
"main": "src/index.ts",
"files": [
"dist"
],
Expand Down
9 changes: 0 additions & 9 deletions packages/payment-widget/src/locales/en.json

This file was deleted.

11 changes: 11 additions & 0 deletions packages/payment-widget/src/locales/en.locale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Locale } from './locale.interaces.js'

export const EnLocale: Locale = {
'payment_widget.pay': 'Pay',
'payment_widget.order_price': 'Order amount',
'payment_widget.email': 'E-mail',
'payment_widget.error_required': 'Required field',
'payment_widget.error_amount': 'The amount must be greater than zero',
'payment_widget.error_email': 'Incorrect e-mail',
'payment_widget.error_phone': 'Incorrect phone',
}
2 changes: 2 additions & 0 deletions packages/payment-widget/src/locales/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './en.locale.js'
export * from './ru.locale.js'
9 changes: 9 additions & 0 deletions packages/payment-widget/src/locales/locale.interaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface Locale {
'payment_widget.pay': string
'payment_widget.order_price': string
'payment_widget.email': string
'payment_widget.error_required': string
'payment_widget.error_amount': string
'payment_widget.error_email': string
'payment_widget.error_phone': string
}
9 changes: 0 additions & 9 deletions packages/payment-widget/src/locales/ru.json

This file was deleted.

11 changes: 11 additions & 0 deletions packages/payment-widget/src/locales/ru.locale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Locale } from './locale.interaces.js'

export const RuLocale: Locale = {
'payment_widget.pay': 'Оплатить',
'payment_widget.order_price': 'Сумма заказа',
'payment_widget.email': 'E-mail',
'payment_widget.error_required': 'Обязательное поле',
'payment_widget.error_amount': 'Сумма должна быть больше нуля',
'payment_widget.error_email': 'Некорректный e-mail',
'payment_widget.error_phone': 'Некорректный номер',
}
4 changes: 2 additions & 2 deletions packages/payment-widget/src/ui/button/button.component.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ButtonProps } from '@atls-ui-parts/button'
import type { FC } from 'react'

import { default as styled } from '@emotion/styled'
import styled from '@emotion/styled'
import { useHover } from 'react-laag'
import React from 'react'

Expand All @@ -10,7 +10,7 @@ import { contentStyles } from './button.styles.js'
import { baseStyles } from './button.styles.js'
import { shapeStyles } from './button.styles.js'

const ButtonElement = styled.default('button')<ButtonProps>(
const ButtonElement = (styled.default ?? styled)('button')<ButtonProps>(
// @ts-expect-error
baseStyles,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
Expand Down
4 changes: 2 additions & 2 deletions packages/payment-widget/src/ui/input/input.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { baseStyles } from './input.styles.js'
import { shapeStyles } from './input.styles.js'
import { transitionStyles } from './input.styles.js'

export const InputElement = styled.default.div<any>(
export const InputElement = (styled.default ?? styled).div<any>(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
baseStyles,
shapeStyles,
Expand All @@ -29,7 +29,7 @@ export const InputElement = styled.default.div<any>(
layout
)

const Container = styled.default.div(({ type }: any) => ({
const Container = (styled.default ?? styled).div(({ type }: any) => ({
display: type === 'hidden' ? 'none' : 'flex',
width: '100%',
flexDirection: 'column',
Expand Down
16 changes: 10 additions & 6 deletions packages/payment-widget/src/ui/widget.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import { IntlProvider } from 'react-intl'
import { useMemo } from 'react'
import React from 'react'

import * as messagesEn from '../locales/en.json' with { type: 'json' }
import * as messagesRu from '../locales/ru.json' with { type: 'json' }
import { LanguagesType } from '../enums/index.js'
import { EnLocale } from '../locales/index.js'
import { RuLocale } from '../locales/index.js'
import { Form } from './form/index.js'
import { FormProvider } from './form/index.js'
import { useCustomButton } from '../hooks/index.js'
import { useCustomFields } from '../hooks/index.js'
import { getNameFields } from '../utils/index.js'

const messages = {
[LanguagesType.RUSSIAN]: messagesRu,
[LanguagesType.ENGLISH]: messagesEn,
[LanguagesType.RUSSIAN]: RuLocale,
[LanguagesType.ENGLISH]: EnLocale,
}

export const Widget = ({
Expand Down Expand Up @@ -47,8 +47,12 @@ export const Widget = ({
const nameFields = getNameFields(customFields)

return (
// @ts-expect-error types mismatch
<IntlProvider locale={locale} messages={messages[locale]} defaultLocale={LanguagesType.RUSSIAN}>
<IntlProvider
locale={locale ?? navigator.language}
// @ts-expect-error types mismatch
messages={messages[locale]}
defaultLocale={LanguagesType.RUSSIAN}
>
<FormProvider
additionalFields={additionalFields}
nameFields={nameFields}
Expand Down

0 comments on commit b611a2e

Please sign in to comment.