-
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 profile page card / get profile data thunk
- Loading branch information
Showing
14 changed files
with
141 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"Edit": "", | ||
"Profile": "", | ||
"Your lastname": "", | ||
"Your name": "", | ||
"Your surname": "" | ||
} |
Empty file.
Empty file.
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,3 +1,5 @@ | ||
export { Profile, ProfileSchema } from './model/types/profile'; | ||
|
||
export { profileActions, profileReducer } from './model/slice/profileSlice'; | ||
export { fetchProfileData } from './model/services/fetchProfileData/fetchProfileData'; | ||
export { ProfileCard } from '../Profile/ui/ProfileCard/ProfileCard'; |
3 changes: 3 additions & 0 deletions
3
src/entities/Profile/model/selectors/getProfileData/getProfileData.ts
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,3 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
|
||
export const getProfileData = (state: StateSchema) => state.profile?.data; |
3 changes: 3 additions & 0 deletions
3
src/entities/Profile/model/selectors/getProfileError/getProfileError.ts
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,3 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
|
||
export const getProfileError = (state: StateSchema) => state.profile?.error; |
3 changes: 3 additions & 0 deletions
3
src/entities/Profile/model/selectors/getProfileIsLoading/getProfileIsLoading.ts
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,3 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
|
||
export const getProfileIsLoading = (state: StateSchema) => state.profile?.isLoading; |
19 changes: 19 additions & 0 deletions
19
src/entities/Profile/model/services/fetchProfileData/fetchProfileData.ts
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,19 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
import { ThunkConfig } from 'app/providers/StoreProvider'; | ||
import { Profile } from '../../types/profile'; | ||
|
||
export const fetchProfileData = createAsyncThunk< | ||
Profile, | ||
void, | ||
ThunkConfig<string> | ||
>('profile/fetchProfileData', async (_, thunkAPI) => { | ||
const { extra, rejectWithValue } = thunkAPI; | ||
|
||
try { | ||
const response = await extra.api.get<Profile>('/profile'); | ||
|
||
return response.data; | ||
} catch (error) { | ||
return rejectWithValue('error'); | ||
} | ||
}); |
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
21 changes: 21 additions & 0 deletions
21
src/entities/Profile/ui/ProfileCard/ProfileCard.module.scss
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,21 @@ | ||
.ProfileCard { | ||
padding: 20px; | ||
border: 2px solid var(--inverted-bg-color); | ||
} | ||
|
||
.header { | ||
display: flex; | ||
} | ||
|
||
.editBtn { | ||
margin-left: auto; | ||
} | ||
|
||
.data { | ||
margin-top: 30px; | ||
} | ||
|
||
.input { | ||
margin-top: 10px; | ||
} | ||
|
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 { useSelector } from 'react-redux'; | ||
import { Text } from 'shared/ui/Text/Text'; | ||
import { Button, ButtonTheme } from 'shared/ui/Button/Button'; | ||
import { Input } from 'shared/ui/Input/Input'; | ||
import { getProfileIsLoading } from '../../model/selectors/getProfileIsLoading/getProfileIsLoading'; | ||
import { getProfileError } from '../../model/selectors/getProfileError/getProfileError'; | ||
import { getProfileData } from '../../model/selectors/getProfileData/getProfileData'; | ||
import cls from './ProfileCard.module.scss'; | ||
|
||
interface ProfileCardProps { | ||
className?: string; | ||
} | ||
|
||
export const ProfileCard = ({ className }: ProfileCardProps) => { | ||
const { t } = useTranslation('profile'); | ||
const data = useSelector(getProfileData); | ||
const isLoading = useSelector(getProfileIsLoading); | ||
const error = useSelector(getProfileError); | ||
return ( | ||
<div className={classNames(cls.ProfileCard, {}, [className])}> | ||
<div className={cls.header}> | ||
<Text title={t('Profile')} /> | ||
<Button | ||
className={cls.editBtn} | ||
theme={ButtonTheme.OUTLINE} | ||
> | ||
{t('Edit')} | ||
</Button> | ||
</div> | ||
<div className={cls.data}> | ||
<Input | ||
value={data?.first} | ||
placeholder={t('Your name')} | ||
className={cls.input} | ||
/> | ||
<Input | ||
value={data?.lastname} | ||
placeholder={t('Your lastname')} | ||
className={cls.input} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; |
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