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

VBM-255: localization fixed #530

Open
wants to merge 1 commit 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
1 change: 0 additions & 1 deletion packages/mobile/src/common/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ export {
CHANEL_NAME,
} from './push';
export { MINIMUM_SLIDER_PRICE, MAXIMUM_SLIDER_PRICE } from './slider-price';
export { CONDITION } from './products';
9 changes: 0 additions & 9 deletions packages/mobile/src/common/constants/products.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { TFunction } from 'i18next';
import { Condition } from '@vse-bude/shared';

type ConditionType = Record<string, string>[];

const getConditions = (t: TFunction): ConditionType => {
return [
{ label: t('make_a_post.NEW'), value: Condition.NEW },
{ label: t('make_a_post.USED'), value: Condition.USED },
];
};

export { getConditions };
2 changes: 2 additions & 0 deletions packages/mobile/src/helpers/products/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export {
makeAuctionParser,
makePostParser,
} from './make-post-parse/make-post-parse';

export { getConditions } from './get-conditions/get-conditions';
4 changes: 2 additions & 2 deletions packages/mobile/src/localization/languages/en/screens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ export const screens = {
FACEBOOK: 'Facebook',
FACEBOOK_PLACEHOLDER: 'Enter your nickname',
SITE: 'Site',
NEW: 'New',
USED: 'Used',
NEW: 'new',
USED: 'used',
SAVE_AS_DRAFT_BUTTON: 'Save as draft',
MAKE_POST_BUTTON: 'Make a post',
MAKE_AUCTION_BUTTON: 'Create auction',
Expand Down
4 changes: 2 additions & 2 deletions packages/mobile/src/localization/languages/ua/screens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ export const screens = {
FACEBOOK: 'Facebook',
FACEBOOK_PLACEHOLDER: 'Введіть URL',
SITE: 'Введіть URL',
NEW: 'Новий',
USED: 'Був у використанні',
NEW: 'новий',
USED: 'уживаний',
SAVE_AS_DRAFT_BUTTON: 'Зберегти як чернетку',
MAKE_POST_BUTTON: 'Створити публікацію',
MAKE_AUCTION_BUTTON: 'Створити аукціон',
Expand Down
1 change: 1 addition & 0 deletions packages/mobile/src/navigation/tabs/tabs.navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ const MainNavigation: FC = () => {
options={{
tabBarLabel: renderTabBarLabel(t('common:tab_navigation.LOG_IN')),
tabBarIcon: LogInIcon,
unmountOnBlur: true,
}}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC } from 'react';
import { useAppForm, useTranslation, useState } from '~/hooks/hooks';
import { resetPassword } from '~/validation-schemas/validation-schemas';
import { getResetPasswordSchema } from '~/validation-schemas/validation-schemas';
import { ResetPasswordLink } from '@vse-bude/shared';
import {
View,
Expand All @@ -21,7 +21,7 @@ const ResetPassword: FC<Props> = ({ onSubmit }) => {
const { t } = useTranslation();
const { control, errors, handleSubmit } = useAppForm<ResetPasswordLink>({
defaultValues: DEFAULT_RESET_PASSWORD_PAYLOAD,
validationSchema: resetPassword,
validationSchema: getResetPasswordSchema(t),
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
useNavigation,
useAppSelector,
} from '~/hooks/hooks';
import { signIn } from '~/validation-schemas/validation-schemas';
import { getSignInSchema } from '~/validation-schemas/validation-schemas';
import { globalStyles } from '~/styles/styles';
import { DataStatus, RootScreenName } from '~/common/enums/enums';
import { RootNavigationProps } from '~/common/types/types';
Expand All @@ -26,13 +26,13 @@ type Props = {
};

const SignInForm: FC<Props> = ({ onSubmit }) => {
const { t } = useTranslation();
const dataStatusAuth = useAppSelector(selectAuthDataStatus);
const isLoading = dataStatusAuth === DataStatus.PENDING;
const { control, errors, handleSubmit } = useAppForm<UserSignInDto>({
defaultValues: DEFAULT_SIGN_IN_PAYLOAD,
validationSchema: signIn,
validationSchema: getSignInSchema(t),
});
const { t } = useTranslation();
const { navigate } = useNavigation<RootNavigationProps>();

const navigateResetPassword = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { UserSignUpDto } from '@vse-bude/shared';
import { View, Input, PrimaryButton } from '~/components/components';
import { useAppForm, useTranslation, useAppSelector } from '~/hooks/hooks';
import { signUp } from '~/validation-schemas/validation-schemas';
import { getSignUpSchema } from '~/validation-schemas/validation-schemas';
import { globalStyles } from '~/styles/styles';
import { selectAuthDataStatus } from '~/store/selectors';
import { DataStatus } from '~/common/enums/enums';
Expand All @@ -18,7 +18,7 @@ const SignUpForm: React.FC<Props> = ({ onSubmit }) => {
const isLoading = dataStatusAuth === DataStatus.PENDING;
const { control, errors, handleSubmit } = useAppForm<UserSignUpDto>({
defaultValues: DEFAULT_SIGN_UP_PAYLOAD,
validationSchema: signUp,
validationSchema: getSignUpSchema(t),
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ import { ButtonAppearance, DateTimeType } from '~/common/enums/ui/ui';
import { ButtonsContainer } from '~/screens/components/components';
import { selectCategories, selectDataStatusProducts } from '~/store/selectors';
import { DataStatus } from '~/common/enums/enums';
import { productsAuctionSchema } from '~/validation-schemas/validation-schemas';
import { getProductsAuctionSchema } from '~/validation-schemas/validation-schemas';
import { notification } from '~/services/services';
import { categoryForDropdown, makeAuctionParser } from '~/helpers/helpers';
import { CONDITION } from '~/common/constants/products';
import {
categoryForDropdown,
getConditions,
makeAuctionParser,
} from '~/helpers/helpers';
import { AddPhotos } from '../add-photos/add-photos';

import { useStyles } from './styles';
Expand Down Expand Up @@ -74,9 +77,10 @@ const NewAuctionForm: FC<Props> = ({ personalInfo }) => {
city: personalInfo.userAddress?.city || '',
phone: personalInfo.phone?.replace(/\s/g, '').slice(4) || '',
},
validationSchema: productsAuctionSchema,
validationSchema: getProductsAuctionSchema(t),
});
const [images, setImages] = useState<Asset[]>([]);
const conditions = getConditions(t);

useEffect(() => {
if (Object.keys(errors).length > 0) {
Expand Down Expand Up @@ -202,7 +206,7 @@ const NewAuctionForm: FC<Props> = ({ personalInfo }) => {
name="condition"
errors={errors}
control={control}
items={CONDITION}
items={conditions}
zIndex={19}
required={true}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ import { categoryForDropdown } from '~/helpers/category/format-category-for-drop
import { ButtonsContainer } from '~/screens/components/components';
import { ButtonAppearance, DataStatus } from '~/common/enums/enums';
import { selectCategories, selectDataStatusProducts } from '~/store/selectors';
import { productsPostSchema } from '~/validation-schemas/validation-schemas';
import { getProductsPostSchema } from '~/validation-schemas/validation-schemas';
import { notification } from '~/services/services';
import { makePostParser } from '~/helpers/helpers';
import { CONDITION } from '~/common/constants/products';
import { getConditions, makePostParser } from '~/helpers/helpers';
import { AddPhotos } from '../add-photos/add-photos';
import { useStyles } from './styles';

Expand Down Expand Up @@ -68,10 +67,11 @@ const NewItemForm: FC<Props> = ({ personalInfo }) => {
city: personalInfo.userAddress?.city || '',
phone: personalInfo.phone?.replace(/\s/g, '').slice(4) || '',
},
validationSchema: productsPostSchema,
validationSchema: getProductsPostSchema(t),
});

const [images, setImages] = useState<Asset[]>([]);
const conditions = getConditions(t);

useEffect(() => {
if (Object.keys(errors).length > 0) {
Expand Down Expand Up @@ -197,7 +197,7 @@ const NewItemForm: FC<Props> = ({ personalInfo }) => {
name="condition"
errors={errors}
control={control}
items={CONDITION}
items={conditions}
zIndex={19}
required={true}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
selectAuthDataStatus,
} from '~/store/selectors';
import { personalInfoActions, auth as authActions } from '~/store/actions';
import { personalInfoSchema } from '~/validation-schemas/validation-schemas';
import { getPersonalInfoSchema } from '~/validation-schemas/validation-schemas';
import { notification } from '~/services/services';
import {
personalInfoParser,
Expand Down Expand Up @@ -68,7 +68,7 @@ const PersonalInfoForm: React.FC<Props> = ({ personalInfo }) => {
const { control, errors, handleSubmit, reset } =
useAppForm<SaveUserProfileDto>({
defaultValues: DEFAULT_VALUES,
validationSchema: personalInfoSchema,
validationSchema: getPersonalInfoSchema(t),
});

const { isDirty } = useFormState({ control });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const LotPriceBlock: FC<LotPriceBlockProps> = ({
const dispatch = useAppDispatch();
const { control, errors, handleSubmit, setValue } = useAppForm({
defaultValues: DEFAULT_BID_VALUE,
validationSchema: getBidValidationSchema(Number(minimalBid)),
validationSchema: getBidValidationSchema(Number(minimalBid), t),
});
const { isAbleToLeaveAuction } = useAppSelector(selectPermission);
const user = useAppSelector(selectCurrentUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
selectUserEmail,
} from '~/store/selectors';
import { notification } from '~/services/services';
import { codeSchema } from '~/validation-schemas/validation-schemas';
import { getCodeSchema } from '~/validation-schemas/validation-schemas';
import { ButtonsContainer, Header } from '~/screens/components/components';
import { VERIFICATION_CODE_REGEX } from '~/common/regexp/regexp';
import {
Expand All @@ -59,7 +59,7 @@ const VerifyCodeEmailScreen: FC<PropsVerifyScreens> = ({ route }) => {
defaultValues: {
code: '',
},
validationSchema: codeSchema,
validationSchema: getCodeSchema(t),
});
const [isCorrectCode, setIsCorrectCode] = useState(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
selectUserPhone,
} from '~/store/selectors';
import { notification } from '~/services/services';
import { codeSchema } from '~/validation-schemas/validation-schemas';
import { getCodeSchema } from '~/validation-schemas/validation-schemas';
import { ButtonsContainer, Header } from '~/screens/components/components';
import { VERIFICATION_CODE_REGEX } from '~/common/regexp/regexp';
import {
Expand All @@ -59,7 +59,7 @@ const VerifyCodePhoneScreen: FC<PropsVerifyScreens> = ({ route }) => {
defaultValues: {
code: '',
},
validationSchema: codeSchema,
validationSchema: getCodeSchema(t),
});
const [isCorrectCode, setIsCorrectCode] = useState(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from '~/components/components';
import { verifyActions } from '~/store/actions';
import { images } from '~/assets/images/images';
import { phone } from '~/validation-schemas/validation-schemas';
import { getPhoneSchema } from '~/validation-schemas/validation-schemas';
import { globalStyles } from '~/styles/styles';
import { selectVerifyDataStatus, selectUserPhone } from '~/store/selectors';
import { notification } from '~/services/services';
Expand All @@ -52,7 +52,7 @@ const VerifyPhoneScreen: FC<PropsVerifyScreens> = ({ route }) => {
defaultValues: {
phone: userPhone,
},
validationSchema: phone,
validationSchema: getPhoneSchema(t),
});

const handleBackButtonPress = (): void => {
Expand Down
8 changes: 4 additions & 4 deletions packages/mobile/src/validation-schemas/bid/make-bid.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as Joi from 'joi';
import i18next from 'i18next';
import { TFunction } from 'i18next';

const getBidValidationSchema = (minimalBid: number) =>
const getBidValidationSchema = (minimalBid: number, t: TFunction) =>
Joi.object({
bid: Joi.number()
.min(minimalBid)
.messages({
'number.min': i18next.t('common:errors.LOW_BID'),
'number.base': i18next.t('common:errors.INVALID_BID'),
'number.min': t('common:errors.LOW_BID'),
'number.base': t('common:errors.INVALID_BID'),
}),
});

Expand Down
26 changes: 14 additions & 12 deletions packages/mobile/src/validation-schemas/code/code.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import * as Joi from 'joi';
import i18next from 'i18next';
import { TFunction } from 'i18next';
import { PhoneVerifyDto } from '@vse-bude/shared';
import { VERIFICATION_CODE_REGEX } from '~/common/regexp/regexp';

const codeSchema = Joi.object<PhoneVerifyDto>({
code: Joi.string()
.pattern(VERIFICATION_CODE_REGEX)
.trim()
.required()
.messages({
'string.pattern.base': i18next.t('errors.WRONG_FORMAT'),
'string.empty': i18next.t('errors.EMPTY_CODE'),
}),
});
const getCodeSchema = (t: TFunction): Joi.ObjectSchema<PhoneVerifyDto> => {
return Joi.object<PhoneVerifyDto>({
code: Joi.string()
.pattern(VERIFICATION_CODE_REGEX)
.trim()
.required()
.messages({
'string.pattern.base': t('errors.WRONG_FORMAT'),
'string.empty': t('errors.EMPTY_CODE'),
}),
});
};

export { codeSchema };
export { getCodeSchema };
21 changes: 11 additions & 10 deletions packages/mobile/src/validation-schemas/helpers/email-validator.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import * as Joi from 'joi';
import i18next from 'i18next';
import { TFunction } from 'i18next';
import { EMAIL_REGEX } from '~/common/regexp/regexp';

const emailValidator = (value: string, helpers: Joi.CustomHelpers) => {
if (value.match(/[а-яА-Я]/)) {
return helpers.message({ custom: i18next.t('errors.LATIN') });
}
const emailValidator =
(t: TFunction) => (value: string, helpers: Joi.CustomHelpers) => {
if (value.match(/[а-яА-Я]/)) {
return helpers.message({ custom: t('errors.LATIN') });
}

if (!value.match(EMAIL_REGEX)) {
return helpers.message({ custom: i18next.t('errors.INVALID_EMAIL') });
}
if (!value.match(EMAIL_REGEX)) {
return helpers.message({ custom: t('errors.INVALID_EMAIL') });
}

return value;
};
return value;
};

export { emailValidator };
Loading