-
Notifications
You must be signed in to change notification settings - Fork 0
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
Embedded Portal Flow #19
Conversation
WalkthroughThe update transforms the handling and presentation of space-related functionalities within a web application. It shifts from creating spaces to fetching and setting up spaces for users, integrating an embedded Flatfile data import portal for streamlined data management. This adjustment enhances user experience by providing a more direct and efficient workflow for managing space data, emphasizing dynamic content rendering based on workflow types and improving code maintainability and readability through refactoring and better use of environment variables. Changes
Possibly related issues
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
export default async function Page() { | ||
const session = await getServerSession(); | ||
invariant(session?.user, "User must be logged in"); | ||
|
||
const space = await SpaceService.getSpaceForWorkflow({ | ||
userId: session.user.id, | ||
workflowType: WorkflowType.Embed, | ||
}); | ||
|
||
if (space) { | ||
redirect(`/embedded-portal/${space.id}`); | ||
} | ||
|
||
return <SetupSpace workflowType={WorkflowType.Embed} />; |
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.
Validate the logic for fetching space data and redirecting or rendering components based on the existence of a space. Consider adding error handling for the asynchronous operations involved.
const space = await SpaceService.getSpaceForWorkflow({
userId: session.user.id,
workflowType: WorkflowType.Embed,
}).catch(error => {
console.error("Failed to fetch space data:", error);
// Handle error appropriately
});
if (space) {
redirect(`/embedded-portal/${space.id}`);
} else {
return <SetupSpace workflowType={WorkflowType.Embed} />;
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
export default async function Page() { | |
const session = await getServerSession(); | |
invariant(session?.user, "User must be logged in"); | |
const space = await SpaceService.getSpaceForWorkflow({ | |
userId: session.user.id, | |
workflowType: WorkflowType.Embed, | |
}); | |
if (space) { | |
redirect(`/embedded-portal/${space.id}`); | |
} | |
return <SetupSpace workflowType={WorkflowType.Embed} />; | |
export default async function Page() { | |
const session = await getServerSession(); | |
invariant(session?.user, "User must be logged in"); | |
const space = await SpaceService.getSpaceForWorkflow({ | |
userId: session.user.id, | |
workflowType: WorkflowType.Embed, | |
}).catch(error => { | |
console.error("Failed to fetch space data:", error); | |
// Handle error appropriately | |
}); | |
if (space) { | |
redirect(`/embedded-portal/${space.id}`); | |
} else { | |
return <SetupSpace workflowType={WorkflowType.Embed} />; | |
} |
const onOpenSpace = async () => { | ||
setShowSpace(!showSpace); | ||
OpenEmbed(); | ||
}; |
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.
Consider adding error handling for the onOpenSpace
function to gracefully manage any exceptions that might occur during the operation.
const onOpenSpace = async () => {
try {
setShowSpace(!showSpace);
OpenEmbed();
} catch (error) {
console.error("Error opening Flatfile space:", error);
// Handle error appropriately
}
};
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
const onOpenSpace = async () => { | |
setShowSpace(!showSpace); | |
OpenEmbed(); | |
}; | |
const onOpenSpace = async () => { | |
try { | |
setShowSpace(!showSpace); | |
OpenEmbed(); | |
} catch (error) { | |
console.error("Error opening Flatfile space:", error); | |
// Handle error appropriately | |
} | |
}; |
if ( | ||
localStorage.getItem(storageKey) === "true" && | ||
steps[0].status === "current" | ||
) { |
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.
Consider adding a dependency array to the useEffect
hook to prevent unnecessary re-renders and ensure the effect runs only when specific values change.
}, [steps, storageKey]);
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
if ( | |
localStorage.getItem(storageKey) === "true" && | |
steps[0].status === "current" | |
) { | |
if ( | |
localStorage.getItem(storageKey) === "true" && | |
steps[0].status === "current" | |
) { |
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.
Know it's WIP but here's a few comments
const space = await SpaceService.getSpace({ | ||
id: spaceId, | ||
}); | ||
if (!space) { | ||
redirect("/embedded-portal"); | ||
} | ||
const flatfileSpace = await FlatfileService.getSpace({ | ||
flatfileSpaceId: space.flatfileSpaceId, | ||
}); |
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.
Add error handling for asynchronous operations to prevent unhandled promise rejections and improve user experience in case of errors.
+ }).catch(error => {
+ console.error("Failed to fetch space data:", error);
+ redirect("/error");
+ });
+
+ if (!space) {
+ redirect("/embedded-portal");
+ } else {
+ const flatfileSpace = await FlatfileService.getSpace({
+ flatfileSpaceId: space.flatfileSpaceId,
+ }).catch(error => {
+ console.error("Failed to fetch Flatfile space data:", error);
+ redirect("/error");
+ });
+
+ if (!flatfileSpace) {
+ redirect("/error");
+ }
+ }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
const space = await SpaceService.getSpace({ | |
id: spaceId, | |
}); | |
if (!space) { | |
redirect("/embedded-portal"); | |
} | |
const flatfileSpace = await FlatfileService.getSpace({ | |
flatfileSpaceId: space.flatfileSpaceId, | |
}); | |
const space = await SpaceService.getSpace({ | |
id: spaceId, | |
}).catch(error => { | |
console.error("Failed to fetch space data:", error); | |
redirect("/error"); | |
}); | |
if (!space) { | |
redirect("/embedded-portal"); | |
} else { | |
const flatfileSpace = await FlatfileService.getSpace({ | |
flatfileSpaceId: space.flatfileSpaceId, | |
}).catch(error => { | |
console.error("Failed to fetch Flatfile space data:", error); | |
redirect("/error"); | |
}); | |
if (!flatfileSpace) { | |
redirect("/error"); | |
} | |
} |
const space = await SpaceService.getSpaceForWorkflow({ | ||
userId: session.user.id, | ||
workflowType: WorkflowType.Embed, | ||
}); |
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.
Add error handling for the asynchronous operation to improve robustness and user experience in case of errors.
const space = await SpaceService.getSpaceForWorkflow({
userId: session.user.id,
workflowType: WorkflowType.Embed,
}).catch(error => {
console.error("Failed to fetch space data:", error);
// Redirect to an error page or show an error message
redirect("/error");
});
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
const space = await SpaceService.getSpaceForWorkflow({ | |
userId: session.user.id, | |
workflowType: WorkflowType.Embed, | |
}); | |
const space = await SpaceService.getSpaceForWorkflow({ | |
userId: session.user.id, | |
workflowType: WorkflowType.Embed, | |
}).catch(error => { | |
console.error("Failed to fetch space data:", error); | |
// Redirect to an error page or show an error message | |
redirect("/error"); | |
}); |
@@ -91,7 +91,7 @@ export default function CreateSpaceForm({ | |||
)} | |||
|
|||
<Button disabled={isPending} type="submit"> | |||
{isPending ? "Creating..." : "Create Space"} | |||
{isPending ? "Setting Up Flatfile..." : "Setup Flatfile"} |
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.
Consider adding an aria-live
attribute to the button or surrounding element to improve accessibility by announcing the button state change to screen readers.
+ <div aria-live="polite">
<Button disabled={isPending} type="submit">
{isPending ? "Setting Up Flatfile..." : "Setup Flatfile"}
</Button>
+ </div>
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
{isPending ? "Setting Up Flatfile..." : "Setup Flatfile"} | |
<div aria-live="polite"> | |
<Button disabled={isPending} type="submit"> | |
{isPending ? "Setting Up Flatfile..." : "Setup Flatfile"} | |
</Button> | |
</div> |
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.
One comment on passing the constant through but otherwise +1!
const space = await SpaceService.getSpaceForWorkflow({ | ||
userId: session.user.id, | ||
workflowType: WorkflowType.Embed, | ||
}); | ||
|
||
if (space) { | ||
redirect(`/embedded-portal/${space.id}`); | ||
} |
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.
Consider wrapping the space fetching and redirection logic in a try-catch block to handle potential errors more gracefully.
+ try {
const space = await SpaceService.getSpaceForWorkflow({
userId: session.user.id,
workflowType: WorkflowType.Embed,
});
if (space) {
redirect(`/embedded-portal/${space.id}`);
}
+ } catch (error) {
+ console.error("Error fetching space or redirecting:", error);
+ // Redirect to an error page or show an error message
+ redirect("/error");
+ }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
const space = await SpaceService.getSpaceForWorkflow({ | |
userId: session.user.id, | |
workflowType: WorkflowType.Embed, | |
}); | |
if (space) { | |
redirect(`/embedded-portal/${space.id}`); | |
} | |
try { | |
const space = await SpaceService.getSpaceForWorkflow({ | |
userId: session.user.id, | |
workflowType: WorkflowType.Embed, | |
}); | |
if (space) { | |
redirect(`/embedded-portal/${space.id}`); | |
} | |
} catch (error) { | |
console.error("Error fetching space or redirecting:", error); | |
// Redirect to an error page or show an error message | |
redirect("/error"); | |
} |
Slightly WIP still. Will clean up a bit later.
Summary by CodeRabbit
EmbeddedPortal
component for displaying an embedded Flatfile data import portal.SetupSpace
component to handle different workflow types dynamically, improving the onboarding process.Page
component to fetch space data based on user session and redirect or render appropriate components based on the existence of space.CreateSpaceForm
by changing the button text to "Setup Flatfile" during submission, enhancing user feedback.SetupSpace
component to accept new props for increased flexibility..env.example
with new environment variables for better configuration management.preflight.js
for improved environment variable management.