Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp
3.8 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-or-later

import {GenericErrorModal} from '@app/features/app/components/alerts/GenericErrorModal';
import {ConfirmModal} from '@app/features/app/components/dialogs/ConfirmModal';
import {Limits} from '@app/features/app/utils/UserLimits';
import * as PremiumModalCommands from '@app/features/premium/commands/PremiumModalCommands';
import {getPremiumProductName, shouldShowPremiumFeatures} from '@app/features/premium/utils/PremiumUtils';
import Users from '@app/features/user/state/Users';
import {MAX_FAVORITE_MEMES_PREMIUM} from '@fluxer/constants/src/LimitConstants';
import {msg, plural} from '@lingui/core/macro';
import {useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';

const SAVED_MEDIA_LIMIT_REACHED_DESCRIPTOR = msg({
	message: "You're at the saved media limit",
	comment: 'Short label in the max favorite memes modal.',
});
const YOU_VE_REACHED_THE_MAXIMUM_LIMIT_OF_THIS_DESCRIPTOR = msg({
	message:
		'You have {count, plural, one {# saved media item} other {# saved media items}}, the most your instance admin allows.',
	comment:
		'Modal body shown when the favorite-memes limit is reached on a self-hosted instance with no Plutonium upgrade path. {count} is the saved media cap.',
});
const YOU_VE_REACHED_THE_MAXIMUM_LIMIT_OF_FOR_DESCRIPTOR = msg({
	message:
		'You have {count, plural, one {# saved media item} other {# saved media items}}, the most you can have for free. With {premiumProductName} you can have up to {premiumCount, plural, one {# saved media item} other {# saved media items}}.',
	comment:
		'Modal body shown when the free favorite-memes limit is reached and Plutonium would increase it. {count} is the free cap, {premiumCount} the Plutonium cap.',
});
const UPGRADE_TO_DESCRIPTOR = msg({
	message: 'Upgrade to {premiumProductName}',
	comment: 'Short label in the max favorite memes modal. Preserve {premiumProductName}; it is inserted by code.',
});
const MAYBE_LATER_DESCRIPTOR = msg({
	message: 'Maybe later',
	comment: 'Short label in the max favorite memes modal.',
});
export const MaxFavoriteMemesModal = observer(() => {
	const {i18n} = useLingui();
	const currentUser = Users.currentUser;
	const showPremium = shouldShowPremiumFeatures();
	const premiumLimit = Limits.getStockValue('max_favorite_memes', MAX_FAVORITE_MEMES_PREMIUM);
	const maxFavoriteMemes = currentUser?.maxFavoriteMemes ?? premiumLimit;
	const canUpgradeFavoriteMemes = maxFavoriteMemes < premiumLimit;
	if (!showPremium) {
		return (
			<GenericErrorModal
				title={i18n._(SAVED_MEDIA_LIMIT_REACHED_DESCRIPTOR)}
				message={i18n._(YOU_VE_REACHED_THE_MAXIMUM_LIMIT_OF_THIS_DESCRIPTOR, {count: maxFavoriteMemes})}
				data-flx="app.max-favorite-memes-modal.confirm-modal"
			/>
		);
	}
	if (!canUpgradeFavoriteMemes) {
		const description = plural(
			{count: maxFavoriteMemes},
			{
				one: "You're at the cap of # saved media item. Remove one to add another.",
				other: "You're at the cap of # saved media items. Remove one to add another.",
			},
		);
		return (
			<ConfirmModal
				title={i18n._(SAVED_MEDIA_LIMIT_REACHED_DESCRIPTOR)}
				description={description}
				data-flx="app.max-favorite-memes-modal.confirm-modal--2"
			/>
		);
	}
	const freeDescription = i18n._(YOU_VE_REACHED_THE_MAXIMUM_LIMIT_OF_FOR_DESCRIPTOR, {
		count: maxFavoriteMemes,
		premiumProductName: getPremiumProductName(),
		premiumCount: premiumLimit,
	});
	return (
		<ConfirmModal
			title={i18n._(SAVED_MEDIA_LIMIT_REACHED_DESCRIPTOR)}
			description={freeDescription}
			primaryText={i18n._(UPGRADE_TO_DESCRIPTOR, {premiumProductName: getPremiumProductName()})}
			primaryVariant="primary"
			onPrimary={() => {
				window.setTimeout(() => {
					PremiumModalCommands.open();
				}, 0);
			}}
			secondaryText={i18n._(MAYBE_LATER_DESCRIPTOR)}
			data-flx="app.max-favorite-memes-modal.confirm-modal--3"
		/>
	);
});