-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: Update To use New React Components #11
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,99 @@ | ||
"use client"; | ||
import { ISpace, useSpace } from "@flatfile/react"; | ||
import api, { Flatfile } from "@flatfile/api"; | ||
import { | ||
Space, | ||
Workbook, | ||
useEvent, | ||
useFlatfile, | ||
usePlugin, | ||
} from "@flatfile/react"; | ||
import Link from "next/link"; | ||
import React, { useState } from "react"; | ||
import { workbook } from "../workbooks/workbooks"; | ||
import { recordHook } from "@flatfile/plugin-record-hook"; | ||
|
||
const Space = ({ | ||
callback, | ||
config, | ||
}: { | ||
callback: () => void; | ||
config: ISpace; | ||
}) => { | ||
return useSpace({ | ||
...config, | ||
closeSpace: { | ||
export default function NewSpace({ config }: { config: Flatfile.SpaceConfig }) { | ||
const [success, setSuccess] = useState(false); | ||
const { openPortal, open, closePortal } = useFlatfile(); | ||
|
||
// Can be used for debugging | ||
// useEvent("**", (event) => { | ||
// console.log("EVENT -> ", { event }); | ||
// }); | ||
|
||
usePlugin( | ||
recordHook("contacts", (record) => { | ||
const firstName = record.get("firstName"); | ||
console.log({ firstName }); | ||
record.set("lastName", "Rock"); | ||
return record; | ||
}) | ||
); | ||
|
||
useEvent( | ||
"job:ready", | ||
{ job: "workbook:submitActionFg" }, | ||
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.", | ||
}, | ||
}); | ||
} | ||
} | ||
); | ||
|
||
useEvent( | ||
"job:outcome-acknowledged", | ||
{ | ||
operation: "submitActionFg", | ||
onClose: () => callback(), | ||
status: "complete", | ||
}, | ||
}); | ||
}; | ||
async (event) => { | ||
// any logic related to the event needed for closing the event | ||
console.log("Window Closed!"); | ||
// close the portal iFrame window | ||
closePortal(); | ||
setSuccess(true); | ||
} | ||
); | ||
|
||
export default function NewSpace({ config }: { config: ISpace }) { | ||
const [showSpace, setShowSpace] = useState(false); | ||
const [success, setSuccess] = useState(false); | ||
const credentials = !!config.publishableKey; | ||
return ( | ||
<div> | ||
{credentials ? ( | ||
<> | ||
<div> | ||
<button | ||
className="btn btn-primary" | ||
onClick={() => { | ||
setShowSpace(!showSpace); | ||
}} | ||
> | ||
{showSpace === true ? "Close" : "Open and create new"} space | ||
</button> | ||
</div> | ||
{showSpace && ( | ||
<div id="flatfile_iFrameContainer"> | ||
<Space | ||
callback={() => { | ||
setShowSpace(false); | ||
setSuccess(true); | ||
}} | ||
config={config} | ||
/> | ||
</div> | ||
)} | ||
</> | ||
) : ( | ||
<div className="alert alert-error"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
className="stroke-current shrink-0 h-6 w-6" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" | ||
/> | ||
</svg> | ||
<span> | ||
Error! Please add your <pre>publishableKey</pre> and{" "} | ||
<pre>environmentId</pre> | ||
</span> | ||
<> | ||
<div> | ||
<button className="btn btn-primary" onClick={openPortal}> | ||
{open === true ? "Close" : "Open and create new"} space | ||
</button> | ||
</div> | ||
)} | ||
<div id="flatfile_iFrameContainer"> | ||
<Space config={config}> | ||
<Workbook config={workbook} /> | ||
</Space> | ||
</div> | ||
</> | ||
|
||
Comment on lines
+2
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The overall structure of the component is clear and logical. Good use of hooks and API interactions. Ensure that all functionalities are covered by unit tests. Would you like me to help with writing unit tests for this component? |
||
{success && ( | ||
<div className="alert alert-success mt-6"> | ||
<svg | ||
|
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.
The API interaction and error handling are robust. However, consider adding more detailed error messages and handling specific error types to improve the user experience.