Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions src/app/newSettings/Sections/General/components/Appearance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ const themes = [
{ theme: 'dark', img: appearance_dark },
];

const filterNewThemes = (newThemes, existingThemes) => {
return newThemes.filter(
(newTheme) => !existingThemes.some((existingTheme) => existingTheme.theme === newTheme.theme),
);
};

const createThemeAppearances = (themes) => {
return themes.map((theme) => ({
theme,
img: appearance_dark,
}));
};

const mergeThemes = (existingThemes, newThemes) => {
const filteredNewThemes = filterNewThemes(newThemes, existingThemes);
return [...existingThemes, ...filteredNewThemes];
};

const Appearance = () => {
const { translate } = useTranslationContext();
const { currentTheme, toggleTheme } = useThemeContext();
Expand All @@ -56,18 +74,10 @@ const Appearance = () => {
const { usedCoupons: userPromoCodes } = await paymentService.getPromoCodesUsedByUser();
const availableThemesService = new UserThemesService(userPromoCodes);

const allAvailableThemesForUSer = availableThemesService.getAllAvailableThemes();
const newAppearances = allAvailableThemesForUSer.map((theme) => ({
theme,
img: appearance_dark,
}));

setAppearances((prev) => {
const filteredNew = newAppearances.filter(
(newAppearance) => !prev.some((appearance) => appearance.theme === newAppearance.theme),
);
return [...prev, ...filteredNew];
});
const allAvailableThemesForUser = availableThemesService.getAllAvailableThemes();
const newAppearances = createThemeAppearances(allAvailableThemesForUser);

setAppearances((prev) => mergeThemes(prev, newAppearances));
} catch (error) {
console.error(`Something went wrong while fetching available themes for user. ERROR: ${error}`);
errorService.reportError(error);
Expand Down
2 changes: 1 addition & 1 deletion src/app/newSettings/components/SectionList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NavSection } from '../containers/SectionListContainer';
import { NavSection } from '../types/section.types';
import SectionItem, { SectionItemProps } from './SectionItem';

interface SectionListProps {
Expand Down
8 changes: 0 additions & 8 deletions src/app/newSettings/containers/SectionListContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import { RootState } from '../../store';
import workspacesSelectors from '../../store/slices/workspaces/workspaces.selectors';
import SectionList from '../components/SectionList';

export interface NavSection {
section?: string;
subsection?: string;
text: string;
isSubsection?: boolean;
notificationsNumber: number;
}

export const sectionItems = [
{
section: 'general',
Expand Down
7 changes: 7 additions & 0 deletions src/app/newSettings/types/section.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface NavSection {
section?: string;
subsection?: string;
text: string;
isSubsection?: boolean;
notificationsNumber: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CheckoutProductCard } from '../../components/checkout/CheckoutProductCa
import { CheckoutUserAuth } from '../../components/checkout/CheckoutUserAuth';
import { HeaderComponent } from '../../components/checkout/Header';
import { AuthMethodTypes, PaymentType } from '../../types';
import { CheckoutViewManager, UserInfoProps } from './CheckoutViewWrapper';
import { CheckoutViewManager, UserInfoProps } from './types/checkout.types';
import { CryptoCurrency } from '@internxt/sdk/dist/payments/types';
import { AvailableCryptoCurrenciesDropdown } from 'app/payment/components/checkout/AvailableCryptoCurrenciesDropdown';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import { planThunks } from '../../../store/slices/plan';
import { useThemeContext } from '../../../theme/ThemeProvider';
import authCheckoutService from '../../services/auth-checkout.service';
import { checkoutReducer, initialStateForCheckout } from '../../store/checkoutReducer';
import { AuthMethodTypes, PaymentType, PlanInterval } from '../../types';
import { PaymentType, PlanInterval } from '../../types';
import { CheckoutViewManager, UserInfoProps } from './types/checkout.types';
import CheckoutView from './CheckoutView';
import { useUserPayment } from 'app/payment/hooks/useUserPayment';
import { CRYPTO_PAYMENT_DIALOG_KEY, CryptoPaymentDialog } from 'app/payment/components/checkout/CryptoPaymentDialog';
Expand Down Expand Up @@ -61,30 +62,6 @@ export const THEME_STYLES = {
},
};

export interface UserInfoProps {
avatar: Blob | null;
name: string;
email: string;
}

export interface CheckoutViewManager {
onCouponInputChange: (coupon?: string) => Promise<void>;
onLogOut: () => Promise<void>;
onCountryChange: (country: string) => void;
onPostalCodeChange: (postalCode: string) => void;
onCheckoutButtonClicked: (
formData: IFormValues,
event: BaseSyntheticEvent<object, any, any> | undefined,
stripeSDK: Stripe | null,
elements: StripeElements | null,
) => Promise<void>;
onRemoveAppliedCouponCode: () => void;
handleAuthMethodChange: (method: AuthMethodTypes) => void;
onUserNameFromAddressElementChange: (userName: string) => void;
onSeatsChange: (seat: number) => void;
onCurrencyChange: (currency: string) => void;
}

const STATUS_CODE_ERROR = {
USER_EXISTS: 409,
COUPON_NOT_VALID: 422,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { BaseSyntheticEvent } from 'react';
import { Stripe, StripeElements } from '@stripe/stripe-js';
import { IFormValues } from '../../../../core/types';
import { AuthMethodTypes } from '../../../types';

export interface UserInfoProps {
avatar: Blob | null;
name: string;
email: string;
}

export interface CheckoutViewManager {
onCouponInputChange: (coupon?: string) => Promise<void>;
onLogOut: () => Promise<void>;
onCountryChange: (country: string) => void;
onPostalCodeChange: (postalCode: string) => void;
onCheckoutButtonClicked: (
formData: IFormValues,
event: BaseSyntheticEvent<object, any, any> | undefined,
stripeSDK: Stripe | null,
elements: StripeElements | null,
) => Promise<void>;
onRemoveAppliedCouponCode: () => void;
handleAuthMethodChange: (method: AuthMethodTypes) => void;
onUserNameFromAddressElementChange: (userName: string) => void;
onSeatsChange: (seat: number) => void;
onCurrencyChange: (currency: string) => void;
}
Loading