Skip to content

Commit

Permalink
Removed old preferences navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon Candel authored and Ramon Candel committed Jul 30, 2024
1 parent 3202944 commit 9aab333
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 22 deletions.
8 changes: 1 addition & 7 deletions src/app/drive/components/WarningMessage/WarningMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { WarningCircle } from '@phosphor-icons/react';
import { t } from 'i18next';
import Button from '../../../shared/components/Button/Button';
import navigationService from '../../../core/services/navigation.service';
import { AppView } from '../../../core/types';

export const WarningMessage = (): JSX.Element => {
const onUpgradeButtonClicked = () => {
navigationService.push(AppView.Preferences, { tab: 'plans' });
};

export const WarningMessage = ({ onUpgradeButtonClicked }: { onUpgradeButtonClicked: () => void }): JSX.Element => {
return (
<div className="mx-5 my-1 flex h-12 w-auto flex-row items-center rounded-lg bg-red/10">
<span className="flex w-auto grow flex-row items-center px-4">
Expand Down
20 changes: 18 additions & 2 deletions src/app/drive/components/WarningMessage/WarningMessageWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { connect } from 'react-redux';
import { connect, useDispatch } from 'react-redux';
import navigationService from '../../../core/services/navigation.service';
import { RootState } from '../../../store';
import { useAppSelector } from '../../../store/hooks';
import { planSelectors } from '../../../store/slices/plan';
import { uiActions } from '../../../store/slices/ui';
import workspacesSelectors from '../../../store/slices/workspaces/workspaces.selectors';
import { WarningMessage } from './WarningMessage';

type WarningMessageWrapperProps = {
Expand All @@ -16,6 +20,18 @@ const WarningMessageWrapper = ({
isLoadingPlanLimit,
isLoadingPlanUsage,
}: WarningMessageWrapperProps): JSX.Element => {
const dispatch = useDispatch();
const selectedWorkspace = useAppSelector(workspacesSelectors.getSelectedWorkspace);

const onUpgradeButtonClicked = () => {
navigationService.openPreferencesDialog({
section: 'account',
subsection: 'plans',
workspaceUuid: selectedWorkspace?.workspaceUser.workspaceId,
});
dispatch(uiActions.setIsPreferencesDialogOpen(true));
};

const isLimitReached = planUsage >= planLimit;
const isLoading = isLoadingPlanLimit || isLoadingPlanUsage;
const plansNotFetched = planUsage === 0 && planLimit === 0;
Expand All @@ -24,7 +40,7 @@ const WarningMessageWrapper = ({

if (plansNotFetched || areNotNumbers || !isLimitReached || isLoading) return <></>;

return <WarningMessage />;
return <WarningMessage onUpgradeButtonClicked={onUpgradeButtonClicked} />;
};

export default connect((state: RootState) => ({
Expand Down
22 changes: 15 additions & 7 deletions src/app/payment/views/CheckoutView/CheckoutPlanView.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { UserType } from '@internxt/sdk/dist/drive/payments/types';
import { UserSettings } from '@internxt/sdk/dist/shared/types/userSettings';
import { useSelector } from 'react-redux';
import navigationService from 'app/core/services/navigation.service';
import { AppView } from 'app/core/types';
import { useTranslationContext } from 'app/i18n/provider/TranslationProvider';
import notificationsService, { ToastType } from 'app/notifications/services/notifications.service';
import paymentService from 'app/payment/services/payment.service';
import { RootState } from 'app/store';
import { useAppDispatch } from 'app/store/hooks';
import { useAppDispatch, useAppSelector } from 'app/store/hooks';
import { planActions, PlanState } from 'app/store/slices/plan';
import navigationService from 'app/core/services/navigation.service';
import { AppView } from 'app/core/types';
import { useEffect } from 'react';
import { useTranslationContext } from 'app/i18n/provider/TranslationProvider';
import { UserType } from '@internxt/sdk/dist/drive/payments/types';
import { useSelector } from 'react-redux';
import { uiActions } from '../../../store/slices/ui';
import workspacesSelectors from '../../../store/slices/workspaces/workspaces.selectors';

interface CheckoutOptions {
price_id: string;
Expand All @@ -25,6 +27,7 @@ interface CheckoutOptions {
export default function CheckoutPlanView(): JSX.Element {
const dispatch = useAppDispatch();
const { translate } = useTranslationContext();
const selectedWorkspace = useAppSelector(workspacesSelectors.getSelectedWorkspace);

const plan = useSelector((state: RootState) => state.plan) as PlanState;
const user = useSelector((state: RootState) => state.user.user) as UserSettings;
Expand Down Expand Up @@ -118,7 +121,12 @@ export default function CheckoutPlanView(): JSX.Element {
if (userSubscription.userType == UserType.Business)
dispatch(planActions.setSubscriptionBusiness(userSubscription));
}
navigationService.push(AppView.Preferences);
navigationService.openPreferencesDialog({
section: 'account',
subsection: 'account',
workspaceUuid: selectedWorkspace?.workspaceUser.workspaceId,
});
dispatch(uiActions.setIsPreferencesDialogOpen(true));
} catch (err) {
console.error(err);
notificationsService.show({
Expand Down
24 changes: 18 additions & 6 deletions src/app/store/slices/referrals/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
import desktopService from 'app/core/services/desktop.service';
import navigationService from 'app/core/services/navigation.service';
import { AppView } from 'app/core/types';
import usersReferralsService from 'app/referrals/services/users-referrals.service';

import { UserReferral, ReferralKey } from '@internxt/sdk/dist/drive/referrals/types';
import { ReferralKey, UserReferral } from '@internxt/sdk/dist/drive/referrals/types';
import notificationsService, { ToastType } from 'app/notifications/services/notifications.service';
import { RootState } from 'app/store';
import { planThunks } from '../plan';
import { uiActions } from '../ui';
import { userSelectors } from '../user';
import notificationsService, { ToastType } from 'app/notifications/services/notifications.service';

interface ReferralsState {
isLoading: boolean;
Expand Down Expand Up @@ -50,7 +49,10 @@ const refreshUserReferrals = createAsyncThunk<void, void, { state: RootState }>(

const executeUserReferralActionThunk = createAsyncThunk<void, { referralKey: ReferralKey }, { state: RootState }>(
'referrals/executeUserReferralActionThunk',
({ referralKey }, { dispatch }) => {
({ referralKey }, { dispatch, getState }) => {
const state = getState();
const selectedWorkspace = state.workspaces.selectedWorkspace;

const getDownloadApp = async () => {
const download = await desktopService.getDownloadAppUrl();
return download;
Expand All @@ -74,11 +76,21 @@ const executeUserReferralActionThunk = createAsyncThunk<void, { referralKey: Ref
break;
}
case ReferralKey.InviteFriends: {
navigationService.push(AppView.Preferences, { tab: 'account' });
navigationService.openPreferencesDialog({
section: 'account',
subsection: 'account',
workspaceUuid: selectedWorkspace?.workspaceUser.workspaceId,
});
dispatch(uiActions.setIsPreferencesDialogOpen(true));
break;
}
case ReferralKey.Invite2Friends: {
navigationService.push(AppView.Preferences, { tab: 'account' });
navigationService.openPreferencesDialog({
section: 'account',
subsection: 'account',
workspaceUuid: selectedWorkspace?.workspaceUser.workspaceId,
});
dispatch(uiActions.setIsPreferencesDialogOpen(true));
break;
}
case ReferralKey.CompleteSurvey: {
Expand Down

0 comments on commit 9aab333

Please sign in to comment.