Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the callStatus to canceled when we end an incoming call #199

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions demos/demo-react-ts/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import CallEndedScreen from "./screens/CallEndedScreen";
import IncomingScreen from "./screens/IncomingScreen";
import { useCti } from "../hooks/useCti";
import { useCallDurationTimer } from "../hooks/useTimer";
import { ScreenNames, Availability, Direction } from "../types/ScreenTypes";
import {
ScreenNames,
Availability,
Direction,
CallStatus,
} from "../types/ScreenTypes";
import Alert from "./Alert";
import { CALYPSO, GYPSUM, KOALA, OLAF, SLINKY } from "../utils/colors";
import { FROM_NUMBER_ONE } from "../utils/phoneNumberUtils";
Expand Down Expand Up @@ -69,6 +74,7 @@ function App() {
const [fromNumber, setFromNumber] = useState(FROM_NUMBER_ONE);
const [incomingNumber, setIncomingNumber] = useState("+1");
const [availability, setAvailability] = useState<Availability>("UNAVAILABLE");
const [callStatus, setCallStatus] = useState<CallStatus | null>(null);

const {
callDuration,
Expand All @@ -85,8 +91,9 @@ function App() {
setIncomingNumber(incomingNumber);
};

const { cti, phoneNumber, engagementId, callStatus, incomingContactName } =
useCti(initializeCallingStateForExistingCall);
const { cti, phoneNumber, engagementId, incomingContactName } = useCti(
initializeCallingStateForExistingCall
);

const screens = direction === "OUTBOUND" ? OUTBOUND_SCREENS : INBOUND_SCREENS;

Expand Down Expand Up @@ -156,12 +163,13 @@ function App() {
setFromNumber={setFromNumber}
incomingNumber={incomingNumber}
setIncomingNumber={setIncomingNumber}
callStatus={callStatus}
availability={availability}
setAvailability={setAvailability}
direction={direction}
setDirection={setDirection}
incomingContactName={incomingContactName}
callStatus={callStatus}
setCallStatus={setCallStatus}
/>
);
}, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function CallEndedScreen({
setNotes,
callDuration,
callDurationString,
callStatus,
}: ScreenProps) {
const handleNotes = (event: ChangeEvent<HTMLTextAreaElement>) => {
setNotes(event.target.value);
Expand All @@ -36,6 +37,7 @@ function CallEndedScreen({
engagementProperties: {
hs_call_body: notes,
hs_call_duration: callDuration.toString(),
hs_call_status: callStatus || "COMPLETED",
},
});
handleSaveCall();
Expand Down
17 changes: 10 additions & 7 deletions demos/demo-react-ts/src/components/screens/IncomingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function IncomingScreen({
handleEndCall,
cti,
startTimer,
callStatus,
incomingContactName,
setCallStatus,
}: ScreenProps) {
const onAnswerCall = () => {
const callStartTime = Date.now();
Expand All @@ -28,10 +28,9 @@ function IncomingScreen({
handleNextScreen();
};

const onEndCall = () => {
cti.callEnded({
callEndStatus: callStatus.INTERNAL_COMPLETED,
});
const onEndIncomingCall = () => {
setCallStatus("CANCELED");
cti.callEnded({ callEndStatus: "CANCELED" });
handleEndCall();
};

Expand Down Expand Up @@ -70,11 +69,15 @@ function IncomingScreen({
<CallButton
use="primary"
onClick={onAnswerCall}
aria-label="start-call"
aria-label="answer-call"
>
{StartCallSvg}
</CallButton>
<EndCallButton use="primary" onClick={onEndCall} aria-label="end-call">
<EndCallButton
use="primary"
onClick={onEndIncomingCall}
aria-label="cancel-call"
>
{EndCallSvg}
</EndCallButton>
</Row>
Expand Down
3 changes: 0 additions & 3 deletions demos/demo-react-ts/src/hooks/useCti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { useMemo, useState } from "react";

// @ts-expect-error module not typed
import CallingExtensions from "../../../../src/CallingExtensions";
// @ts-expect-error module not typed
import { callStatus } from "../../../../src/Constants";

// @TODO Move it to CallingExtensions and export it once migrated to typescript
type ObjectCoordinates = {
Expand Down Expand Up @@ -260,7 +258,6 @@ export const useCti = (
phoneNumber,
engagementId,
cti,
callStatus,
incomingContactName,
};
};
4 changes: 3 additions & 1 deletion demos/demo-react-ts/src/types/ScreenTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export type CallStatus = "NO_ANSWER" | "CANCELED" | "COMPLETED";
export type Availability = "AVAILABLE" | "UNAVAILABLE";
export type Direction = "INBOUND" | "OUTBOUND";

Expand Down Expand Up @@ -29,12 +30,13 @@ export interface ScreenProps {
handleSaveCall: Function;
fromNumber: string;
setFromNumber: Function;
callStatus: any;
availability: Availability;
setAvailability: (availability: Availability) => void;
direction: Direction;
setDirection: (direction: Direction) => void;
incomingContactName: string;
incomingNumber: string;
setIncomingNumber: (number: string) => void;
callStatus: CallStatus | null;
setCallStatus: (callStatus: CallStatus) => void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,27 @@ describe("CallEndedScreen", () => {
engagementProperties: {
hs_call_body: "calling notes",
hs_call_duration: "3000",
hs_call_status: "COMPLETED",
},
});
});

it("Saves canceled call", () => {
const { getByRole } = renderWithContext(
<CallEndedScreen
{...props}
engagementId={1}
notes="calling notes"
callDuration={3000}
callStatus="CANCELED"
/>
);
const button = getByRole("button", { name: /save-call/ });
button.click();
expect(props.handleSaveCall).toHaveBeenCalled();
expect(
(cti.callCompleted as jasmine.Spy).calls.argsFor(0)[0]
.engagementProperties.hs_call_status
).toEqual("CANCELED");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const props: Partial<ScreenProps> = {
callStatus: {
INTERNAL_COMPLETED: "COMPLETED",
},
setCallStatus: noop,
};

describe("IncomingScreen", () => {
Expand Down Expand Up @@ -91,7 +92,7 @@ describe("IncomingScreen", () => {
it("Receives call", () => {
// ARRANGE
const { getByRole } = renderWithContext(<IncomingScreen {...props} />);
const button = getByRole("button", { name: /start-call/ });
const button = getByRole("button", { name: /answer-call/ });

// ACT
button.click();
Expand All @@ -105,15 +106,15 @@ describe("IncomingScreen", () => {
it("Ends call", () => {
// ARRANGE
const { getByRole } = renderWithContext(<IncomingScreen {...props} />);
const button = getByRole("button", { name: /end-call/ });
const button = getByRole("button", { name: /cancel-call/ });

// ACT
button.click();

// ASSERT
expect(props.handleEndCall).toHaveBeenCalled();
expect(cti.callEnded).toHaveBeenCalledWith({
callEndStatus: "COMPLETED",
callEndStatus: "CANCELED",
});
});
});
Loading