Skip to content
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
22 changes: 9 additions & 13 deletions lib/components/Slack/SlackConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function SlackConnect({
selectChannelText = 'Choose a channel or user to receive notifications:'
}: SlackConnectProps = {}) {
const context = useContext(NotificationAPIContext);
const client = context?.getClient();
const [slackToken, setSlackToken] = useState<
User['slackToken'] | undefined
>();
Expand All @@ -53,11 +54,10 @@ export function SlackConnect({
const [isEditing, setIsEditing] = useState(false);

const fetchUserSlackStatus = useCallback(async () => {
if (!context) return;
if (!client) return;

try {
setLoading(true);
const client = context.getClient();

// Get user's current slack configuration using user.get
const user = await client.user.get();
Expand All @@ -75,15 +75,14 @@ export function SlackConnect({
} finally {
setLoading(false);
}
}, [context]);
}, [client]);

const loadChannels = useCallback(async () => {
if (!context || !slackToken) return [];
if (!client || !slackToken) return [];

try {
setLoading(true);
setError(null);
const client = context.getClient();

// Get channels and users from Slack
const response = await client.slack.getChannels();
Expand Down Expand Up @@ -115,7 +114,7 @@ export function SlackConnect({
} finally {
setLoading(false);
}
}, [context, slackToken]);
}, [client, slackToken]);

useEffect(() => {
// Fetch the user's current slackToken and slackChannel from the API
Expand All @@ -129,12 +128,11 @@ export function SlackConnect({
}, [slackToken, slackChannel, isEditing, loadChannels]);

const handleConnectSlack = async () => {
if (!context) return;
if (!client) return;

try {
setLoading(true);
setError(null);
const client = context.getClient();

// Generate Slack OAuth URL
const url = await client.slack.getOAuthUrl();
Expand All @@ -150,12 +148,11 @@ export function SlackConnect({
};

const handleSaveChannel = async () => {
if (!context || !selectedChannel) return;
if (!client || !selectedChannel) return;

try {
setLoading(true);
setError(null);
const client = context.getClient();

// Find the selected channel info to get its name and type
const channelInfo = channels.find((c) => c.id === selectedChannel);
Expand Down Expand Up @@ -184,12 +181,11 @@ export function SlackConnect({
};

const handleDisconnect = async () => {
if (!context) return;
if (!client) return;

try {
setLoading(true);
setError(null);
const client = context.getClient();

// Remove slackToken and slackChannel using identify
await client.identify({
Expand Down Expand Up @@ -243,7 +239,7 @@ export function SlackConnect({
setSelectedChannel('');
};

if (!context) {
if (!client) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@notificationapi/react",
"private": false,
"version": "1.5.0",
"version": "1.5.1",
"type": "module",
"overrides": {
"esbuild": "^0.25.0",
Expand Down