Skip to content

Commit

Permalink
fix: remove unnecessary helper text, rename class, fix profile persis…
Browse files Browse the repository at this point in the history
…t on relog
  • Loading branch information
naumovski-filip committed Jul 17, 2023
1 parent 9a98254 commit 1c7a537
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 7 deletions.
1 change: 0 additions & 1 deletion public/locales/en/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
"adult": "Adult",
"avatar": "Avatar",
"content_rating": "Content rating",
"content_rating_helper": "Content 12+ will not be available for kids profiles",
"create": "Create profile",
"delete": "Delete profile",
"delete_description": "Permanently delete your profile along with all of your watch history and favorites.",
Expand Down
1 change: 0 additions & 1 deletion public/locales/es/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
"adult": "",
"avatar": "",
"content_rating": "",
"content_rating_helper": "",
"create": "",
"delete": "",
"delete_description": "",
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProfileBox/ProfileBox.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
position: relative;
transition: all 0.5s ease;
}
.kids {
.kidsLabel {
position: absolute;
top: 5px;
right: 5px;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProfileBox/ProfileBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ProfileBox = ({ name, image, adult = true, editMode = false, onClick, onEd
<div className={classNames(styles.inner, selected && styles.selected)}>
<div onClick={onClick} className={styles.box}>
<img className={styles.image} src={image} alt="" />
{!adult && <span className={styles.kids}>Kids</span>}
{!adult && <span className={styles.kidsLabel}>Kids</span>}
</div>
{editMode && (
<div onClick={onEdit} className={styles.overlay}>
Expand Down
6 changes: 5 additions & 1 deletion src/components/Root/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const Root: FC = () => {
registerCustomScreens();
}, []);

const userData = useAccountStore((s) => ({ loading: s.loading, user: s.user }));
const userData = useAccountStore((s) => ({ loading: s.loading, user: s.user, profile: s.profile }));

if (userData.user && !userData.loading && window.location.href.includes('#token')) {
return <Navigate to="/" />; // component instead of hook to prevent extra re-renders
Expand All @@ -59,6 +59,10 @@ const Root: FC = () => {
return <LoadingOverlay />;
}

if (!userData.profile) {
return <Navigate to="/u/profiles" />;
}

if (settingsQuery.isError) {
return (
<ErrorPage
Expand Down
7 changes: 6 additions & 1 deletion src/components/UserMenu/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useConfigStore } from '#src/stores/ConfigStore';
import { useAccountStore } from '#src/stores/AccountStore';
import LoadingOverlay from '#components/LoadingOverlay/LoadingOverlay';
import Plus from '#src/icons/Plus';
import { useSelectProfile, useListProfiles } from '#src/hooks/useProfiles';
import { useSelectProfile, useListProfiles, unpersistProfile } from '#src/hooks/useProfiles';

type Props = {
small?: boolean;
Expand All @@ -32,6 +32,11 @@ const UserMenu = ({ showPaymentsItem, small = false, onClick }: Props) => {
const { data, isFetching } = useListProfiles();
const profiles = data?.responseData.collection;

if (!profiles?.length) {
unpersistProfile();
navigate('/u/profiles');
}

const selectProfile = useSelectProfile();

const onLogout = useCallback(async () => {
Expand Down
1 change: 0 additions & 1 deletion src/containers/Profiles/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ const Form = ({ initialValues, formHandler, setFullName, selectedAvatar, showCan
required
name="adult"
label={t('profile.content_rating')}
helperText={t('profile.content_rating_helper')}
className={styles.dropdown}
options={options}
value={values?.adult?.toString() || 'true'}
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/useProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ type ProfileSelectionPayload = {
navigate: (path: string) => void;
};

export const unpersistProfile = () => {
persist.removeItem(PERSIST_PROFILE);
persist.removeItem(PERSIST_KEY_ACCOUNT);
};

const handleProfileSelection = async ({ id, navigate }: ProfileSelectionPayload) => {
try {
useAccountStore.setState({ loading: true });
Expand Down

0 comments on commit 1c7a537

Please sign in to comment.