Skip to content

Commit

Permalink
fix: additional profiles PR comments fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
naumovski-filip committed Oct 18, 2023
1 parent 029f684 commit 514f3ca
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 23 deletions.
3 changes: 3 additions & 0 deletions public/locales/en/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"login": {
"field_required": "This field is required"
},
"name": "Name",
"nav": {
"account": "Account",
"add_profile": "Add new profile",
Expand Down Expand Up @@ -123,6 +124,8 @@
"delete_description": "Permanently delete your profile along with all of your watch history and favorites.",
"delete_main": "The main profile cannot be deleted because it’s linked to your account's watch history and favorites.",
"description": "Profiles allow you to watch content and assemble your own personal collection of favorites.",
"done": "Done",
"edit": "Edit profile",
"form_error": "Something went wrong. Please try again later.",
"info": "Profile info",
"kids": "Kids",
Expand Down
1 change: 1 addition & 0 deletions public/locales/es/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"login": {
"field_required": ""
},
"name": "",
"nav": {
"account": "Cuenta",
"add_profile": "Añade un nuevo perfil",
Expand Down
7 changes: 7 additions & 0 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { ReactFragment, useState } from 'react';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
import type { UseMutateFunction } from 'react-query';

import styles from './Header.module.scss';

Expand Down Expand Up @@ -52,6 +53,8 @@ type Props = {
currentProfile?: Profile;
profiles?: Profile[];
profilesEnabled?: boolean;
selectProfile?: UseMutateFunction<unknown, unknown, { id: string; avatarUrl: string }, unknown>;
isSelectingProfile?: boolean;
accessModel?: AccessModel;
};

Expand Down Expand Up @@ -82,6 +85,8 @@ const Header: React.FC<Props> = ({
currentProfile,
profiles,
profilesEnabled,
selectProfile,
isSelectingProfile,
accessModel,
}) => {
const { t } = useTranslation('menu');
Expand Down Expand Up @@ -145,6 +150,8 @@ const Header: React.FC<Props> = ({
currentProfile={currentProfile}
profilesEnabled={profilesEnabled}
profiles={profiles}
selectProfile={selectProfile}
isSelectingProfile={!!isSelectingProfile}
/>
</Panel>
</Popover>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProfileBox/AddNewProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const AddNewProfile = ({ onClick }: Props) => {
const keyDownHandler = (event: React.KeyboardEvent<HTMLDivElement>) => (event.key === 'Enter' || event.key === ' ') && onClick();

return (
<div onClick={onClick} tabIndex={0} onKeyDown={keyDownHandler} className={classNames(styles.wrapper, styles.addProfileContainer)}>
<div onClick={onClick} tabIndex={0} onKeyDown={keyDownHandler} className={classNames(styles.wrapper, styles.addProfileContainer)} role="button">
<div className={styles.iconContainer}>
<div className={`${styles.box} ${styles.circle}`}>
<Plus />
Expand Down
8 changes: 6 additions & 2 deletions src/components/ProfileBox/ProfileBox.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';

import styles from './ProfileBox.module.scss';

Expand All @@ -19,14 +20,17 @@ type Props = {
};

const ProfileBox = ({ name, image, editMode = false, onClick, onEdit, selected = false }: Props) => {
const { t } = useTranslation('user');
const keyDownHandler = (event: React.KeyboardEvent<HTMLDivElement>) => (event.key === 'Enter' || event.key === ' ') && onClick();

return (
<div className={styles.wrapper}>
<div className={classNames(styles.inner, selected && styles.selected)}>
<div onClick={onClick} className={styles.box}>
<div onClick={onClick} className={styles.box} role="button" tabIndex={0} onKeyDown={keyDownHandler}>
<img className={styles.image} src={image || defaultAvatar} alt="" />
</div>
{editMode && (
<IconButton aria-label="edit-profile-button" onClick={onEdit} className={styles.overlay}>
<IconButton aria-label={t('profile.edit')} onClick={onEdit} className={styles.overlay}>
<Edit />
</IconButton>
)}
Expand Down
16 changes: 10 additions & 6 deletions src/components/UserMenu/ProfilesMenu/ProfilesMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ const ProfilesMenu = ({
<>
<li className={styles.sectionHeader}>{switchProfilesLabel}</li>
{selectingProfile ? (
<LoadingOverlay inline />
<li>
<LoadingOverlay inline />
</li>
) : (
profiles?.map((profile) => (
<li key={profile.id}>
Expand All @@ -54,11 +56,13 @@ const ProfilesMenu = ({
<MenuButton small={small} onClick={onCreateButtonClick} startIcon={<Plus />} label={createButtonLabel} />
</li>
)}
<hr
className={classNames(styles.divider, {
[styles.small]: small,
})}
/>
<li>
<hr
className={classNames(styles.divider, {
[styles.small]: small,
})}
/>
</li>
</>
);

Expand Down
28 changes: 20 additions & 8 deletions src/components/UserMenu/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useCallback } from 'react';
import { useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import classNames from 'classnames';
import type { UseMutateFunction } from 'react-query';

import styles from './UserMenu.module.scss';
import ProfilesMenu from './ProfilesMenu/ProfilesMenu';
Expand All @@ -12,7 +13,6 @@ import BalanceWallet from '#src/icons/BalanceWallet';
import Exit from '#src/icons/Exit';
import MenuButton from '#components/MenuButton/MenuButton';
import { logout } from '#src/stores/AccountController';
import { useSelectProfile } from '#src/hooks/useProfiles';
import ProfileCircle from '#src/icons/ProfileCircle';
import type { AccessModel } from '#types/Config';
import type { Profile } from '#types/account';
Expand All @@ -26,14 +26,24 @@ type Props = {
currentProfile?: Profile;
profilesEnabled?: boolean;
profiles?: Profile[];
isSelectingProfile?: boolean;
selectProfile?: UseMutateFunction<unknown, unknown, { id: string; avatarUrl: string }, unknown>;
};

const UserMenu = ({ showPaymentsItem, small = false, onClick, accessModel, currentProfile, profilesEnabled, profiles }: Props) => {
const UserMenu = ({
showPaymentsItem,
small = false,
onClick,
accessModel,
currentProfile,
profilesEnabled,
profiles,
isSelectingProfile,
selectProfile,
}: Props) => {
const { t } = useTranslation('user');
const navigate = useNavigate();

const selectProfile = useSelectProfile();

const onLogout = useCallback(async () => {
if (onClick) {
onClick();
Expand All @@ -45,13 +55,13 @@ const UserMenu = ({ showPaymentsItem, small = false, onClick, accessModel, curre

return (
<ul className={styles.menuItems}>
{accessModel === 'SVOD' && profilesEnabled && (
{accessModel === 'SVOD' && profilesEnabled && selectProfile && (
<ProfilesMenu
profiles={profiles ?? []}
currentProfile={currentProfile}
small={small}
selectingProfile={selectProfile.isLoading}
selectProfile={selectProfile.mutate}
selectingProfile={!!isSelectingProfile}
selectProfile={selectProfile}
defaultAvatar={defaultAvatar}
createButtonLabel={t('nav.add_profile')}
switchProfilesLabel={t('nav.switch_profiles')}
Expand Down Expand Up @@ -82,7 +92,9 @@ const UserMenu = ({ showPaymentsItem, small = false, onClick, accessModel, curre
<MenuButton small={small} onClick={onClick} to="/u/payments" label={t('nav.payments')} startIcon={<BalanceWallet />} />
</li>
)}
<hr className={classNames(styles.divider, { [styles.small]: small })} />
<li>
<hr className={classNames(styles.divider, { [styles.small]: small })} />
</li>
<li>
<MenuButton small={small} onClick={onLogout} label={t('nav.logout')} startIcon={<Exit />} />
</li>
Expand Down
8 changes: 5 additions & 3 deletions src/components/UserMenu/__snapshots__/UserMenu.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ exports[`<UserMenu> > renders and matches snapshot 1`] = `
</span>
</a>
</li>
<hr
class="_divider_457528"
/>
<li>
<hr
class="_divider_457528"
/>
</li>
<li>
<div
aria-label="nav.logout"
Expand Down
4 changes: 4 additions & 0 deletions src/containers/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const Layout = () => {
unpersistProfile();
}

const selectProfile = useSelectProfile();

const { searchQuery, searchActive, userMenuOpen, languageMenuOpen } = useUIStore(
({ searchQuery, searchActive, userMenuOpen, languageMenuOpen }) => ({
languageMenuOpen,
Expand Down Expand Up @@ -154,6 +156,8 @@ const Layout = () => {
currentProfile={profile ?? undefined}
profiles={profiles}
profilesEnabled={profilesEnabled}
selectProfile={selectProfile.mutate}
isSelectingProfile={!!selectProfile.isLoading}
accessModel={accessModel}
>
<Button label={t('home')} to="/" variant="text" />
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Profiles/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const Form = ({ initialValues, formHandler, selectedAvatar, showCancelButton = t
<div className={profileStyles.formFields}>
{errors.form ? <FormFeedback variant="error">{errors.form}</FormFeedback> : null}
{submitting && <LoadingOverlay inline />}
<h2 className={profileStyles.nameHeading}>Name</h2>
<h2 className={profileStyles.nameHeading}>{t('name')}</h2>
<TextField
required
name="name"
Expand Down
4 changes: 2 additions & 2 deletions src/containers/Profiles/Profiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const Profiles = ({ editMode = false }: Props) => {
<div className={styles.wrapper}>
{activeProfiles === 0 ? (
<div className={styles.headings}>
<p className={styles.paragarph}>{t('profile.no_one_watching')}</p>
<p className={styles.paragraph}>{t('profile.no_one_watching')}</p>
<h2 className={styles.heading}>{t('profile.create_message')}</h2>
</div>
) : (
Expand All @@ -71,7 +71,7 @@ const Profiles = ({ editMode = false }: Props) => {
{!editMode ? (
<Button onClick={() => navigate('/u/profiles/edit')} label={t('account.manage_profiles')} variant="outlined" size="large" fullWidth={isMobile} />
) : (
<Button onClick={() => navigate('/u/profiles')} label="Done" variant="outlined" size="large" fullWidth={isMobile} />
<Button onClick={() => navigate('/u/profiles')} label={t('profile.done')} variant="outlined" size="large" fullWidth={isMobile} />
)}
</div>
)}
Expand Down

0 comments on commit 514f3ca

Please sign in to comment.