Skip to content

Commit

Permalink
Demo console banner (#78)
Browse files Browse the repository at this point in the history
* Add developer console banner

* Preview all branches with demo keyword

* Close widget after saving call
  • Loading branch information
esme committed Apr 3, 2023
1 parent 681a3cb commit b79ed14
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ concurrency: preview-${{ github.ref }}
on:
workflow_dispatch:
pull_request:
branches: [project-demo-v1]
branches: ['*demo*']

jobs:
deploy-preview:
Expand Down
29 changes: 29 additions & 0 deletions demo-v1/src/components/Alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ReactElement, MouseEventHandler } from "react";
import { LinkButton } from "./Components";

function Alert({
title,
onConfirm,
}: {
title: string | ReactElement;
onConfirm: MouseEventHandler<HTMLButtonElement>;
}) {
return (
<div
style={{
backgroundColor: "white",
border: "2px solid #CBD6E2",
padding: "10px",
display: "flex",
fontSize: "13px",
}}
>
{title}
<LinkButton use="transparent-on-primary" onClick={onConfirm}>
&times;
</LinkButton>
</div>
);
}

export default Alert;
25 changes: 20 additions & 5 deletions demo-v1/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useCti } from "../hooks/useCti";
import { useCallDurationTimer } from "../hooks/useTimer";
import { WHITE } from "../visitor-ui-component-library/theme/ColorConstants";
import { ScreenNames } from "../types/ScreenTypes";
import Alert from "./Alert";

export const screens = [
LoginScreen,
Expand All @@ -40,6 +41,7 @@ function App() {
const [dialNumber, setDialNumber] = useState("+1");
const [notes, setNotes] = useState("");
const { callDurationString, startTimer, stopTimer } = useCallDurationTimer();
const [showAlert, setShowAlert] = useState(true);

const handleNextScreen = () => {
if (screenIndex === screens.length - 1) {
Expand All @@ -66,17 +68,21 @@ function App() {

const handleEndCall = () => {
stopTimer();
cti.callCompleted({
engagementId,
});
handleNavigateToScreen(ScreenNames.CallEnded);
};

const handleSaveCall = () => {
resetInputs();
cti.callCompleted({
engagementId,
});
handleNavigateToScreen(ScreenNames.Keypad);
};

const hideAlert = () => {
setShowAlert(false);
};

const screenComponent = useMemo(() => {
const Component = screens[screenIndex];
if (!Component) {
Expand Down Expand Up @@ -115,12 +121,21 @@ function App() {
<div
style={{
backgroundColor: "#f5f8fa",
color: "#2d3e50",
minWidth: "400px",
color: "#516f90",
width: "400px",
minHeight: "600px",
display: "flex",
flexDirection: "column",
justifyContent: "space-between",
}}
>
{screenComponent}
{showAlert && (
<Alert
title="Open your console to see the incoming and outgoing messages with HubSpot."
onConfirm={hideAlert}
/>
)}
</div>
</ThemeProvider>
);
Expand Down
2 changes: 1 addition & 1 deletion demo-v1/src/components/Components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const LinkButton = styled(VizExButton).attrs((props) => ({
padding: 0;
`;

export const RoundedButton = styled(Button).attrs((props) => ({
export const RoundedButton = styled(VizExButton).attrs((props) => ({
disabled: props.disabled,
}))`
border-radius: 25px;
Expand Down
38 changes: 38 additions & 0 deletions demo-v1/test/spec/components/App-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { screen, waitForElementToBeRemoved } from "@testing-library/react";
import App from "../../../src/components/App";
import { renderWithWrapper } from "../../render";

describe("App", () => {
it("Shows login screen", () => {
renderWithWrapper(<App />);
expect(
screen.getByText("Log into your calling account")
).toBeInTheDocument();
});

it("Shows alert", () => {
renderWithWrapper(<App />);
expect(
screen.getByText(
/Open your console to see the incoming and outgoing messages with HubSpot./i
)
).toBeInTheDocument();
});

it("Hides alert when confirm button is clicked", async () => {
renderWithWrapper(<App />);
const confirmAlertButton = screen.getByRole("button", { name: /×/i });
confirmAlertButton.click();

await waitForElementToBeRemoved(() =>
screen.getByText(
/Open your console to see the incoming and outgoing messages with HubSpot./i
)
);
expect(
screen.queryByText(
/Open your console to see the incoming and outgoing messages with HubSpot./i
)
).not.toBeInTheDocument();
});
});
4 changes: 2 additions & 2 deletions demo-v1/test/spec/components/screens/KeypadScreen-test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { fireEvent, waitFor } from "@testing-library/react";
import { fireEvent } from "@testing-library/react";
import KeypadScreen, {
validateKeypadInput,
} from "../../../../src/components/screens/KeypadScreen";
import { ScreenNames } from "../../../../src/types/ScreenTypes";
import { renderWithWrapper } from "../../../render";

const noop = () => {};
const noop = (..._args: any[]) => {};

const cti = {
userLoggedOut: noop,
Expand Down
2 changes: 1 addition & 1 deletion demo-v1/test/spec/components/screens/LoginScreen-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fireEvent } from "@testing-library/react";
import LoginScreen from "../../../../src/components/screens/LoginScreen";
import { renderWithWrapper } from "../../../render";

const noop = () => {};
const noop = (..._args: any[]) => {};

const cti = {
userLoggedIn: noop,
Expand Down

0 comments on commit b79ed14

Please sign in to comment.