import { useCallback, useEffect } from "react"; import type { WithRouterProps } from "next/dist/client/with-router"; import type { BlitzPage, ErrorFallbackProps } from "blitz"; import { ErrorBoundary, Routes, useParam, withRouter } from "blitz"; import type { TwilioError } from "@twilio/voice-sdk"; import { atom, useAtom } from "jotai"; import { IoCall } from "react-icons/io5"; import useMakeCall from "../../hooks/use-make-call"; import useDevice from "../../hooks/use-device"; import Keypad from "../../components/keypad"; const OutgoingCall: BlitzPage = () => { const [phoneNumber, setPhoneNumber] = useAtom(phoneNumberAtom); const recipient = decodeURIComponent(useParam("recipient", "string") ?? ""); const onHangUp = useCallback(() => setPhoneNumber(""), [setPhoneNumber]); const call = useMakeCall({ recipient, onHangUp }); const { isDeviceReady } = useDevice(); const pressDigit = useAtom(pressDigitAtom)[1]; const onDigitPressProps = useCallback( (digit: string) => ({ onPress() { pressDigit(digit); call.sendDigits(digit); }, }), [call, pressDigit], ); useEffect(() => { if (isDeviceReady) { call.makeCall(); } }, [call, isDeviceReady]); return (
) : null}{error.description} ({error.code}){error.explanation}
We have been automatically notified and we're doing our best to make sure this does not happen again!