@umituz/react-native-subscription 2.14.88 → 2.14.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.89",
|
|
4
4
|
"description": "Complete subscription management with RevenueCat, paywall UI, and credits system for React Native apps",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"@umituz/react-native-design-system": "latest",
|
|
36
36
|
"@umituz/react-native-firebase": "latest",
|
|
37
37
|
"@umituz/react-native-localization": "latest",
|
|
38
|
-
"@umituz/react-native-storage": "latest"
|
|
38
|
+
"@umituz/react-native-storage": "latest",
|
|
39
|
+
"@umituz/react-native-timezone": "^1.3.5"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
42
|
"@tanstack/react-query": ">=5.0.0",
|
|
@@ -2,7 +2,14 @@
|
|
|
2
2
|
* Subscription Status Entity
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export const SUBSCRIPTION_STATUS = {
|
|
6
|
+
ACTIVE: 'active',
|
|
7
|
+
EXPIRED: 'expired',
|
|
8
|
+
CANCELED: 'canceled',
|
|
9
|
+
NONE: 'none',
|
|
10
|
+
} as const;
|
|
11
|
+
|
|
12
|
+
export type SubscriptionStatusType = (typeof SUBSCRIPTION_STATUS)[keyof typeof SUBSCRIPTION_STATUS];
|
|
6
13
|
|
|
7
14
|
export interface SubscriptionStatus {
|
|
8
15
|
isPremium: boolean;
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
AtomicText,
|
|
13
13
|
AtomicIcon,
|
|
14
14
|
} from "@umituz/react-native-design-system";
|
|
15
|
+
import { timezoneService } from "@umituz/react-native-timezone";
|
|
15
16
|
import type { CreditLog, TransactionReason } from "../../domain/types/transaction.types";
|
|
16
17
|
|
|
17
18
|
export interface TransactionItemTranslations {
|
|
@@ -47,7 +48,7 @@ const getReasonIcon = (reason: TransactionReason): string => {
|
|
|
47
48
|
|
|
48
49
|
const defaultDateFormatter = (timestamp: number): string => {
|
|
49
50
|
const date = new Date(timestamp);
|
|
50
|
-
return
|
|
51
|
+
return timezoneService.formatDateTime(date, "en-US", {
|
|
51
52
|
month: "short",
|
|
52
53
|
day: "numeric",
|
|
53
54
|
hour: "2-digit",
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
type SubscriptionStatus,
|
|
4
|
+
SUBSCRIPTION_STATUS,
|
|
5
|
+
type SubscriptionStatusType
|
|
6
|
+
} from "../../domain/entities/SubscriptionStatus";
|
|
3
7
|
import { isSubscriptionExpired } from "../../utils/dateValidationUtils";
|
|
4
8
|
import { formatDateForLocale, calculateDaysRemaining } from "../utils/subscriptionDateUtils";
|
|
5
9
|
|
|
@@ -19,7 +23,7 @@ export interface SubscriptionDetails {
|
|
|
19
23
|
/** Formatted purchase date */
|
|
20
24
|
formattedPurchaseDate: string | null;
|
|
21
25
|
/** Status text key for localization */
|
|
22
|
-
statusKey:
|
|
26
|
+
statusKey: SubscriptionStatusType;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
interface UseSubscriptionDetailsParams {
|
|
@@ -45,7 +49,7 @@ export function useSubscriptionDetails(
|
|
|
45
49
|
daysRemaining: null,
|
|
46
50
|
formattedExpirationDate: null,
|
|
47
51
|
formattedPurchaseDate: null,
|
|
48
|
-
statusKey:
|
|
52
|
+
statusKey: SUBSCRIPTION_STATUS.NONE,
|
|
49
53
|
};
|
|
50
54
|
}
|
|
51
55
|
|
|
@@ -54,9 +58,15 @@ export function useSubscriptionDetails(
|
|
|
54
58
|
const daysRemainingValue = calculateDaysRemaining(status.expiresAt ?? null);
|
|
55
59
|
const isPremium = status.isPremium && !isExpired;
|
|
56
60
|
|
|
57
|
-
let statusKey:
|
|
61
|
+
let statusKey: SubscriptionStatusType = status.status || SUBSCRIPTION_STATUS.NONE;
|
|
62
|
+
|
|
63
|
+
// Override status key based on current calculation for active/expired
|
|
58
64
|
if (status.isPremium) {
|
|
59
|
-
statusKey = isExpired ?
|
|
65
|
+
statusKey = isExpired ? SUBSCRIPTION_STATUS.EXPIRED : SUBSCRIPTION_STATUS.ACTIVE;
|
|
66
|
+
} else if (status.status === SUBSCRIPTION_STATUS.CANCELED) {
|
|
67
|
+
statusKey = SUBSCRIPTION_STATUS.CANCELED;
|
|
68
|
+
} else {
|
|
69
|
+
statusKey = SUBSCRIPTION_STATUS.NONE;
|
|
60
70
|
}
|
|
61
71
|
|
|
62
72
|
return {
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Subscription Date Utilities
|
|
3
|
-
* Date formatting and calculation utilities for subscription
|
|
4
|
-
*/
|
|
1
|
+
import { timezoneService } from "@umituz/react-native-timezone";
|
|
5
2
|
|
|
6
3
|
/**
|
|
7
4
|
* Converts Firestore timestamp or Date to ISO string
|
|
@@ -14,11 +11,13 @@ export const convertPurchasedAt = (purchasedAt: unknown): string | null => {
|
|
|
14
11
|
purchasedAt !== null &&
|
|
15
12
|
"toDate" in purchasedAt
|
|
16
13
|
) {
|
|
17
|
-
return
|
|
14
|
+
return timezoneService.formatToISOString(
|
|
15
|
+
(purchasedAt as { toDate: () => Date }).toDate()
|
|
16
|
+
);
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
if (purchasedAt instanceof Date) {
|
|
21
|
-
return
|
|
20
|
+
return timezoneService.formatToISOString(purchasedAt);
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
return null;
|
|
@@ -34,11 +33,11 @@ export const formatDateForLocale = (
|
|
|
34
33
|
if (!dateStr) return null;
|
|
35
34
|
|
|
36
35
|
try {
|
|
37
|
-
return new
|
|
36
|
+
return timezoneService.formatDate(new Date(dateStr), locale, {
|
|
38
37
|
year: "numeric",
|
|
39
38
|
month: "long",
|
|
40
39
|
day: "numeric",
|
|
41
|
-
})
|
|
40
|
+
});
|
|
42
41
|
} catch {
|
|
43
42
|
return null;
|
|
44
43
|
}
|
|
@@ -52,9 +51,11 @@ export const calculateDaysRemaining = (
|
|
|
52
51
|
): number | null => {
|
|
53
52
|
if (!expiresAtIso) return null;
|
|
54
53
|
|
|
55
|
-
const
|
|
54
|
+
const expiresDate = new Date(expiresAtIso);
|
|
56
55
|
const now = new Date();
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
|
|
57
|
+
// Use timezoneService's mathematical approach if possible, or keep existing log
|
|
58
|
+
const diff = expiresDate.getTime() - now.getTime();
|
|
59
59
|
return Math.max(0, Math.ceil(diff / (1000 * 60 * 60 * 24)));
|
|
60
60
|
};
|
|
61
|
+
|