rename hasActiveSubscription from useCurrentUser() to hasOngoingSubscription

This commit is contained in:
m5r 2021-10-21 00:01:03 +02:00
parent 6dbdeac4d3
commit 1dd1c2bafe
6 changed files with 19 additions and 9 deletions

View File

@ -1,6 +1,6 @@
import { useQuery } from "blitz"; 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"; import useCurrentUser from "./use-current-user";
export default function useUserPhoneNumber() { export default function useUserPhoneNumber() {

View File

@ -15,7 +15,7 @@ export default function useCurrentUser() {
organization, organization,
hasFilledTwilioCredentials, hasFilledTwilioCredentials,
hasPhoneNumber: Boolean(phoneNumber), hasPhoneNumber: Boolean(phoneNumber),
hasActiveSubscription: organization && organization.subscriptions.length > 0, hasOngoingSubscription: organization && organization.subscriptions.length > 0,
refetch: userQuery.refetch, refetch: userQuery.refetch,
}; };
} }

View File

@ -10,7 +10,7 @@ import { formatRelativeDate } from "app/core/helpers/date-formatter";
import useCurrentUser from "app/core/hooks/use-current-user"; import useCurrentUser from "app/core/hooks/use-current-user";
export default function PhoneCallsList() { export default function PhoneCallsList() {
const { hasActiveSubscription } = useCurrentUser(); const { hasOngoingSubscription } = useCurrentUser();
const [phoneCalls, query] = usePhoneCalls(); const [phoneCalls, query] = usePhoneCalls();
useEffect(() => { useEffect(() => {
@ -25,7 +25,7 @@ export default function PhoneCallsList() {
} }
if (phoneCalls.length === 0) { if (phoneCalls.length === 0) {
return hasActiveSubscription ? <EmptyCalls /> : null; return hasOngoingSubscription ? <EmptyCalls /> : null;
} }
return ( return (

View File

@ -11,7 +11,7 @@ import InactiveSubscription from "app/core/components/inactive-subscription";
import PhoneCallsList from "../components/phone-calls-list"; import PhoneCallsList from "../components/phone-calls-list";
const PhoneCalls: BlitzPage = () => { const PhoneCalls: BlitzPage = () => {
const { hasFilledTwilioCredentials, hasPhoneNumber, hasActiveSubscription } = useCurrentUser(); const { hasFilledTwilioCredentials, hasPhoneNumber, hasOngoingSubscription } = useCurrentUser();
if (!hasFilledTwilioCredentials || !hasPhoneNumber) { if (!hasFilledTwilioCredentials || !hasPhoneNumber) {
return ( return (
@ -22,7 +22,7 @@ const PhoneCalls: BlitzPage = () => {
); );
} }
if (!hasActiveSubscription) { if (!hasOngoingSubscription) {
return ( return (
<> <>
<InactiveSubscription /> <InactiveSubscription />

View File

@ -15,7 +15,7 @@ import useCurrentUser from "app/core/hooks/use-current-user";
import KeypadErrorModal from "../components/keypad-error-modal"; import KeypadErrorModal from "../components/keypad-error-modal";
const KeypadPage: BlitzPage = () => { const KeypadPage: BlitzPage = () => {
const { hasFilledTwilioCredentials, hasPhoneNumber, hasActiveSubscription } = useCurrentUser(); const { hasFilledTwilioCredentials, hasPhoneNumber, hasOngoingSubscription } = useCurrentUser();
const router = useRouter(); const router = useRouter();
const [isKeypadErrorModalOpen, setIsKeypadErrorModalOpen] = useState(false); const [isKeypadErrorModalOpen, setIsKeypadErrorModalOpen] = useState(false);
const [phoneCalls] = usePhoneCalls(); const [phoneCalls] = usePhoneCalls();
@ -90,8 +90,10 @@ const KeypadPage: BlitzPage = () => {
return; return;
} }
if (!hasActiveSubscription) { if (!hasOngoingSubscription) {
// TODO // TODO
setIsKeypadErrorModalOpen(true);
return;
} }
if (phoneNumber === "") { if (phoneNumber === "") {

View File

@ -17,7 +17,15 @@ export default async function getCurrentUser(_ = null, { session }: Ctx) {
organization: { organization: {
include: { include: {
subscriptions: { subscriptions: {
where: { status: SubscriptionStatus.active }, where: {
OR: [
{ status: { not: SubscriptionStatus.deleted } },
{
status: SubscriptionStatus.deleted,
cancellationEffectiveDate: { gt: new Date() },
},
],
},
}, },
}, },
}, },