Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat(subscription): only re-enable channels when the limit grows, tell the user after checkout

Gilad Resisic145f0c3b663
diff --git a/apps/frontend/src/components/launches/launches.component.tsx b/apps/frontend/src/components/launches/launches.component.tsx
index bb8d9ce6d..be3fde1b8 100644
--- a/apps/frontend/src/components/launches/launches.component.tsx
+++ b/apps/frontend/src/components/launches/launches.component.tsx
@@ -29,6 +29,7 @@ import { useT } from '@gitroom/react/translation/get.transation.service.client';
import { useIntegrationList } from '@gitroom/frontend/components/launches/helpers/use.integration.list';
import useCookie from 'react-use-cookie';
import { Onboarding } from '@gitroom/frontend/components/onboarding/onboarding';
+import { ChannelsAfterPayment } from '@gitroom/frontend/components/layout/check.payment';
import { useModals } from '@gitroom/frontend/components/layout/new-modal';
export const SVGLine = () => {
@@ -523,6 +524,7 @@ export const LaunchesComponent = () => {
return (
<DNDProvider>
<Onboarding />
+ <ChannelsAfterPayment integrations={integrations} />
<CalendarWeekProvider integrations={sortedIntegrations}>
<div
className={clsx(
diff --git a/apps/frontend/src/components/layout/check.payment.tsx b/apps/frontend/src/components/layout/check.payment.tsx
index 35dd866d5..97c813083 100644
--- a/apps/frontend/src/components/layout/check.payment.tsx
+++ b/apps/frontend/src/components/layout/check.payment.tsx
@@ -1,9 +1,11 @@
-import { FC, ReactNode, useCallback, useEffect, useState } from 'react';
+import { FC, ReactNode, useCallback, useEffect, useRef, useState } from 'react';
+import { useSearchParams } from 'next/navigation';
import Loading from '@gitroom/frontend/components/layout/loading';
import { useFetch } from '@gitroom/helpers/utils/custom.fetch';
import { timer } from '@gitroom/helpers/utils/timer';
import { useToaster } from '@gitroom/react/toaster/toaster';
import { useDecisionModal } from '@gitroom/frontend/components/layout/new-modal';
+import { useT } from '@gitroom/react/translation/get.transation.service.client';
export const CheckPayment: FC<{
check: string;
mutate: () => void;
@@ -76,3 +78,49 @@ export const CheckPaymentInner: FC<{
}
return props.children;
};
+
+export const ChannelsAfterPayment: FC<{
+ integrations: { disabled: boolean }[];
+}> = ({ integrations }) => {
+ const check = useSearchParams().get('check');
+ const fetch = useFetch();
+ const modal = useDecisionModal();
+ const t = useT();
+ const shown = useRef(false);
+
+ useEffect(() => {
+ if (!check || shown.current || !integrations?.length) {
+ return;
+ }
+ shown.current = true;
+ (async () => {
+ const { status } = await (await fetch('/billing/check/' + check)).json();
+ if (status !== 2) {
+ return;
+ }
+ if (integrations.some((p) => p.disabled)) {
+ modal.open({
+ title: t('channels_still_disabled', 'Your channels are disabled'),
+ onlyApprove: true,
+ approveLabel: t('ok', 'OK'),
+ description: t(
+ 'channels_still_disabled_description',
+ "Your plan doesn't cover all of your connected channels, so they stay disabled. Enable the ones you want from each channel's menu, up to your plan's limit, or upgrade your plan to enable all of them."
+ ),
+ });
+ return;
+ }
+ modal.open({
+ title: t('channels_enabled_again', 'Your channels are enabled'),
+ onlyApprove: true,
+ approveLabel: t('ok', 'OK'),
+ description: t(
+ 'channels_enabled_again_description',
+ 'All of your connected channels were enabled again and are ready to publish.'
+ ),
+ });
+ })();
+ }, [check, integrations]);
+
+ return null;
+};
diff --git a/libraries/nestjs-libraries/src/database/prisma/subscriptions/subscription.service.ts b/libraries/nestjs-libraries/src/database/prisma/subscriptions/subscription.service.ts
index e7e749e04..f66cbbe25 100644
--- a/libraries/nestjs-libraries/src/database/prisma/subscriptions/subscription.service.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/subscriptions/subscription.service.ts
@@ -121,12 +121,14 @@ export class SubscriptionService {
}
// channels are auto-disabled when a subscription lapses; once the new plan
- // can hold all of them, enable everything back (partial enabling would risk
- // enabling channels the user disabled on purpose)
+ // can hold all of them and the limit grew, enable everything back (partial
+ // enabling or same-plan updates would risk enabling channels the user
+ // disabled on purpose)
if (
billing !== 'FREE' &&
currentTotalChannels.length < allChannels.length &&
- allChannels.length <= totalChannels
+ allChannels.length <= totalChannels &&
+ totalChannels > (getCurrentSubscription?.totalChannels || 0)
) {
await this._integrationService.enableAllIntegrations(organizationId);
}
@@ -194,12 +196,14 @@ export class SubscriptionService {
}
// channels are auto-disabled when a subscription lapses; once the new plan
- // can hold all of them, enable everything back (partial enabling would risk
- // enabling channels the user disabled on purpose)
+ // can hold all of them and the limit grew, enable everything back (partial
+ // enabling or same-plan updates would risk enabling channels the user
+ // disabled on purpose)
if (
billing !== 'FREE' &&
currentTotalChannels.length < allChannels.length &&
- allChannels.length <= totalChannels
+ allChannels.length <= totalChannels &&
+ totalChannels > (getCurrentSubscription?.totalChannels || 0)
) {
await this._integrationService.enableAllIntegrations(
getOrgByCustomerId?.id!