-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add currency & country entities and profile page if not auth
- Loading branch information
Showing
23 changed files
with
338 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{ | ||
"Cancel": "", | ||
"Choose country": "", | ||
"Choose currency": "", | ||
"Edit": "", | ||
"PROFILE PAGE": "", | ||
"Profile": "", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,38 @@ | ||
import React, { Suspense } from 'react'; | ||
import React, { memo, Suspense, useMemo } from 'react'; | ||
import { Route, Routes } from 'react-router-dom'; | ||
import { routeConfig } from 'shared/config/routeConfig/routeConfig'; | ||
import { PageLoader } from 'shared/ui/PageLoader/PageLoader'; | ||
import { useSelector } from 'react-redux'; | ||
import { getUserAuthData } from 'entities/User'; | ||
|
||
const AppRouter = () => ( | ||
<Routes> | ||
{Object.values(routeConfig).map(({ element, path }) => ( | ||
<Route | ||
key={path} | ||
path={path} | ||
element={( | ||
<Suspense fallback={<PageLoader />}> | ||
<div className="page-wrapper"> | ||
{element} | ||
</div> | ||
</Suspense> | ||
)} | ||
/> | ||
))} | ||
</Routes> | ||
); | ||
const AppRouter = () => { | ||
const isAuth = useSelector(getUserAuthData); | ||
|
||
export default AppRouter; | ||
const routes = useMemo(() => Object.values(routeConfig).filter((route) => { | ||
if (route.authOnly && !isAuth) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}), [isAuth]); | ||
|
||
return ( | ||
<Routes> | ||
{routes.map(({ element, path }) => ( | ||
<Route | ||
key={path} | ||
path={path} | ||
element={( | ||
<Suspense fallback={<PageLoader />}> | ||
<div className="page-wrapper"> | ||
{element} | ||
</div> | ||
</Suspense> | ||
)} | ||
/> | ||
))} | ||
</Routes> | ||
); | ||
}; | ||
|
||
export default memo(AppRouter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { Country } from './model/types/country'; | ||
export { CountrySelect } from './ui/CountrySelect/CountrySelect'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export enum Country { | ||
Russia = 'Russia', | ||
Belarus = 'Belarus', | ||
Ukraine = 'Ukraine', | ||
Kazakhstan = 'Kazahstan', | ||
Armenia = 'Armenia', | ||
} |
15 changes: 15 additions & 0 deletions
15
src/entities/Country/ui/CountrySelect/CountrySelect.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
import { CountrySelect } from './CountrySelect'; | ||
|
||
export default { | ||
title: 'entities/CountrySelect', | ||
component: CountrySelect, | ||
argTypes: { | ||
backgroundColor: { control: 'color' }, | ||
}, | ||
} as ComponentMeta<typeof CountrySelect>; | ||
|
||
const Template: ComponentStory<typeof CountrySelect> = (args) => <CountrySelect {...args} />; | ||
|
||
export const Primary = Template.bind({}); | ||
Primary.args = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { classNames } from 'shared/lib/classNames/classNames'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Select } from 'shared/ui/Select/Select'; | ||
import { memo, useCallback } from 'react'; | ||
import { Country } from '../../model/types/country'; | ||
|
||
interface CountrySelectProps { | ||
className?: string; | ||
value?: string; | ||
onChange?: (value: Country) => void; | ||
readonly?:boolean; | ||
} | ||
|
||
const options = [ | ||
{ value: Country.Armenia, content: Country.Armenia }, | ||
{ value: Country.Ukraine, content: Country.Ukraine }, | ||
{ value: Country.Belarus, content: Country.Belarus }, | ||
{ value: Country.Kazakhstan, content: Country.Kazakhstan }, | ||
{ value: Country.Russia, content: Country.Russia }, | ||
]; | ||
|
||
export const CountrySelect = memo((props: CountrySelectProps) => { | ||
const { t } = useTranslation(); | ||
|
||
const { | ||
className, | ||
value, | ||
onChange, | ||
readonly, | ||
} = props; | ||
|
||
const onChangeHandler = useCallback((value: string) => { | ||
onChange?.(value as Country); | ||
}, [onChange]); | ||
|
||
return ( | ||
<Select | ||
className={classNames('', {}, [className])} | ||
label={t('Choose country')} | ||
options={options} | ||
value={value} | ||
onChange={onChangeHandler} | ||
readonly={readonly} | ||
/> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { Currency } from './model/types/currency'; | ||
export { CurrencySelect } from './ui/CurrencySelect/CurrencySelect'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum Currency { | ||
"RUB" = "RUB", | ||
"EUR" = "EUR", | ||
"USD" = "USD", | ||
} |
15 changes: 15 additions & 0 deletions
15
src/entities/Currency/ui/CurrencySelect/CurrencySelect.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
import { CurrencySelect } from './CurrencySelect'; | ||
|
||
export default { | ||
title: 'entities/CurrencySelect', | ||
component: CurrencySelect, | ||
argTypes: { | ||
backgroundColor: { control: 'color' }, | ||
}, | ||
} as ComponentMeta<typeof CurrencySelect>; | ||
|
||
const Template: ComponentStory<typeof CurrencySelect> = (args) => <CurrencySelect {...args} />; | ||
|
||
export const Primary = Template.bind({}); | ||
Primary.args = {}; |
44 changes: 44 additions & 0 deletions
44
src/entities/Currency/ui/CurrencySelect/CurrencySelect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { classNames } from 'shared/lib/classNames/classNames'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Select } from 'shared/ui/Select/Select'; | ||
import { memo, useCallback } from 'react'; | ||
import { Currency } from '../../model/types/currency'; | ||
|
||
interface CurrencySelectProps { | ||
className?: string; | ||
value?: string; | ||
onChange?: (value: Currency) => void; | ||
readonly?:boolean; | ||
} | ||
|
||
const options = [ | ||
{ value: Currency.RUB, content: Currency.RUB }, | ||
{ value: Currency.USD, content: Currency.USD }, | ||
{ value: Currency.EUR, content: Currency.EUR }, | ||
]; | ||
|
||
export const CurrencySelect = memo((props: CurrencySelectProps) => { | ||
const { t } = useTranslation(); | ||
|
||
const { | ||
className, | ||
value, | ||
onChange, | ||
readonly, | ||
} = props; | ||
|
||
const onChangeHandler = useCallback((value: string) => { | ||
onChange?.(value as Currency); | ||
}, [onChange]); | ||
|
||
return ( | ||
<Select | ||
className={classNames('', {}, [className])} | ||
label={t('Choose currency')} | ||
options={options} | ||
value={value} | ||
onChange={onChangeHandler} | ||
readonly={readonly} | ||
/> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,7 @@ | |
display: flex; | ||
justify-content: center; | ||
} | ||
|
||
.editing { | ||
border: 2px solid var(--inverted-primary-color); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.