-
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 readOnly for inputs, isLoading and error for profile page
- Loading branch information
Showing
15 changed files
with
195 additions
and
44 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
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
3 changes: 3 additions & 0 deletions
3
src/entities/Profile/model/selectors/getProfileReadonly/getProfileReadonly.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 getProfileReadonly = (state: StateSchema) => state.profile?.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
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
8 changes: 8 additions & 0 deletions
8
src/pages/ProfilePage/ui/ProfilePageHeader/ProfilePageHeader.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,8 @@ | ||
.ProfilePageHeader { | ||
display: flex; | ||
margin-bottom: 20px; | ||
|
||
.editBtn { | ||
margin-left: auto; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/pages/ProfilePage/ui/ProfilePageHeader/ProfilePageHeader.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,53 @@ | ||
import { classNames } from 'shared/lib/classNames/classNames'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Text } from 'shared/ui/Text/Text'; | ||
import { Button, ButtonTheme } from 'shared/ui/Button/Button'; | ||
import { useSelector } from 'react-redux'; | ||
import { getProfileReadonly, profileActions } from 'entities/Profile'; | ||
import { useCallback } from 'react'; | ||
import { useAppDispatch } from 'shared/lib/hook/useAppDispatch/useAppDispatch'; | ||
import cls from './ProfilePageHeader.module.scss'; | ||
|
||
interface ProfilePageHeaderProps { | ||
className?: string; | ||
} | ||
|
||
export const ProfilePageHeader = ({ className }: ProfilePageHeaderProps) => { | ||
const { t } = useTranslation(); | ||
|
||
const readonly = useSelector(getProfileReadonly); | ||
const dispatch = useAppDispatch(); | ||
|
||
const onEdit = useCallback(() => { | ||
dispatch(profileActions.setReadonly(false)); | ||
}, [dispatch]); | ||
|
||
const onCancelEdit = useCallback(() => { | ||
dispatch(profileActions.setReadonly(true)); | ||
}, [dispatch]); | ||
|
||
return ( | ||
<div className={classNames(cls.ProfilePageHeader, {}, [className])}> | ||
<Text title={t('Profile')} /> | ||
{readonly | ||
? ( | ||
<Button | ||
className={cls.editBtn} | ||
theme={ButtonTheme.OUTLINE} | ||
onClick={onEdit} | ||
> | ||
{t('Edit')} | ||
</Button> | ||
) : ( | ||
<Button | ||
className={cls.editBtn} | ||
theme={ButtonTheme.OUTLINE} | ||
onClick={onCancelEdit} | ||
> | ||
{t('Cancel')} | ||
</Button> | ||
)} | ||
|
||
</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
Oops, something went wrong.