set your twilio things from settings

This commit is contained in:
m5r
2021-10-16 01:25:13 +02:00
parent 3cc6f35071
commit 2afd3554b3
18 changed files with 242 additions and 483 deletions

View File

@ -1,17 +1,21 @@
import { useSession, useQuery } from "blitz";
import getCurrentUser from "../../users/queries/get-current-user";
import getCurrentPhoneNumber from "../../phone-numbers/queries/get-current-phone-number";
export default function useCurrentUser() {
const session = useSession();
const [user] = useQuery(getCurrentUser, null, { enabled: Boolean(session.userId) });
const [user, userQuery] = useQuery(getCurrentUser, null, { enabled: Boolean(session.userId) });
const organization = user?.memberships[0]!.organization;
const hasFilledTwilioCredentials = Boolean(organization?.twilioAccountSid && organization?.twilioAuthToken);
const [phoneNumber] = useQuery(getCurrentPhoneNumber, {}, { enabled: hasFilledTwilioCredentials });
return {
user,
organization,
hasFilledTwilioCredentials: Boolean(
organization && organization.twilioAccountSid && organization.twilioAuthToken,
),
hasFilledTwilioCredentials,
hasPhoneNumber: Boolean(phoneNumber),
hasActiveSubscription: organization && organization.subscriptions.length > 0,
refetch: userQuery.refetch,
};
}