feat: fix filter scroll, add translate for auth modals

This commit is contained in:
SD 2024-04-12 20:34:18 +04:00
parent b6d11a5b30
commit ffbbeadb40
13 changed files with 68 additions and 37 deletions

View File

@ -5,7 +5,7 @@ import { useSearchParams } from 'next/navigation';
import debounce from 'lodash/debounce'; import debounce from 'lodash/debounce';
import { useRouter } from '../../navigation'; import { useRouter } from '../../navigation';
import { AdditionalFilter } from '../../types/experts'; import { AdditionalFilter } from '../../types/experts';
import { getObjectByFilter, getObjectByAdditionalFilter } from '../../utils/filter'; import { getObjectByFilter, getObjectByAdditionalFilter, getSearchParamsString } from '../../utils/filter';
import { CustomInput } from '../view/CustomInput'; import { CustomInput } from '../view/CustomInput';
import { CustomSelect } from '../view/CustomSelect'; import { CustomSelect } from '../view/CustomSelect';
import { i18nText } from '../../i18nKeys'; import { i18nText } from '../../i18nKeys';
@ -22,6 +22,7 @@ export const ExpertsAdditionalFilter = ({
const searchParams = useSearchParams(); const searchParams = useSearchParams();
const router = useRouter(); const router = useRouter();
const [filter, setFilter] = useState<AdditionalFilter | undefined>(getObjectByAdditionalFilter(searchParams)); const [filter, setFilter] = useState<AdditionalFilter | undefined>(getObjectByAdditionalFilter(searchParams));
const [isMounted, setIsMounted] = useState<boolean>(false);
const onChangeInput = useCallback(debounce((e: any) => { const onChangeInput = useCallback(debounce((e: any) => {
const newFilter: AdditionalFilter = { ...filter }; const newFilter: AdditionalFilter = { ...filter };
@ -48,17 +49,35 @@ export const ExpertsAdditionalFilter = ({
}, [filter]); }, [filter]);
const updateRoute = debounce(() => { const updateRoute = debounce(() => {
router.push({ const newFilter = {
pathname: basePath as any, ...getObjectByFilter(searchParams),
query: { ...filter
...getObjectByFilter(searchParams), };
...filter const search = getSearchParamsString(newFilter);
}
}) console.log('here1');
router.push(search ? `${basePath}?${search}#filter` : `${basePath}#filter`);
// router.push({
// pathname: basePath as any,
// query: {
// ...getObjectByFilter(searchParams),
// ...filter
// }
// })
}, 300); }, 300);
useEffect(() => { useEffect(() => {
updateRoute(); if (!isMounted) {
setIsMounted(true);
}
}, []);
useEffect(() => {
if (isMounted) {
updateRoute();
}
}, [filter]); }, [filter]);
return ( return (

View File

@ -7,7 +7,7 @@ import { useSearchParams } from 'next/navigation';
import { useRouter } from '../../navigation'; import { useRouter } from '../../navigation';
import { Filter } from '../../types/experts'; import { Filter } from '../../types/experts';
import { Languages, SearchData, Tag } from '../../types/tags'; import { Languages, SearchData, Tag } from '../../types/tags';
import { getObjectByFilter, getObjectByAdditionalFilter } from '../../utils/filter'; import { getObjectByFilter, getObjectByAdditionalFilter, getSearchParamsString } from '../../utils/filter';
import { CustomSwitch } from '../view/CustomSwitch'; import { CustomSwitch } from '../view/CustomSwitch';
import { CustomSlider } from '../view/CustomSlider'; import { CustomSlider } from '../view/CustomSlider';
import { CustomInput } from '../view/CustomInput'; import { CustomInput } from '../view/CustomInput';
@ -109,21 +109,21 @@ export const ExpertsFilter = ({
}, [filter, searchParams, searchData]); }, [filter, searchParams, searchData]);
const goToFilterPage = useCallback(() => { const goToFilterPage = useCallback(() => {
// const newFilter: GeneralFilter = { const newFilter = {
// ...filter, ...filter,
// ...getObjectByAdditionalFilter(searchParams) ...getObjectByAdditionalFilter(searchParams)
// }; };
// const search = getSearchParamsString(newFilter); const search = getSearchParamsString(newFilter);
//
// router.push(search ? `${pathname}?${search}` : pathname, { scroll: false });
router.push({ router.push(search ? `${basePath}?${search}#filter` : `${basePath}#filter`);
pathname: basePath as any,
query: { // router.push({
...filter, // pathname: basePath as any,
...getObjectByAdditionalFilter(searchParams) // query: {
} // ...filter,
}) // ...getObjectByAdditionalFilter(searchParams)
// }
// })
}, [filter, searchParams, searchData]); }, [filter, searchParams, searchData]);
const getSelectedLanguage = useCallback((): string => { const getSelectedLanguage = useCallback((): string => {

View File

@ -95,10 +95,10 @@ export const AuthModal: FC<AuthModalProps> = ({
/> />
)} )}
{mode === 'reset' && ( {mode === 'reset' && (
<ResetContent form={form} updateMode={updateMode} /> <ResetContent form={form} updateMode={updateMode} locale={paths[1]} />
)} )}
{mode === 'finish' && ( {mode === 'finish' && (
<FinishContent /> <FinishContent locale={paths[1]} />
)} )}
<div className="b-modal__auth__agreement"> <div className="b-modal__auth__agreement">
I have read and agree with the terms of the I have read and agree with the terms of the

View File

@ -12,6 +12,7 @@ import { CustomInputPassword } from '../../view/CustomInputPassword';
import { FilledButton } from '../../view/FilledButton'; import { FilledButton } from '../../view/FilledButton';
import { OutlinedButton } from '../../view/OutlinedButton'; import { OutlinedButton } from '../../view/OutlinedButton';
import { LinkButton } from '../../view/LinkButton'; import { LinkButton } from '../../view/LinkButton';
import { i18nText } from '../../../i18nKeys';
type EnterProps = { type EnterProps = {
form: FormInstance; form: FormInstance;
@ -133,7 +134,7 @@ export const EnterContent: FC<EnterProps> = ({
> >
<CustomInputPassword <CustomInputPassword
size="small" size="small"
placeholder="Password" placeholder={i18nText('password', locale)}
autoComplete="off" autoComplete="off"
onPressEnter={onLogin} onPressEnter={onLogin}
/> />
@ -144,9 +145,9 @@ export const EnterContent: FC<EnterProps> = ({
onClick={onLogin} onClick={onLogin}
loading={isLoading} loading={isLoading}
> >
Enter {i18nText('enter', locale)}
</FilledButton> </FilledButton>
<OutlinedButton onClick={() => updateMode('register')}>Register</OutlinedButton> <OutlinedButton onClick={() => updateMode('register')}>{i18nText('registration', locale)}</OutlinedButton>
<LinkButton <LinkButton
type="link" type="link"
onClick={() => updateMode('reset')} onClick={() => updateMode('reset')}

View File

@ -1,7 +1,8 @@
import React from 'react'; import React from 'react';
import { FilledButton } from '../../view/FilledButton'; import { FilledButton } from '../../view/FilledButton';
import { i18nText } from '../../../i18nKeys';
export const FinishContent = () => ( export const FinishContent = ({ locale }: { locale: string }) => (
<> <>
<div className="b-modal__auth__agreement"> <div className="b-modal__auth__agreement">
A link to reset your password has been sent A link to reset your password has been sent
@ -11,7 +12,7 @@ export const FinishContent = () => (
<FilledButton <FilledButton
type="primary" type="primary"
> >
Enter Account {i18nText('enter', locale)}
</FilledButton> </FilledButton>
</> </>
); );

View File

@ -11,6 +11,7 @@ import { CustomInput } from '../../view/CustomInput';
import { CustomInputPassword } from '../../view/CustomInputPassword'; import { CustomInputPassword } from '../../view/CustomInputPassword';
import { FilledButton } from '../../view/FilledButton'; import { FilledButton } from '../../view/FilledButton';
import { OutlinedButton } from '../../view/OutlinedButton'; import { OutlinedButton } from '../../view/OutlinedButton';
import { i18nText } from '../../../i18nKeys';
type RegisterProps = { type RegisterProps = {
form: FormInstance; form: FormInstance;
@ -138,7 +139,7 @@ export const RegisterContent: FC<RegisterProps> = ({
> >
<CustomInputPassword <CustomInputPassword
size="small" size="small"
placeholder="Password" placeholder={i18nText('password', locale)}
/> />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
@ -163,7 +164,7 @@ export const RegisterContent: FC<RegisterProps> = ({
> >
<CustomInputPassword <CustomInputPassword
size="small" size="small"
placeholder="Confirm password" placeholder={i18nText('confirmPass', locale)}
/> />
</Form.Item> </Form.Item>
</Form> </Form>
@ -172,9 +173,9 @@ export const RegisterContent: FC<RegisterProps> = ({
onClick={onRegister} onClick={onRegister}
loading={isLoading} loading={isLoading}
> >
Register {i18nText('registration', locale)}
</FilledButton> </FilledButton>
<OutlinedButton onClick={() => updateMode('enter')}>Enter</OutlinedButton> <OutlinedButton onClick={() => updateMode('enter')}>{i18nText('enter', locale)}</OutlinedButton>
<span>or</span> <span>or</span>
<OutlinedButton <OutlinedButton
icon={<Image src="/images/facebook-logo.png" height={20} width={20} alt="" />} icon={<Image src="/images/facebook-logo.png" height={20} width={20} alt="" />}

View File

@ -3,15 +3,18 @@ import { Form, FormInstance } from 'antd';
import { CustomInput } from '../../view/CustomInput'; import { CustomInput } from '../../view/CustomInput';
import { FilledButton } from '../../view/FilledButton'; import { FilledButton } from '../../view/FilledButton';
import { LinkButton } from '../../view/LinkButton'; import { LinkButton } from '../../view/LinkButton';
import { i18nText } from '../../../i18nKeys';
type ResetProps = { type ResetProps = {
form: FormInstance; form: FormInstance;
updateMode: (mode: 'enter' | 'register' | 'reset' | 'finish') => void; updateMode: (mode: 'enter' | 'register' | 'reset' | 'finish') => void;
locale: string;
} }
export const ResetContent: FC<ResetProps> = ({ export const ResetContent: FC<ResetProps> = ({
form, form,
updateMode updateMode,
locale
}) => { }) => {
const onResetPassword = () => { const onResetPassword = () => {
console.log('reset'); console.log('reset');
@ -51,7 +54,7 @@ export const ResetContent: FC<ResetProps> = ({
type="link" type="link"
onClick={() => updateMode('enter')} onClick={() => updateMode('enter')}
> >
Enter {i18nText('enter', locale)}
</LinkButton> </LinkButton>
</> </>
); );

View File

@ -32,6 +32,7 @@ export default {
topic: 'Thema', topic: 'Thema',
name: 'Name', name: 'Name',
surname: 'Nachname', surname: 'Nachname',
password: 'Passwort',
birthday: 'Geburtsdatum', birthday: 'Geburtsdatum',
oldPass: 'Altes Passwort', oldPass: 'Altes Passwort',
newPass: 'Neues Passwort', newPass: 'Neues Passwort',

View File

@ -32,6 +32,7 @@ export default {
topic: 'Topic', topic: 'Topic',
name: 'Name', name: 'Name',
surname: 'Surname', surname: 'Surname',
password: 'Password',
birthday: 'Date of Birth', birthday: 'Date of Birth',
oldPass: 'Old Password', oldPass: 'Old Password',
newPass: 'New Password', newPass: 'New Password',

View File

@ -32,6 +32,7 @@ export default {
topic: 'Tema', topic: 'Tema',
name: 'Nombre', name: 'Nombre',
surname: 'Apellido', surname: 'Apellido',
password: 'Contraseña',
birthday: 'Fecha de nacimiento', birthday: 'Fecha de nacimiento',
oldPass: 'Contraseña antigua', oldPass: 'Contraseña antigua',
newPass: 'Nueva contraseña', newPass: 'Nueva contraseña',

View File

@ -32,6 +32,7 @@ export default {
topic: 'Sujet', topic: 'Sujet',
name: 'Prénom', name: 'Prénom',
surname: 'Nom de famille', surname: 'Nom de famille',
password: 'Passe',
birthday: 'Date de naissance', birthday: 'Date de naissance',
oldPass: 'Ancien mot de passe', oldPass: 'Ancien mot de passe',
newPass: 'Nouveau mot de passe', newPass: 'Nouveau mot de passe',

View File

@ -32,6 +32,7 @@ export default {
topic: 'Argomento', topic: 'Argomento',
name: 'Nome', name: 'Nome',
surname: 'Cognome', surname: 'Cognome',
password: 'Password',
birthday: 'Data di nascita', birthday: 'Data di nascita',
oldPass: 'Vecchia password', oldPass: 'Vecchia password',
newPass: 'Nuova password', newPass: 'Nuova password',

View File

@ -32,6 +32,7 @@ export default {
topic: 'Тема', topic: 'Тема',
name: 'Имя', name: 'Имя',
surname: 'Фамилия', surname: 'Фамилия',
password: 'Пароль',
birthday: 'Дата рождения', birthday: 'Дата рождения',
oldPass: 'Старый пароль', oldPass: 'Старый пароль',
newPass: 'Новый пароль', newPass: 'Новый пароль',