Skip to content

Commit

Permalink
fix: create a provisional token and set the calendarUrl when offline
Browse files Browse the repository at this point in the history
  • Loading branch information
psanders committed Nov 28, 2023
1 parent 71fe4c9 commit 17a8a48
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions mods/widget/src/GoodtokUA.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,29 @@ const GoodtokUA = () => {
});

const workspaces = new SDK.Workspaces(client);
const tokens = new SDK.Tokens(client);

const subscription = workspaces.watchWorkspaceStatus(
workspaceId,
(error, workspaceStatus) => {
if (error) {
console.error("failed to watch workspace status", error);
setNotificationType(NotificationType.UNKNOWN_ERROR);
setNotificationOpen(true);
// If an error occurs is better to show the widget as offline
setIsOnline(false);
return;
}
setIsOnline(workspaceStatus.isOpen && workspaceStatus.isEnabled);
}
);

// We create a provisional token just to get the calendar url
// TODO: Consider a better error handling here
tokens
.createAnonymousToken({ ref: "placeholder", workspaceId, metadata: {} })
.then((token) => {
const connectionObj = jwtDecode(token) as ConnectionObject;
setCalendarUrl(connectionObj.calendarUrl);
});

return () => {
subscription.unsubscribe();
};
Expand Down

0 comments on commit 17a8a48

Please sign in to comment.