Skip to content

Commit

Permalink
Rename MSTeams to MsTeams
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmikolay committed Jan 8, 2025
1 parent 777a6d8 commit 8db9f4a
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .changeset/khaki-ways-protect.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"@knocklabs/react": minor
---

feat: add MSTeamsAuthButton
feat: add MsTeamsAuthButton
4 changes: 2 additions & 2 deletions packages/client/src/clients/ms-teams/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AuthCheckInput, RevokeAccessTokenInput } from "../../interfaces";
import Knock from "../../knock";
import { TENANT_OBJECT_COLLECTION } from "../objects/constants";

class MSTeamsClient {
class MsTeamsClient {
private instance: Knock;

constructor(instance: Knock) {
Expand Down Expand Up @@ -57,4 +57,4 @@ class MSTeamsClient {
}
}

export default MSTeamsClient;
export default MsTeamsClient;
4 changes: 2 additions & 2 deletions packages/client/src/knock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { jwtDecode } from "jwt-decode";
import ApiClient from "./api";
import FeedClient from "./clients/feed";
import MessageClient from "./clients/messages";
import MSTeamsClient from "./clients/ms-teams";
import MsTeamsClient from "./clients/ms-teams";
import ObjectClient from "./clients/objects";
import Preferences from "./clients/preferences";
import SlackClient from "./clients/slack";
Expand All @@ -28,7 +28,7 @@ class Knock {
readonly objects = new ObjectClient(this);
readonly preferences = new Preferences(this);
readonly slack = new SlackClient(this);
readonly msTeams = new MSTeamsClient(this);
readonly msTeams = new MsTeamsClient(this);
readonly user = new UserClient(this);
readonly messages = new MessageClient(this);

Expand Down
8 changes: 4 additions & 4 deletions packages/react-core/src/modules/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ export function slackProviderKey({
}

/*
Used to build a consistent key for the KnockMSTeamsProvider so that React knows when
Used to build a consistent key for the KnockMsTeamsProvider so that React knows when
to trigger a re-render of the context when a key property changes.
*/
export function msTeamsProviderKey({
knockMSTeamsChannelId,
knockMsTeamsChannelId,
tenantId,
connectionStatus,
errorLabel,
}: {
knockMSTeamsChannelId: string;
knockMsTeamsChannelId: string;
tenantId: string;
connectionStatus: string;
errorLabel: string | null;
}) {
return [knockMSTeamsChannelId, tenantId, connectionStatus, errorLabel]
return [knockMsTeamsChannelId, tenantId, connectionStatus, errorLabel]
.filter((f) => f !== null && f !== undefined)
.join("-");
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { PropsWithChildren } from "react";

import { useKnockClient } from "../../core";
import { msTeamsProviderKey } from "../../core/utils";
import { useMSTeamsConnectionStatus } from "../hooks";
import { ConnectionStatus } from "../hooks/useMSTeamsConnectionStatus";
import { useMsTeamsConnectionStatus } from "../hooks";
import { ConnectionStatus } from "../hooks/useMsTeamsConnectionStatus";

export interface KnockMSTeamsProviderState {
knockMSTeamsChannelId: string;
export interface KnockMsTeamsProviderState {
knockMsTeamsChannelId: string;
tenantId: string;
connectionStatus: ConnectionStatus;
setConnectionStatus: (connectionStatus: ConnectionStatus) => void;
Expand All @@ -17,17 +17,17 @@ export interface KnockMSTeamsProviderState {
setActionLabel: (label: string | null) => void;
}

const MSTeamsProviderStateContext =
React.createContext<KnockMSTeamsProviderState | null>(null);
const MsTeamsProviderStateContext =
React.createContext<KnockMsTeamsProviderState | null>(null);

export interface KnockMSTeamsProviderProps {
knockMSTeamsChannelId: string;
export interface KnockMsTeamsProviderProps {
knockMsTeamsChannelId: string;
tenantId: string;
}

export const KnockMSTeamsProvider: React.FC<
PropsWithChildren<KnockMSTeamsProviderProps>
> = ({ knockMSTeamsChannelId, tenantId, children }) => {
export const KnockMsTeamsProvider: React.FC<
PropsWithChildren<KnockMsTeamsProviderProps>
> = ({ knockMsTeamsChannelId, tenantId, children }) => {
const knock = useKnockClient();

const {
Expand All @@ -37,12 +37,12 @@ export const KnockMSTeamsProvider: React.FC<
setErrorLabel,
actionLabel,
setActionLabel,
} = useMSTeamsConnectionStatus(knock, knockMSTeamsChannelId, tenantId);
} = useMsTeamsConnectionStatus(knock, knockMsTeamsChannelId, tenantId);

return (
<MSTeamsProviderStateContext.Provider
<MsTeamsProviderStateContext.Provider
key={msTeamsProviderKey({
knockMSTeamsChannelId,
knockMsTeamsChannelId,
tenantId,
connectionStatus,
errorLabel,
Expand All @@ -54,20 +54,20 @@ export const KnockMSTeamsProvider: React.FC<
setErrorLabel,
actionLabel,
setActionLabel,
knockMSTeamsChannelId,
knockMsTeamsChannelId,
tenantId,
}}
>
{children}
</MSTeamsProviderStateContext.Provider>
</MsTeamsProviderStateContext.Provider>
);
};

export const useKnockMSTeamsClient = (): KnockMSTeamsProviderState => {
const context = React.useContext(MSTeamsProviderStateContext);
export const useKnockMsTeamsClient = (): KnockMsTeamsProviderState => {
const context = React.useContext(MsTeamsProviderStateContext);
if (!context) {
throw new Error(
"useKnockMSTeamsClient must be used within a KnockMSTeamsProvider",
"useKnockMsTeamsClient must be used within a KnockMsTeamsProvider",
);
}
return context;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core/src/modules/ms-teams/context/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./KnockMSTeamsProvider";
export * from "./KnockMsTeamsProvider";
4 changes: 2 additions & 2 deletions packages/react-core/src/modules/ms-teams/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as useMSTeamsConnectionStatus } from "./useMSTeamsConnectionStatus";
export { default as useMSTeamsAuth } from "./useMSTeamsAuth";
export { default as useMsTeamsConnectionStatus } from "./useMsTeamsConnectionStatus";
export { default as useMsTeamsAuth } from "./useMsTeamsAuth";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useKnockMSTeamsClient } from "..";
import { useKnockMsTeamsClient } from "..";
import { TENANT_OBJECT_COLLECTION } from "@knocklabs/client";
import { useCallback, useMemo } from "react";

Expand All @@ -9,37 +9,37 @@ const MS_TEAMS_ADMINCONSENT_URL =

const AUTH_REDIRECT_PATH = "/providers/ms-teams/authenticate";

interface UseMSTeamsAuthOutput {
buildMSTeamsAuthUrl: () => string;
disconnectFromMSTeams: () => void;
interface UseMsTeamsAuthOutput {
buildMsTeamsAuthUrl: () => string;
disconnectFromMsTeams: () => void;
}

function useMSTeamsAuth(
function useMsTeamsAuth(
msTeamsBotId: string,
redirectUrl?: string,
): UseMSTeamsAuthOutput {
): UseMsTeamsAuthOutput {
const knock = useKnockClient();
const {
setConnectionStatus,
knockMSTeamsChannelId,
knockMsTeamsChannelId,
tenantId,
setActionLabel,
} = useKnockMSTeamsClient();
} = useKnockMsTeamsClient();

const authRedirectUri = useMemo(
() => knock.host + AUTH_REDIRECT_PATH,
[knock.host],
);

const buildMSTeamsAuthUrl = useCallback(() => {
const buildMsTeamsAuthUrl = useCallback(() => {
const rawParams = {
state: JSON.stringify({
redirect_url: redirectUrl,
ms_teams_tenant_object: {
object_id: tenantId,
collection: TENANT_OBJECT_COLLECTION,
},
channel_id: knockMSTeamsChannelId,
channel_id: knockMsTeamsChannelId,
public_key: knock.apiKey,
user_token: knock.userToken,
}),
Expand All @@ -50,20 +50,20 @@ function useMSTeamsAuth(
}, [
redirectUrl,
tenantId,
knockMSTeamsChannelId,
knockMsTeamsChannelId,
knock.apiKey,
knock.userToken,
msTeamsBotId,
authRedirectUri,
]);

const disconnectFromMSTeams = useCallback(async () => {
const disconnectFromMsTeams = useCallback(async () => {
setActionLabel(null);
setConnectionStatus("disconnecting");
try {
const revokeResult = await knock.msTeams.revokeAccessToken({
tenant: tenantId,
knockChannelId: knockMSTeamsChannelId,
knockChannelId: knockMsTeamsChannelId,
});

setConnectionStatus(revokeResult === "ok" ? "disconnected" : "error");
Expand All @@ -74,11 +74,11 @@ function useMSTeamsAuth(
setConnectionStatus,
knock.msTeams,
tenantId,
knockMSTeamsChannelId,
knockMsTeamsChannelId,
setActionLabel,
]);

return { buildMSTeamsAuthUrl, disconnectFromMSTeams };
return { buildMsTeamsAuthUrl, disconnectFromMsTeams };
}

export default useMSTeamsAuth;
export default useMsTeamsAuth;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type ConnectionStatus =
| "error"
| "disconnecting";

type UseMSTeamsConnectionStatusOutput = {
type UseMsTeamsConnectionStatusOutput = {
connectionStatus: ConnectionStatus;
setConnectionStatus: (status: ConnectionStatus) => void;
errorLabel: string | null;
Expand All @@ -19,11 +19,11 @@ type UseMSTeamsConnectionStatusOutput = {
setActionLabel: (actionLabel: string | null) => void;
};

function useMSTeamsConnectionStatus(
function useMsTeamsConnectionStatus(
knock: Knock,
knockMSTeamsChannelId: string,
knockMsTeamsChannelId: string,
tenantId: string,
): UseMSTeamsConnectionStatusOutput {
): UseMsTeamsConnectionStatusOutput {
const { t } = useTranslations();

const [connectionStatus, setConnectionStatus] =
Expand All @@ -38,7 +38,7 @@ function useMSTeamsConnectionStatus(
try {
const authRes = await knock.msTeams.authCheck({
tenant: tenantId,
knockChannelId: knockMSTeamsChannelId,
knockChannelId: knockMsTeamsChannelId,
});

if (authRes.connection?.ok === true) {
Expand Down Expand Up @@ -67,7 +67,7 @@ function useMSTeamsConnectionStatus(
};

checkAuthStatus();
}, [connectionStatus, tenantId, knockMSTeamsChannelId, knock.msTeams, t]);
}, [connectionStatus, tenantId, knockMsTeamsChannelId, knock.msTeams, t]);

return {
connectionStatus,
Expand All @@ -79,4 +79,4 @@ function useMSTeamsConnectionStatus(
};
}

export default useMSTeamsConnectionStatus;
export default useMsTeamsConnectionStatus;

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import {
useKnockClient,
useKnockMSTeamsClient,
useMSTeamsAuth,
useKnockMsTeamsClient,
useMsTeamsAuth,
useTranslations,
} from "@knocklabs/react-core";
import { FunctionComponent, useEffect } from "react";

import { openPopupWindow } from "../../../core/utils";
import "../../theme.css";
import { MSTeamsIcon } from "../MSTeamsIcon";
import { MsTeamsIcon } from "../MsTeamsIcon";

import "./styles.css";

export interface MSTeamsAuthButtonProps {
export interface MsTeamsAuthButtonProps {
msTeamsBotId: string;
redirectUrl?: string;
onAuthenticationComplete?: (authenticationResp: string) => void;
}

export const MSTeamsAuthButton: FunctionComponent<MSTeamsAuthButtonProps> = ({
export const MsTeamsAuthButton: FunctionComponent<MsTeamsAuthButtonProps> = ({
msTeamsBotId,
redirectUrl,
onAuthenticationComplete,
Expand All @@ -32,9 +32,9 @@ export const MSTeamsAuthButton: FunctionComponent<MSTeamsAuthButtonProps> = ({
setActionLabel,
actionLabel,
errorLabel,
} = useKnockMSTeamsClient();
} = useKnockMsTeamsClient();

const { buildMSTeamsAuthUrl, disconnectFromMSTeams } = useMSTeamsAuth(
const { buildMsTeamsAuthUrl, disconnectFromMsTeams } = useMsTeamsAuth(
msTeamsBotId,
redirectUrl,
);
Expand Down Expand Up @@ -78,7 +78,7 @@ export const MSTeamsAuthButton: FunctionComponent<MSTeamsAuthButtonProps> = ({
) {
return (
<div className="rtk-connect__button rtk-connect__button--loading">
<MSTeamsIcon height="16px" width="16px" />
<MsTeamsIcon height="16px" width="16px" />
<span>
{connectionStatus === "connecting"
? t("msTeamsConnecting")
Expand All @@ -92,12 +92,12 @@ export const MSTeamsAuthButton: FunctionComponent<MSTeamsAuthButtonProps> = ({
if (connectionStatus === "error") {
return (
<button
onClick={() => openPopupWindow(buildMSTeamsAuthUrl())}
onClick={() => openPopupWindow(buildMsTeamsAuthUrl())}
className="rtk-connect__button rtk-connect__button--error"
onMouseEnter={() => setActionLabel(reconnectLabel)}
onMouseLeave={() => setActionLabel(null)}
>
<MSTeamsIcon height="16px" width="16px" />
<MsTeamsIcon height="16px" width="16px" />
<span className="rtk-connect__button__text--error">
{actionLabel || errorLabel || t("msTeamsError")}
</span>
Expand All @@ -109,10 +109,10 @@ export const MSTeamsAuthButton: FunctionComponent<MSTeamsAuthButtonProps> = ({
if (connectionStatus === "disconnected") {
return (
<button
onClick={() => openPopupWindow(buildMSTeamsAuthUrl())}
onClick={() => openPopupWindow(buildMsTeamsAuthUrl())}
className="rtk-connect__button rtk-connect__button--disconnected"
>
<MSTeamsIcon height="16px" width="16px" />
<MsTeamsIcon height="16px" width="16px" />
<span>{t("msTeamsConnect")}</span>
</button>
);
Expand All @@ -121,12 +121,12 @@ export const MSTeamsAuthButton: FunctionComponent<MSTeamsAuthButtonProps> = ({
// Connected state
return (
<button
onClick={disconnectFromMSTeams}
onClick={disconnectFromMsTeams}
className="rtk-connect__button rtk-connect__button--connected"
onMouseEnter={() => setActionLabel(disconnectLabel)}
onMouseLeave={() => setActionLabel(null)}
>
<MSTeamsIcon height="16px" width="16px" />
<MsTeamsIcon height="16px" width="16px" />
<span className="rtk-connect__button__text--connected">
{actionLabel || t("msTeamsConnected")}
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./MsTeamsAuthButton";
Loading

0 comments on commit 8db9f4a

Please sign in to comment.