Skip to content

Commit

Permalink
Move localStorage saving logic to inside of queryFn
Browse files Browse the repository at this point in the history
  • Loading branch information
AhyoungRyu committed Apr 9, 2024
1 parent 0e7b9ba commit 1d8502a
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/hooks/useGroupChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const useManualGroupChannelCreation = () => {
const store = useSendbirdStateContext();
const sb = store.stores.sdkStore.sdk as SendbirdGroupChat;

const { data: channelUrl } = useQuery({
useQuery({
enabled:
sb?.groupChannel != null &&
botId != null &&
Expand Down Expand Up @@ -56,25 +56,21 @@ export const useManualGroupChannelCreation = () => {
data: paramData,
};
const channel = await sb?.groupChannel?.createChannel(params);
return channel.url;
localStorageHelper().setItem(
CHAT_AI_WIDGET_LOCAL_STORAGE_KEY,
JSON.stringify({
channelUrl: channel.url,
expireAt: getDateNDaysLater(30),
userId: customUserId,
// there's no sessionToken in this case since we don't know the value of it
// but instead, it should be handled by configureSession that user provides
sessionToken: undefined,
})
);
} catch (error) {
console.error(error);
throw new Error('Failed to create a new channel');
}
},
});

if (channelUrl != null) {
localStorageHelper().setItem(
CHAT_AI_WIDGET_LOCAL_STORAGE_KEY,
JSON.stringify({
channelUrl,
expireAt: getDateNDaysLater(30),
userId: customUserId,
// there's no sessionToken in this case since we don't know the value of it
// but instead, it should be handled by configureSession that user provides
sessionToken: undefined,
})
);
}
};

0 comments on commit 1d8502a

Please sign in to comment.