get rid of onboarding requirements
This commit is contained in:
@ -22,7 +22,7 @@ export default function EmptyMessages() {
|
||||
<p className="mt-1 text-sm text-gray-500">Get started by calling someone you know.</p>
|
||||
<div className="mt-6">
|
||||
<Link href={Routes.KeypadPage()}>
|
||||
<a className="inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-[#007AFF] focus:outline-none focus:ring-2 focus:ring-offset-2">
|
||||
<a className="inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-primary-500 focus:outline-none focus:ring-2 focus:ring-offset-2">
|
||||
<IoKeypad className="-ml-1 mr-2 h-5 w-5" aria-hidden="true" />
|
||||
Open keypad
|
||||
</a>
|
||||
|
53
app/phone-calls/components/keypad-error-modal.tsx
Normal file
53
app/phone-calls/components/keypad-error-modal.tsx
Normal file
@ -0,0 +1,53 @@
|
||||
import type { FunctionComponent } from "react";
|
||||
import { useRef } from "react";
|
||||
import { Link, Routes, useRouter } from "blitz";
|
||||
|
||||
import Modal, { ModalTitle } from "app/core/components/modal";
|
||||
|
||||
type Props = {
|
||||
isOpen: boolean;
|
||||
closeModal: () => void;
|
||||
};
|
||||
|
||||
const KeypadErrorModal: FunctionComponent<Props> = ({ isOpen, closeModal }) => {
|
||||
const openSettingsButtonRef = useRef<HTMLButtonElement>(null);
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<Modal initialFocus={openSettingsButtonRef} isOpen={isOpen} onClose={closeModal}>
|
||||
<div className="md:flex md:items-start">
|
||||
<div className="mt-3 text-center md:mt-0 md:ml-4 md:text-left">
|
||||
<ModalTitle>Woah, hold on! Set up your 🐚phone number first</ModalTitle>
|
||||
<div className="mt-2 text-gray-500">
|
||||
<p>
|
||||
First things first. Head over to your{" "}
|
||||
<Link href={Routes.PhoneSettings()}>
|
||||
<a className="underline">phone settings</a>
|
||||
</Link>{" "}
|
||||
to set up your phone number.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-5 md:mt-4 md:flex md:flex-row-reverse">
|
||||
<button
|
||||
ref={openSettingsButtonRef}
|
||||
type="button"
|
||||
className="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-primary-500 text-base font-medium text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 md:mt-0 md:w-auto md:text-sm"
|
||||
onClick={() => router.push(Routes.PhoneSettings())}
|
||||
>
|
||||
Take me there
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 md:mt-0 md:w-auto md:text-sm"
|
||||
onClick={closeModal}
|
||||
>
|
||||
I got it, thanks!
|
||||
</button>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default KeypadErrorModal;
|
@ -1,14 +1,15 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useMutation } from "blitz";
|
||||
import { NotFoundError, Routes, useMutation, useRouter } from "blitz";
|
||||
import type { TwilioError } from "@twilio/voice-sdk";
|
||||
import { Call, Device } from "@twilio/voice-sdk";
|
||||
|
||||
import getToken from "../mutations/get-token";
|
||||
import appLogger from "../../../integrations/logger";
|
||||
import appLogger from "integrations/logger";
|
||||
|
||||
const logger = appLogger.child({ module: "use-device" });
|
||||
|
||||
export default function useDevice() {
|
||||
const router = useRouter();
|
||||
const [device, setDevice] = useState<Device | null>(null);
|
||||
const [isDeviceReady, setIsDeviceReady] = useState(() => device?.state === Device.State.Registered);
|
||||
const [getTokenMutation] = useMutation(getToken);
|
||||
@ -18,9 +19,17 @@ export default function useDevice() {
|
||||
return;
|
||||
}
|
||||
|
||||
const token = await getTokenMutation();
|
||||
device.updateToken(token);
|
||||
}, [device, getTokenMutation]);
|
||||
try {
|
||||
const token = await getTokenMutation();
|
||||
device.updateToken(token);
|
||||
} catch (error) {
|
||||
if (error instanceof NotFoundError) {
|
||||
throw router.push(Routes.KeypadPage());
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}, [device, getTokenMutation, router]);
|
||||
|
||||
useEffect(() => {
|
||||
const intervalId = setInterval(() => {
|
||||
@ -31,17 +40,25 @@ export default function useDevice() {
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const token = await getTokenMutation();
|
||||
const device = new Device(token, {
|
||||
codecPreferences: [Call.Codec.Opus, Call.Codec.PCMU],
|
||||
sounds: {
|
||||
[Device.SoundName.Disconnect]: undefined, // TODO
|
||||
},
|
||||
});
|
||||
device.register();
|
||||
setDevice(device);
|
||||
try {
|
||||
const token = await getTokenMutation();
|
||||
const device = new Device(token, {
|
||||
codecPreferences: [Call.Codec.Opus, Call.Codec.PCMU],
|
||||
sounds: {
|
||||
[Device.SoundName.Disconnect]: undefined, // TODO
|
||||
},
|
||||
});
|
||||
device.register();
|
||||
setDevice(device);
|
||||
} catch (error) {
|
||||
if (error instanceof NotFoundError) {
|
||||
throw router.push(Routes.KeypadPage());
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
})();
|
||||
}, [getTokenMutation, setDevice]);
|
||||
}, [getTokenMutation, setDevice, router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!device) {
|
||||
|
@ -5,9 +5,6 @@ import getPhoneCalls from "../queries/get-phone-calls";
|
||||
|
||||
export default function usePhoneCalls() {
|
||||
const phoneNumber = useCurrentPhoneNumber();
|
||||
if (!phoneNumber) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
|
||||
return useQuery(getPhoneCalls, { phoneNumberId: phoneNumber.id });
|
||||
return useQuery(getPhoneCalls, { phoneNumberId: phoneNumber?.id as string }, { enabled: Boolean(phoneNumber) });
|
||||
}
|
||||
|
@ -2,18 +2,27 @@ import { Suspense } from "react";
|
||||
import type { BlitzPage } from "blitz";
|
||||
import { Routes } from "blitz";
|
||||
|
||||
import Layout from "../../core/layouts/layout";
|
||||
import Layout from "app/core/layouts/layout";
|
||||
import PhoneCallsList from "../components/phone-calls-list";
|
||||
import useRequireOnboarding from "../../core/hooks/use-require-onboarding";
|
||||
import MissingTwilioCredentials from "app/core/components/missing-twilio-credentials";
|
||||
import useCurrentUser from "app/core/hooks/use-current-user";
|
||||
import PageTitle from "../../core/components/page-title";
|
||||
|
||||
const PhoneCalls: BlitzPage = () => {
|
||||
useRequireOnboarding();
|
||||
const { hasFilledTwilioCredentials } = useCurrentUser();
|
||||
|
||||
if (!hasFilledTwilioCredentials) {
|
||||
return (
|
||||
<>
|
||||
<MissingTwilioCredentials />
|
||||
<PageTitle className="filter blur-sm absolute top-0" title="Calls" />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col space-y-6 py-3 pl-12">
|
||||
<h2 className="text-3xl font-bold">Calls</h2>
|
||||
</div>
|
||||
<PageTitle className="pl-12" title="Calls" />
|
||||
<section className="flex flex-grow flex-col">
|
||||
<Suspense fallback="Loading...">
|
||||
<PhoneCallsList />
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Fragment, useRef } from "react";
|
||||
import { Fragment, useRef, useState } from "react";
|
||||
import type { BlitzPage } from "blitz";
|
||||
import { Routes, useRouter } from "blitz";
|
||||
import { atom, useAtom } from "jotai";
|
||||
@ -7,15 +7,17 @@ import { Transition } from "@headlessui/react";
|
||||
import { IoBackspace, IoCall } from "react-icons/io5";
|
||||
|
||||
import { Direction } from "db";
|
||||
import Layout from "../../core/layouts/layout";
|
||||
import Layout from "app/core/layouts/layout";
|
||||
import Keypad from "../components/keypad";
|
||||
import useRequireOnboarding from "../../core/hooks/use-require-onboarding";
|
||||
import usePhoneCalls from "../hooks/use-phone-calls";
|
||||
import useKeyPress from "../hooks/use-key-press";
|
||||
import useCurrentUser from "app/core/hooks/use-current-user";
|
||||
import KeypadErrorModal from "../components/keypad-error-modal";
|
||||
|
||||
const KeypadPage: BlitzPage = () => {
|
||||
useRequireOnboarding();
|
||||
const { hasFilledTwilioCredentials, hasActiveSubscription } = useCurrentUser();
|
||||
const router = useRouter();
|
||||
const [isKeypadErrorModalOpen, setIsKeypadErrorModalOpen] = useState(false);
|
||||
const [phoneCalls] = usePhoneCalls();
|
||||
const [phoneNumber, setPhoneNumber] = useAtom(phoneNumberAtom);
|
||||
const removeDigit = useAtom(pressBackspaceAtom)[1];
|
||||
@ -74,49 +76,61 @@ const KeypadPage: BlitzPage = () => {
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="w-96 h-full flex flex-col justify-around py-5 mx-auto text-center text-black">
|
||||
<div className="h-16 text-3xl text-gray-700">
|
||||
<span>{phoneNumber}</span>
|
||||
</div>
|
||||
<>
|
||||
<div className="w-96 h-full flex flex-col justify-around py-5 mx-auto text-center text-black">
|
||||
<div className="h-16 text-3xl text-gray-700">
|
||||
<span>{phoneNumber}</span>
|
||||
</div>
|
||||
|
||||
<Keypad onDigitPressProps={onDigitPressProps} onZeroPressProps={onZeroPressProps}>
|
||||
<button
|
||||
onClick={async () => {
|
||||
if (phoneNumber === "") {
|
||||
const lastCall = phoneCalls?.[0];
|
||||
if (lastCall) {
|
||||
const lastCallRecipient =
|
||||
lastCall.direction === Direction.Inbound ? lastCall.from : lastCall.to;
|
||||
setPhoneNumber(lastCallRecipient);
|
||||
<Keypad onDigitPressProps={onDigitPressProps} onZeroPressProps={onZeroPressProps}>
|
||||
<button
|
||||
onClick={async () => {
|
||||
if (!hasFilledTwilioCredentials) {
|
||||
setIsKeypadErrorModalOpen(true);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if (!hasActiveSubscription) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
await router.push(Routes.OutgoingCall({ recipient: encodeURI(phoneNumber) }));
|
||||
setPhoneNumber("");
|
||||
}}
|
||||
className="cursor-pointer select-none col-start-2 h-12 w-12 flex justify-center items-center mx-auto bg-green-800 rounded-full"
|
||||
>
|
||||
<IoCall className="w-6 h-6 text-white" />
|
||||
</button>
|
||||
if (phoneNumber === "") {
|
||||
const lastCall = phoneCalls?.[0];
|
||||
if (lastCall) {
|
||||
const lastCallRecipient =
|
||||
lastCall.direction === Direction.Inbound ? lastCall.from : lastCall.to;
|
||||
setPhoneNumber(lastCallRecipient);
|
||||
}
|
||||
|
||||
<Transition
|
||||
as={Fragment}
|
||||
show={phoneNumber.length > 0}
|
||||
enter="transition duration-300 ease-in-out"
|
||||
enterFrom="transform scale-95 opacity-0"
|
||||
enterTo="transform scale-100 opacity-100"
|
||||
leave="transition duration-100 ease-out"
|
||||
leaveFrom="transform scale-100 opacity-100"
|
||||
leaveTo="transform scale-95 opacity-0"
|
||||
>
|
||||
<div {...onBackspacePress} className="cursor-pointer select-none m-auto">
|
||||
<IoBackspace className="w-6 h-6" />
|
||||
</div>
|
||||
</Transition>
|
||||
</Keypad>
|
||||
</div>
|
||||
return;
|
||||
}
|
||||
|
||||
await router.push(Routes.OutgoingCall({ recipient: encodeURI(phoneNumber) }));
|
||||
setPhoneNumber("");
|
||||
}}
|
||||
className="cursor-pointer select-none col-start-2 h-12 w-12 flex justify-center items-center mx-auto bg-green-800 rounded-full"
|
||||
>
|
||||
<IoCall className="w-6 h-6 text-white" />
|
||||
</button>
|
||||
|
||||
<Transition
|
||||
as={Fragment}
|
||||
show={phoneNumber.length > 0}
|
||||
enter="transition duration-300 ease-in-out"
|
||||
enterFrom="transform scale-95 opacity-0"
|
||||
enterTo="transform scale-100 opacity-100"
|
||||
leave="transition duration-100 ease-out"
|
||||
leaveFrom="transform scale-100 opacity-100"
|
||||
leaveTo="transform scale-95 opacity-0"
|
||||
>
|
||||
<div {...onBackspacePress} className="cursor-pointer select-none m-auto">
|
||||
<IoBackspace className="w-6 h-6" />
|
||||
</div>
|
||||
</Transition>
|
||||
</Keypad>
|
||||
</div>
|
||||
<KeypadErrorModal closeModal={() => setIsKeypadErrorModalOpen(false)} isOpen={isKeypadErrorModalOpen} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -5,14 +5,12 @@ import type { TwilioError } from "@twilio/voice-sdk";
|
||||
import { atom, useAtom } from "jotai";
|
||||
import { IoCall } from "react-icons/io5";
|
||||
|
||||
import useRequireOnboarding from "../../../core/hooks/use-require-onboarding";
|
||||
import useMakeCall from "../../hooks/use-make-call";
|
||||
import useDevice from "../../hooks/use-device";
|
||||
|
||||
import Keypad from "../../components/keypad";
|
||||
|
||||
const OutgoingCall: BlitzPage = () => {
|
||||
useRequireOnboarding();
|
||||
const [phoneNumber, setPhoneNumber] = useAtom(phoneNumberAtom);
|
||||
const router = useRouter();
|
||||
const recipient = decodeURIComponent(router.params.recipient);
|
||||
|
Reference in New Issue
Block a user