Skip to content

Commit

Permalink
Merge pull request #9 from FlatFilers/structure-update-for-docs
Browse files Browse the repository at this point in the history
Update structure to be closer to next.js recommendation
  • Loading branch information
bangarang authored Apr 26, 2024
2 parents 82d0ebb + ddf3d8b commit 8ebe89f
Show file tree
Hide file tree
Showing 21 changed files with 17,534 additions and 3,628 deletions.
73 changes: 73 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"next/core-web-vitals"
],
"plugins": [
"@typescript-eslint",
"prettier"
],
"root": true,
"env": {
"browser": true,
"node": true,
"es6": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"requireConfigFile": false,
"sourceType": "module",
"ecmaVersion": 2022,
"ecmaFeatures": {
"jsx": true,
"impliedStrict": true
}
},
"globals":{
"JSX": "readonly"
},
"rules": {
"react/no-unescaped-entities": "off",
"prettier/prettier": [
"error",
{
"endOfLine": "lf",
"singleQuote": true,
"block-closing-brace-newline-after": "always-multi-line",
"block-closing-brace-empty-line-before": "never",
"block-closing-brace-space-before": "always",
"block-opening-brace-space-after": "always",
"block-opening-brace-space-before": "always",
"block-closing-brace-newline-before": "always-multi-line",
"block-opening-brace-newline-after": "always-multi-line",
"tabs": false,
"indent_size": 2,
"trailingComma": "none",
"comma-dangle": ["error", {
"arrays": "never",
"objects": "never",
"imports": "never",
"exports": "never",
"functions": "never"
}]
}
],
"no-console": "warn",
"no-undef": "error",
"no-unused-vars": "warn",
"semi": 2,
"no-extra-semi": 2,
"quotes": [2, "single", "avoid-escape"]

// "indent": ["error", 2],

},
"overrides": [{
"files": ["*.cjs", "*.js"],
"rules":{
"@typescript-eslint/no-var-requires": "off"
}
}]
}
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18
v18
17 changes: 17 additions & 0 deletions app/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import Menu from './Menu';
import './global.css';

export const metadata = {
title: 'Embedded Flatfile in a Next.js App',
description: 'Generated by Flatfile'
};

export default function Layout({ children }: { children: React.ReactNode }) {
return (
<>
<Menu />
<main>{children}</main>
</>
);
}
File renamed without changes.
14 changes: 6 additions & 8 deletions app/globals/Menu.tsx → app/Menu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"use client";
import styles from "./page.module.css";
import Link from "next/link";
import "./global.css";
import { usePathname } from "next/navigation";
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import styles from './Menu.module.css';

const routes = [
{ path: "/new-space", label: "New Space" },
{ path: "/reused-space", label: "Reused Space" },
{ path: '/new-space', label: 'New Space' },
{ path: '/reuse-space', label: 'Reuse Space' }
];

