Skip to content

Commit 2783368

Browse files
authored
refactor(console): update PaymentOverDueModal display logic (#7908)
* refactor(console): update PaymentOverDueModal display logic update PaymentOverDueModal display logic * fix(console): fix overdue label fix overdue label
1 parent 011c1f7 commit 2783368

File tree

7 files changed

+167
-77
lines changed

7 files changed

+167
-77
lines changed

packages/connectors/connector-logto-email/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"access": "public"
5353
},
5454
"devDependencies": {
55-
"@logto/cloud": "0.2.5-299028a",
55+
"@logto/cloud": "0.2.5-c450763",
5656
"@silverhand/eslint-config": "6.0.1",
5757
"@silverhand/ts-config": "6.0.0",
5858
"@types/node": "^22.14.0",

packages/console/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@fontsource/roboto-mono": "^5.0.0",
2929
"@inkeep/cxkit-react": "^0.5.66",
3030
"@jest/types": "^29.5.0",
31-
"@logto/cloud": "0.2.5-299028a",
31+
"@logto/cloud": "0.2.5-c450763",
3232
"@logto/connector-kit": "workspace:^",
3333
"@logto/core-kit": "workspace:^",
3434
"@logto/language-kit": "workspace:^",

packages/console/src/components/PaymentOverdueModal/index.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { Trans, useTranslation } from 'react-i18next';
33
import ReactModal from 'react-modal';
44

55
import { contactEmailLink } from '@/consts';
6-
import { isCloud } from '@/consts/env';
76
import { TenantsContext } from '@/contexts/TenantsProvider';
87
import Button from '@/ds-components/Button';
98
import FormField from '@/ds-components/FormField';
109
import InlineNotification from '@/ds-components/InlineNotification';
1110
import ModalLayout from '@/ds-components/ModalLayout';
11+
import useOverdueInvoices from '@/hooks/use-overdue-invoices';
1212
import useSubscribe from '@/hooks/use-subscribe';
1313
import modalStyles from '@/scss/modal.module.scss';
1414

@@ -23,20 +23,15 @@ function PaymentOverdueModal() {
2323

2424
const { visitManagePaymentPage } = useSubscribe();
2525
const [isActionLoading, setIsActionLoading] = useState(false);
26-
2726
const [hasClosed, setHasClosed] = useState(false);
2827

29-
// TODO: this is a temporary fix to hide the modal for enterprise tenants
30-
// Enterprise tenants' invoices are manually paid and has a due date in the future
31-
// Should show the modal only if the invoices are overdue
32-
const isEnterprise = currentTenant?.subscription.isEnterprisePlan;
28+
const { hasOverdueInvoices } = useOverdueInvoices();
3329

3430
const handleCloseModal = () => {
3531
setHasClosed(true);
3632
};
3733

38-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
39-
if (!isCloud || openInvoices.length === 0 || isEnterprise || hasClosed) {
34+
if (!hasOverdueInvoices || hasClosed) {
4035
return null;
4136
}
4237

packages/console/src/components/Topbar/TenantSelector/TenantDropdownItem/TenantStatusTag.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type TenantResponse } from '@/cloud/types/router';
22
import DynamicT from '@/ds-components/DynamicT';
33
import Tag from '@/ds-components/Tag';
4+
import useOverdueInvoices from '@/hooks/use-overdue-invoices';
45
import { isPaidPlan } from '@/utils/subscription';
56

67
type Props = {
@@ -12,11 +13,12 @@ function TenantStatusTag({ tenantData, className }: Props) {
1213
const {
1314
usage,
1415
quota,
15-
openInvoices,
1616
isSuspended,
1717
subscription: { planId, isEnterprisePlan },
1818
} = tenantData;
1919

20+
const { hasOverdueInvoices } = useOverdueInvoices();
21+
2022
/**
2123
* Tenant status priority:
2224
* 1. suspend
@@ -33,7 +35,7 @@ function TenantStatusTag({ tenantData, className }: Props) {
3335
);
3436
}
3537

36-
if (openInvoices.length > 0) {
38+
if (hasOverdueInvoices) {
3739
return (
3840
<Tag className={className}>
3941
<DynamicT forKey="tenants.status.overdue" />
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { useContext, useMemo } from 'react';
2+
3+
import { isCloud } from '@/consts/env';
4+
import { TenantsContext } from '@/contexts/TenantsProvider';
5+
6+
function useOverdueInvoices() {
7+
const { currentTenant } = useContext(TenantsContext);
8+
const { openInvoices = [] } = currentTenant ?? {};
9+
const isEnterprise = currentTenant?.subscription.isEnterprisePlan;
10+
11+
const hasOverdueInvoices = useMemo(() => {
12+
if (!isCloud || openInvoices.length === 0) {
13+
return false;
14+
}
15+
16+
// Enterprise tenants' invoices are manually paid and has a due date in the future
17+
// Should show the modal only if the invoices are overdue.
18+
// Keep this for now as some legacy invoices data might not have the `collectionMethod` and `dueDate` fields
19+
// TODO: this is a temporary fix to hide the modal for enterprise tenants. Remove this after all legacy invoices are handled.
20+
if (isEnterprise) {
21+
return false;
22+
}
23+
24+
return openInvoices.some(({ dueDate, collectionMethod }) => {
25+
switch (collectionMethod) {
26+
// For automatic collection method, consider open invoices always overdue
27+
case 'charge_automatically': {
28+
return true;
29+
}
30+
// For manual collection method, consider invoices overdue if past due date
31+
case 'send_invoice': {
32+
return dueDate && dueDate < new Date();
33+
}
34+
default: {
35+
// For legacy invoices without collection method, consider them overdue
36+
return true;
37+
}
38+
}
39+
});
40+
}, [isEnterprise, openInvoices]);
41+
42+
return useMemo(
43+
() => ({
44+
hasOverdueInvoices,
45+
openInvoices,
46+
}),
47+
[hasOverdueInvoices, openInvoices]
48+
);
49+
}
50+
51+
export default useOverdueInvoices;

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"zod": "3.24.3"
102102
},
103103
"devDependencies": {
104-
"@logto/cloud": "0.2.5-299028a",
104+
"@logto/cloud": "0.2.5-c450763",
105105
"@silverhand/eslint-config": "6.0.1",
106106
"@silverhand/ts-config": "6.0.0",
107107
"@types/adm-zip": "^0.5.5",

0 commit comments

Comments
 (0)