fix: avoid app crashed when there is no data to render

This commit is contained in:
Pablo Lara
2024-11-06 07:45:57 +01:00
parent f96777bcf9
commit 76c6065a80
2 changed files with 15 additions and 9 deletions
@@ -31,6 +31,9 @@ async function SSRTestConnection({
formData.append("id", searchParams.id);
const providerData = await getProvider(formData);
if (providerData.errors) {
redirect("/providers/connect-account");
}
return (
<TestConnectionForm
+12 -9
View File
@@ -3,17 +3,20 @@ import { MetaDataProps } from "@/types";
export const wait = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));
// Helper function to create dictionaries by type
export const createDict = (
type: string,
data: any,
includedField: string = "included",
) =>
Object.fromEntries(
data[includedField]
.filter((item: { type: string }) => item.type === type)
.map((item: { id: string }) => [item.id, item]),
export function createDict(type: string, data: any) {
const includedField = data?.included?.filter(
(item: { type: string }) => item.type === type,
);
if (!includedField || includedField.length === 0) {
return {};
}
return Object.fromEntries(
includedField.map((item: { id: string }) => [item.id, item]),
);
}
export const parseStringify = (value: any) => JSON.parse(JSON.stringify(value));
export const convertFileToUrl = (file: File) => URL.createObjectURL(file);