export default function Menu() {
Expand All @@ -24,7 +22,7 @@ export default function Menu() {
key={path}
href={path}
className={`tab tab-bordered ${
currentRoute === path ? "tab-active" : ""
currentRoute === path ? 'tab-active' : ''
}`}
>
{label}
Expand Down
11 changes: 5 additions & 6 deletions app/new-space/NewSpaceApp.tsx → app/NewSpace/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import React, { Dispatch, SetStateAction, useState } from "react";
import { ISpace, useSpace } from "@flatfile/react";
import Link from "next/link";
import React, { useState } from "react";

const Space = ({
callback,
Expand All @@ -10,20 +10,19 @@ const Space = ({
callback: () => void;
config: ISpace;
}) => {
const space = useSpace({
return useSpace({
...config,
closeSpace: {
operation: "contacts:submit",
operation: "submitActionFg",
onClose: () => callback(),
},
});
return space;
};

export default function App({ config }: { config: ISpace }) {
export default function NewSpace({ config }: { config: ISpace }) {
const [showSpace, setShowSpace] = useState(false);
const [success, setSuccess] = useState(false);
const credentials = !!config.publishableKey && !!config.environmentId;
const credentials = !!config.publishableKey;
return (
<div>
{credentials ? (
Expand Down
20 changes: 9 additions & 11 deletions app/reused-space/ReusedSpaceApp.tsx → app/ReuseSpace/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import React, { Dispatch, SetStateAction, useState } from "react";
import { ISpace, useSpace } from "@flatfile/react";
import { useEffect } from "react";
import React, { Dispatch, SetStateAction, useEffect, useState } from "react";
import { listener } from "../listeners/listeners";

const Space = ({
setShowSpace,
Expand All @@ -16,22 +16,22 @@ const Space = ({
}) => {
const spaceProps: ISpace = {
environmentId: config.environmentId,
listener,
space: {
id: config.spaceId,
accessToken: config.accessToken,
},
};
const space = useSpace({
return useSpace({
...spaceProps,
closeSpace: {
operation: "contacts:submit",
operation: "simpleSubmitAction",
onClose: () => setShowSpace(false),
},
});
return space;
};

function App({
export default function ReuseSpace({
spaceId,
environmentId,
}: {
Expand All @@ -55,14 +55,14 @@ function App({
const spaceInfo = {
spaceId,
accessToken: json.space.data.accessToken,
environmentId,
...(environmentId ? { environmentId } : {}),
};

setData(spaceInfo);
setLoading(false);
};

if (!spaceId || !environmentId) {
if (!spaceId) {
setLoading(false);
return;
}
Expand All @@ -81,7 +81,7 @@ function App({
</button>
);
}
if (!spaceId || !environmentId || error) {
if (!spaceId || error) {
return (
<div className="alert alert-error">
<svg
Expand Down Expand Up @@ -155,5 +155,3 @@ function App({
</div>
);
}

export default App;
2 changes: 1 addition & 1 deletion app/globals/global.css → app/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ pre {

/* The description text you see in the error component */
/* .ff_error_text {
}*/
}*/
22 changes: 0 additions & 22 deletions app/layout.tsx

This file was deleted.

33 changes: 32 additions & 1 deletion listeners/basic.ts → app/listeners/listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { recordHook } from "@flatfile/plugin-record-hook";
*/
export const listener = FlatfileListener.create((listener) => {
listener.on("**", (event) => {
console.log(`Received event: ${event.topic}`);
console.log(`Received event: ${event.topic}`, { event });
});

listener.use(
Expand Down Expand Up @@ -50,4 +50,35 @@ export const listener = FlatfileListener.create((listener) => {
}
});
});
listener.filter({ job: "workbook:simpleSubmitAction" }, (configure) => {
configure.on("job:ready", async ({ context: { jobId } }) => {
try {
await api.jobs.ack(jobId, {
info: "Getting started.",
progress: 10,
});

// Make changes after cells in a Sheet have been updated
console.log("Make changes here when an action is clicked");

await api.jobs.complete(jobId, {
outcome: {
acknowledge: true,
message: "This is now complete.",
next: {
type: "wait",
},
},
});
} catch (error: any) {
console.error("Error:", error.stack);

await api.jobs.fail(jobId, {
outcome: {
message: "This job encountered an error.",
},
});
}
});
});
});
39 changes: 0 additions & 39 deletions app/new-space/page.tsx

This file was deleted.

42 changes: 42 additions & 0 deletions app/workbooks/workbooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Flatfile } from '@flatfile/api';

export const workbook: Pick<
Flatfile.CreateWorkbookConfig,
'name' | 'labels' | 'sheets' | 'actions'
> = {
name: 'All Data',
labels: ['pinned'],
sheets: [
{
name: 'Contacts',
slug: 'contacts',
allowAdditionalFields: true,
fields: [
{
key: 'firstName',
type: 'string',
label: 'First Name'
},
{
key: 'lastName',
type: 'string',
label: 'Last Name'
},
{
key: 'email',
type: 'string',
label: 'Email'
}
]
}
],
actions: [
{
operation: 'submitActionFg',
mode: 'foreground',
label: 'Submit foreground',
description: 'Submit data to webhook.site',
primary: true
}
]
};
Loading

0 comments on commit 8ebe89f

Please sign in to comment.