-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨(frontend) add crisp chatbot #273
Open
arnaud-robin
wants to merge
4
commits into
main
Choose a base branch
from
feature/crisp-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+153
−3
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Submodule secrets
updated
from 264369 to 551d72
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
NEXT_PUBLIC_API_ORIGIN= | ||
NEXT_PUBLIC_Y_PROVIDER_URL= | ||
NEXT_PUBLIC_MEDIA_URL= | ||
NEXT_PUBLIC_THEME=dsfr | ||
NEXT_PUBLIC_THEME=dsfr | ||
NEXT_PUBLIC_CRISP_WEBSITE_ID= |
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
56 changes: 56 additions & 0 deletions
56
src/frontend/apps/impress/src/core/auth/__tests__/useAuthStore.test.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,56 @@ | ||
import { waitFor } from '@testing-library/react'; | ||
import { Crisp } from 'crisp-sdk-web'; | ||
import fetchMock from 'fetch-mock'; | ||
|
||
import { useAuthStore } from '../useAuthStore'; | ||
|
||
jest.mock('crisp-sdk-web', () => ({ | ||
...jest.requireActual('crisp-sdk-web'), | ||
Crisp: { | ||
setTokenId: jest.fn(), | ||
user: { | ||
setEmail: jest.fn(), | ||
}, | ||
session: { | ||
reset: jest.fn(), | ||
}, | ||
}, | ||
})); | ||
|
||
describe('useAuthStore', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
fetchMock.restore(); | ||
}); | ||
|
||
it('checks initialize support session when initAuth', async () => { | ||
window.$crisp = true; | ||
fetchMock.mock('end:users/me/', { | ||
id: '123456', | ||
email: 'test@email.com', | ||
}); | ||
|
||
useAuthStore.getState().initAuth(); | ||
|
||
await waitFor(() => { | ||
expect(Crisp.setTokenId).toHaveBeenCalledWith('123456'); | ||
}); | ||
|
||
expect(Crisp.user.setEmail).toHaveBeenCalledWith('test@email.com'); | ||
}); | ||
|
||
it('checks support session is terminated when logout', () => { | ||
window.$crisp = true; | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
...window.location, | ||
replace: jest.fn(), | ||
}, | ||
writable: true, | ||
}); | ||
|
||
useAuthStore.getState().logout(); | ||
|
||
expect(Crisp.session.reset).toHaveBeenCalled(); | ||
}); | ||
}); |
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
30 changes: 30 additions & 0 deletions
30
src/frontend/apps/impress/src/hook/__tests__/useSupport.test.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,30 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { Crisp } from 'crisp-sdk-web'; | ||
|
||
import { useSupport } from '../useSupport'; | ||
|
||
jest.mock('crisp-sdk-web', () => ({ | ||
...jest.requireActual('crisp-sdk-web'), | ||
Crisp: { | ||
configure: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('useSupport', () => { | ||
afterEach(() => jest.clearAllMocks()); | ||
|
||
it('checks that env NEXT_PUBLIC_CRISP_WEBSITE_ID not set give a warning', () => { | ||
process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID = ''; | ||
jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
|
||
renderHook(() => useSupport()); | ||
expect(console.warn).toHaveBeenCalledWith('Crisp Website ID is not set'); | ||
}); | ||
|
||
it('checks Crisp is configured', () => { | ||
process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID = '123456'; | ||
renderHook(() => useSupport()); | ||
|
||
expect(Crisp.configure).toHaveBeenCalledWith('123456'); | ||
}); | ||
}); |
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,43 @@ | ||
import { Crisp } from 'crisp-sdk-web'; | ||
import { useEffect } from 'react'; | ||
|
||
import { User } from '@/core'; | ||
|
||
const isCrispConfigured = (): boolean => { | ||
return typeof window !== 'undefined' && !!window.$crisp; | ||
}; | ||
|
||
export const initializeSupportSession = (user: User) => { | ||
if (!isCrispConfigured()) { | ||
return; | ||
} | ||
Crisp.setTokenId(user.id); | ||
Crisp.user.setEmail(user.email); | ||
}; | ||
|
||
export const terminateSupportSession = () => { | ||
if (!isCrispConfigured()) { | ||
return; | ||
} | ||
Crisp.session.reset(); | ||
}; | ||
|
||
/** | ||
* Configure Crisp chat for real-time support across all pages. | ||
*/ | ||
export const useSupport = () => { | ||
useEffect(() => { | ||
const CRISP_WEBSITE_ID = process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID; | ||
|
||
if (!CRISP_WEBSITE_ID) { | ||
console.warn('Crisp Website ID is not set'); | ||
return; | ||
} | ||
if (isCrispConfigured()) { | ||
return; | ||
} | ||
Crisp.configure(CRISP_WEBSITE_ID); | ||
}, []); | ||
|
||
return null; | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure anymore of this part … let's discuss it before merging, I am reading their doc