Skip to content

Nextjs app router examples #796

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

Merged
merged 5 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ Steps to reproduce the behavior:
3. Scroll down to '....'
4. See error

**Codesandbox link**
Include a codesandox will help us to investigate the issue quicker.
**StackBlitz link**
Include a StackBLitz will help us to investigate the issue quicker.

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz_small.svg)](https://stackblitz.com/fork/github/devrnt/react-use-intercom/)

**Expected behavior**
A clear and concise description of what you expected to happen.
Expand Down
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
auto-install-peers = true
node-linker=hoisted
# This allows us to use workspace packages if available, otherwise pull from the remote registry
link-workspace-packages = true
5 changes: 5 additions & 0 deletions apps/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Examples

* [gatsby](https://stackblitz.com/github/devrnt/react-use-intercom/tree/main/apps/examples/gatsby)
* [nextjs-page-router](https://stackblitz.com/github/devrnt/react-use-intercom/tree/main/apps/examples/nextjs-page-router)
* [nextjs-app-router](https://stackblitz.com/github/devrnt/react-use-intercom/tree/main/apps/examples/nextjs-app-router)
2 changes: 1 addition & 1 deletion apps/examples/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"gatsby": "^5.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-use-intercom": "workspace:*"
"react-use-intercom": "*"
}
}
5 changes: 0 additions & 5 deletions apps/examples/gatsby/sandbox.config.json

This file was deleted.

3 changes: 3 additions & 0 deletions apps/examples/nextjs-app-router/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# react-use-intercom in NextJS (App Router)

Replace `INTERCOM_APP_ID` with your Intercom app id.
17 changes: 17 additions & 0 deletions apps/examples/nextjs-app-router/app/intercom.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use client';

import { IntercomProvider } from 'react-use-intercom';

const INTERCOM_APP_ID = 'jcabc7e3';

export function OurIntercomProvider({ children }) {
return (
<html lang="en">
<body>
<IntercomProvider appId={INTERCOM_APP_ID}>
{children}
</IntercomProvider>
</body>
</html>
);
}
13 changes: 13 additions & 0 deletions apps/examples/nextjs-app-router/app/layout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { OurIntercomProvider } from './intercom';

export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<OurIntercomProvider>
{children}
</OurIntercomProvider>
</body>
</html>
);
}
13 changes: 13 additions & 0 deletions apps/examples/nextjs-app-router/app/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use client';

import { useIntercom } from "react-use-intercom";

export default function Home() {
const { boot } = useIntercom();

return (
<main>
<button onClick={() => boot()}>Boot</button>
</main>
);
}
16 changes: 16 additions & 0 deletions apps/examples/nextjs-app-router/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "nextjs-app-router-example",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev --port 3001",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "^14.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-use-intercom": "*"
}
}
34 changes: 34 additions & 0 deletions apps/examples/nextjs-page-router/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# react-use-intercom in NextJS
# react-use-intercom in NextJS (Page Router)

Replace `INTERCOM_APP_ID` with your Intercom app id.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"name": "nextjs-example",
"name": "nextjs-page-router-example",
"scripts": {
"dev": "next dev",
"build": "next build",
Expand All @@ -10,6 +10,6 @@
"next": "13.4.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-use-intercom": "workspace:*"
"react-use-intercom": "*"
}
}
6 changes: 0 additions & 6 deletions apps/examples/nextjs/sandbox.config.json

This file was deleted.

1 change: 0 additions & 1 deletion apps/playground/cypress/e2e/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ describe('update', () => {
app_id: 'jcabc7e3',
name: 'ponas',
});
cy.get('.intercom-lightweight-app-launcher-icon-open').should('not.exist');
});
});
7 changes: 2 additions & 5 deletions apps/playground/cypress/e2e/visitorId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ describe('getVisitorId', () => {
cy.get('[data-cy=boot]').click();
cy.wait('@intercomPing');

// FIXME: something goes wrong here in the pipeline
cy.get('button[data-cy="visitorId"]').click({ timeout: 10000 });
cy.get('button[data-cy="visitorId"]').click();

cy.wait(10000);

cy.get('p[data-cy="visitorIdValue"]', { timeout: 10000 }).should('exist');
cy.get('p[data-cy="visitorIdValue"]').should('exist');
});
});
Loading
Loading