From 1dd1c2bafe77dc431ce44a8127fd064ce7c694c4 Mon Sep 17 00:00:00 2001 From: m5r Date: Thu, 21 Oct 2021 00:01:03 +0200 Subject: [PATCH] rename `hasActiveSubscription` from `useCurrentUser()` to `hasOngoingSubscription` --- app/core/hooks/use-current-phone-number.ts | 2 +- app/core/hooks/use-current-user.ts | 2 +- app/phone-calls/components/phone-calls-list.tsx | 4 ++-- app/phone-calls/pages/calls.tsx | 4 ++-- app/phone-calls/pages/keypad.tsx | 6 ++++-- app/users/queries/get-current-user.ts | 10 +++++++++- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/core/hooks/use-current-phone-number.ts b/app/core/hooks/use-current-phone-number.ts index a139c46..c483614 100644 --- a/app/core/hooks/use-current-phone-number.ts +++ b/app/core/hooks/use-current-phone-number.ts @@ -1,6 +1,6 @@ import { useQuery } from "blitz"; -import getCurrentPhoneNumber from "../../phone-numbers/queries/get-current-phone-number"; +import getCurrentPhoneNumber from "app/phone-numbers/queries/get-current-phone-number"; import useCurrentUser from "./use-current-user"; export default function useUserPhoneNumber() { diff --git a/app/core/hooks/use-current-user.ts b/app/core/hooks/use-current-user.ts index 201eacd..f6b3749 100644 --- a/app/core/hooks/use-current-user.ts +++ b/app/core/hooks/use-current-user.ts @@ -15,7 +15,7 @@ export default function useCurrentUser() { organization, hasFilledTwilioCredentials, hasPhoneNumber: Boolean(phoneNumber), - hasActiveSubscription: organization && organization.subscriptions.length > 0, + hasOngoingSubscription: organization && organization.subscriptions.length > 0, refetch: userQuery.refetch, }; } diff --git a/app/phone-calls/components/phone-calls-list.tsx b/app/phone-calls/components/phone-calls-list.tsx index 2a55c86..b19c62f 100644 --- a/app/phone-calls/components/phone-calls-list.tsx +++ b/app/phone-calls/components/phone-calls-list.tsx @@ -10,7 +10,7 @@ import { formatRelativeDate } from "app/core/helpers/date-formatter"; import useCurrentUser from "app/core/hooks/use-current-user"; export default function PhoneCallsList() { - const { hasActiveSubscription } = useCurrentUser(); + const { hasOngoingSubscription } = useCurrentUser(); const [phoneCalls, query] = usePhoneCalls(); useEffect(() => { @@ -25,7 +25,7 @@ export default function PhoneCallsList() { } if (phoneCalls.length === 0) { - return hasActiveSubscription ? : null; + return hasOngoingSubscription ? : null; } return ( diff --git a/app/phone-calls/pages/calls.tsx b/app/phone-calls/pages/calls.tsx index be843fc..966a6af 100644 --- a/app/phone-calls/pages/calls.tsx +++ b/app/phone-calls/pages/calls.tsx @@ -11,7 +11,7 @@ import InactiveSubscription from "app/core/components/inactive-subscription"; import PhoneCallsList from "../components/phone-calls-list"; const PhoneCalls: BlitzPage = () => { - const { hasFilledTwilioCredentials, hasPhoneNumber, hasActiveSubscription } = useCurrentUser(); + const { hasFilledTwilioCredentials, hasPhoneNumber, hasOngoingSubscription } = useCurrentUser(); if (!hasFilledTwilioCredentials || !hasPhoneNumber) { return ( @@ -22,7 +22,7 @@ const PhoneCalls: BlitzPage = () => { ); } - if (!hasActiveSubscription) { + if (!hasOngoingSubscription) { return ( <> diff --git a/app/phone-calls/pages/keypad.tsx b/app/phone-calls/pages/keypad.tsx index a4d4230..9a9f82a 100644 --- a/app/phone-calls/pages/keypad.tsx +++ b/app/phone-calls/pages/keypad.tsx @@ -15,7 +15,7 @@ import useCurrentUser from "app/core/hooks/use-current-user"; import KeypadErrorModal from "../components/keypad-error-modal"; const KeypadPage: BlitzPage = () => { - const { hasFilledTwilioCredentials, hasPhoneNumber, hasActiveSubscription } = useCurrentUser(); + const { hasFilledTwilioCredentials, hasPhoneNumber, hasOngoingSubscription } = useCurrentUser(); const router = useRouter(); const [isKeypadErrorModalOpen, setIsKeypadErrorModalOpen] = useState(false); const [phoneCalls] = usePhoneCalls(); @@ -90,8 +90,10 @@ const KeypadPage: BlitzPage = () => { return; } - if (!hasActiveSubscription) { + if (!hasOngoingSubscription) { // TODO + setIsKeypadErrorModalOpen(true); + return; } if (phoneNumber === "") { diff --git a/app/users/queries/get-current-user.ts b/app/users/queries/get-current-user.ts index bceb966..da6ac97 100644 --- a/app/users/queries/get-current-user.ts +++ b/app/users/queries/get-current-user.ts @@ -17,7 +17,15 @@ export default async function getCurrentUser(_ = null, { session }: Ctx) { organization: { include: { subscriptions: { - where: { status: SubscriptionStatus.active }, + where: { + OR: [ + { status: { not: SubscriptionStatus.deleted } }, + { + status: SubscriptionStatus.deleted, + cancellationEffectiveDate: { gt: new Date() }, + }, + ], + }, }, }, },