Skip to content

Commit

Permalink
feat: add simple flows to apps/react
Browse files Browse the repository at this point in the history
  • Loading branch information
bangarang committed Apr 11, 2024
1 parent 5aba95c commit d788180
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/react/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export default function RootLayout({
>
<a style={menuLinkStyles} href="/">Create a New Space</a>
<a style={menuLinkStyles} href="/re-used-space">Re-use a Space</a>
<a style={menuLinkStyles} href="/sheet">Sheet</a>
<a style={menuLinkStyles} href="/workbook">Workbook</a>
</div>
{children}
</body>
Expand Down
3 changes: 1 addition & 2 deletions apps/react/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export default function Home() {
<FlatfileProvider
publishableKey={PUBLISHABLE_KEY}
config={{
mountElement: 'example-mount-class',
preload: true
preload: true,
}}
>
<App />
Expand Down
44 changes: 44 additions & 0 deletions apps/react/app/sheet/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use client'
import { sheet } from '@/utils/sheet'
import { useFlatfile, useEvent, Sheet, Workbook, Space } from '@flatfile/react'
import React from 'react'
import styles from '../page.module.css'
const App = () => {
const { open, openPortal, closePortal } = useFlatfile()

useEvent('**', async (event) => {
console.group('Event ->', event.topic)
console.log({ event })
console.groupEnd()
})

return (
<div className={styles.main}>
<div className={styles.description}>
<button
onClick={() => {
open ? closePortal() : openPortal()
}}
>
{open ? 'CLOSE' : 'OPEN'} PORTAL
</button>
</div>

<Sheet
config={sheet}
onRecordHook={(record) => {
const email = record.get('email')
if (!email) {
record.addError('email', 'Gotta add an Email here!')
}
return record
}}
onSubmit={(sheet) => {
console.log('onSubmit from Sheet Action', { sheet })
}}
/>
</div>
)
}

export default App
20 changes: 20 additions & 0 deletions apps/react/app/sheet/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client'
import React from 'react'

import App from './App'
import { FlatfileProvider } from '@flatfile/react'

export default function Home() {
const PUBLISHABLE_KEY = process.env.NEXT_PUBLIC_FLATFILE_PUBLISHABLE_KEY
if (!PUBLISHABLE_KEY) return <>No Publishable Key Available</>
return (
<FlatfileProvider
publishableKey={PUBLISHABLE_KEY}
config={{
preload: true,
}}
>
<App />
</FlatfileProvider>
)
}
53 changes: 53 additions & 0 deletions apps/react/app/workbook/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use client'
import { workbook } from '@/utils/workbook'
import { useFlatfile, useEvent, Sheet, Workbook, Space } from '@flatfile/react'
import React from 'react'
import styles from '../page.module.css'
const App = () => {
const { open, openPortal, closePortal } = useFlatfile()

useEvent('**', async (event) => {
console.group('Event ->', event.topic)
console.log({ event })
console.groupEnd()
})

return (
<div className={styles.main}>
<div className={styles.description}>
<button
onClick={() => {
open ? closePortal() : openPortal()
}}
>
{open ? 'CLOSE' : 'OPEN'} PORTAL
</button>
</div>

<Workbook
config={workbook}
onSubmit={async (sheet) => {
console.log('on Workbook Submit ', { sheet })
}}
onRecordHooks={[
[
'contacts',
(record) => {
record.set('email', 'SHEET 1 RECORDHOOKS')
return record
},
],
[
'contacts2',
(record) => {
record.set('email', 'SHEET 2 RECORDHOOKS')
return record
},
],
]}
/>
</div>
)
}

export default App
20 changes: 20 additions & 0 deletions apps/react/app/workbook/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client'
import React from 'react'

import App from './App'
import { FlatfileProvider } from '@flatfile/react'

export default function Home() {
const PUBLISHABLE_KEY = process.env.NEXT_PUBLIC_FLATFILE_PUBLISHABLE_KEY
if (!PUBLISHABLE_KEY) return <>No Publishable Key Available</>
return (
<FlatfileProvider
publishableKey={PUBLISHABLE_KEY}
config={{
preload: true,
}}
>
<App />
</FlatfileProvider>
)
}

0 comments on commit d788180

Please sign in to comment.