Skip to content

Commit

Permalink
refactor(sdk): use map for chat room attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Oct 24, 2023
1 parent bd8cf39 commit fbd1844
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/pages/Home/EmbedCodeDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,29 @@ export const EmbedCodeDialog = ({

const needsRootUrlAttribute = window.location.origin !== homepageUrl.origin

const chatRoomAttributes: {
room: string
['root-url']?: string
width: string
height: string
} = {
room: roomName,
width: '800',
height: '800',
}

if (needsRootUrlAttribute) {
chatRoomAttributes['root-url'] = `${window.location.origin}/`
}

const attributesString = Object.entries(chatRoomAttributes)
.map(([key, value]) => `${key}=${value}`)
.join(' ')

// NOTE: The script src is inaccurate in the local development environment.
const sdkEmbedCode = `<script src="${window.location.origin}/sdk.js"></script>
<chat-room room="${roomName}" ${
needsRootUrlAttribute ? `root-url="${window.location.origin}/" ` : ''
}width="800" height="800" />`
<chat-room ${attributesString} />`

return (
<Dialog open={showEmbedCode} onClose={handleEmbedCodeWindowClose}>
Expand Down

0 comments on commit fbd1844

Please sign in to comment.