-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
onLoad
and onLoadFailed
callbacks to config
- Loading branch information
1 parent
a10dcaa
commit 32e3ad4
Showing
8 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// <reference types="cypress" /> | ||
|
||
describe('onLoad/onLoadFailed', () => { | ||
it('should call onLoad when successful', () => { | ||
cy.visit('/useIntercomWithLoadCallbacks'); | ||
|
||
cy.get('[data-cy=call]').should(($p) => | ||
expect($p).to.have.text('onLoad was called!'), | ||
); | ||
}); | ||
|
||
it('should call onLoadFailed when not successful', () => { | ||
cy.visit('/useIntercomWithLoadCallbacks'); | ||
|
||
cy.intercept('https://widget.intercom.io/widget/jcabc7e3', { | ||
forceNetworkError: true, | ||
}); | ||
|
||
cy.get('[data-cy=call]').should(($p) => | ||
expect($p).to.have.text('onLoadFailed was called!'), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
apps/playground/src/modules/useIntercom/useIntercomWithLoadCallbacks.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useState } from 'react'; | ||
import * as React from 'react'; | ||
import { IntercomProvider } from 'react-use-intercom'; | ||
import styled from 'styled-components'; | ||
|
||
const Grid = styled.div` | ||
display: grid; | ||
grid-template-columns: repeat(1, 1fr); | ||
width: 100%; | ||
`; | ||
|
||
const Item = styled.div` | ||
display: grid; | ||
grid-template-rows: min-content; | ||
&::after { | ||
content: ''; | ||
margin: 2rem 0 1.5rem; | ||
border-bottom: 2px solid var(--grey); | ||
width: 100%; | ||
} | ||
`; | ||
|
||
const RawUseIntercomPage = ({ call }: { call: string | undefined }) => { | ||
return ( | ||
<Grid> | ||
<Item> | ||
<p> | ||
The Intercom Messenger script will be loaded and{' '} | ||
<code>onLoad/onLoadFailed</code> be called | ||
</p> | ||
<p data-cy="call">{call ?? 'Waiting…'}</p> | ||
</Item> | ||
</Grid> | ||
); | ||
}; | ||
|
||
const UseIntercomWithLoadCallbacks = () => { | ||
const [call, setCall] = useState<string>(); | ||
|
||
return ( | ||
<IntercomProvider | ||
appId="jcabc7e3" | ||
autoBoot | ||
onLoad={() => setCall('onLoad was called!')} | ||
onLoadFailed={() => setCall('onLoadFailed was called!')} | ||
> | ||
<RawUseIntercomPage call={call} /> | ||
</IntercomProvider> | ||
); | ||
}; | ||
|
||
export default UseIntercomWithLoadCallbacks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters