realtimex-crm 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{DealList-C_0DbLKA.js → DealList-CT-qgbS4.js} +2 -2
- package/dist/assets/{DealList-C_0DbLKA.js.map → DealList-CT-qgbS4.js.map} +1 -1
- package/dist/assets/{index-CdC59W53.js → index-B1O8LdjN.js} +45 -45
- package/dist/assets/{index-CdC59W53.js.map → index-B1O8LdjN.js.map} +1 -1
- package/dist/index.html +1 -1
- package/dist/stats.html +1 -1
- package/package.json +1 -1
- package/src/components/atomic-crm/login/StartPage.tsx +37 -5
- package/src/components/atomic-crm/root/DatabaseHealthCheck.tsx +2 -4
- package/src/lib/database-health-check.ts +27 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "realtimex-crm",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "RealTimeX CRM - A full-featured CRM built with React, shadcn-admin-kit, and Supabase. Fork of Atomic CRM with RealTimeX App SDK integration.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -2,26 +2,58 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
2
2
|
import { useDataProvider } from "ra-core";
|
|
3
3
|
import { Navigate } from "react-router-dom";
|
|
4
4
|
import { LoginPage } from "@/components/admin/login-page";
|
|
5
|
+
import { checkDatabaseHealth } from "@/lib/database-health-check";
|
|
6
|
+
import { getSupabaseConfig } from "@/lib/supabase-config";
|
|
7
|
+
import { DatabaseSetupGuide } from "../setup/DatabaseSetupGuide";
|
|
5
8
|
|
|
6
9
|
import type { CrmDataProvider } from "../providers/types";
|
|
7
10
|
import { LoginSkeleton } from "./LoginSkeleton";
|
|
8
11
|
|
|
9
12
|
export const StartPage = () => {
|
|
10
13
|
const dataProvider = useDataProvider<CrmDataProvider>();
|
|
14
|
+
|
|
15
|
+
// First check database health
|
|
16
|
+
const {
|
|
17
|
+
data: healthStatus,
|
|
18
|
+
error: healthError,
|
|
19
|
+
isPending: isCheckingHealth,
|
|
20
|
+
} = useQuery({
|
|
21
|
+
queryKey: ["database-health"],
|
|
22
|
+
queryFn: checkDatabaseHealth,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Then check if initialized (only if database is healthy)
|
|
11
26
|
const {
|
|
12
27
|
data: isInitialized,
|
|
13
|
-
error,
|
|
14
|
-
isPending,
|
|
28
|
+
error: initError,
|
|
29
|
+
isPending: isCheckingInit,
|
|
15
30
|
} = useQuery({
|
|
16
31
|
queryKey: ["init"],
|
|
17
32
|
queryFn: async () => {
|
|
18
33
|
return dataProvider.isInitialized();
|
|
19
34
|
},
|
|
35
|
+
enabled: healthStatus?.isHealthy === true,
|
|
20
36
|
});
|
|
21
37
|
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
|
|
38
|
+
// Show loading state
|
|
39
|
+
if (isCheckingHealth || isCheckingInit) return <LoginSkeleton />;
|
|
40
|
+
|
|
41
|
+
// Show database setup guide if schema is missing
|
|
42
|
+
if (healthStatus && !healthStatus.isHealthy) {
|
|
43
|
+
const config = getSupabaseConfig();
|
|
44
|
+
if (config) {
|
|
45
|
+
return (
|
|
46
|
+
<DatabaseSetupGuide
|
|
47
|
+
missingTables={healthStatus.missingTables}
|
|
48
|
+
supabaseUrl={config.url}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Show login page if there's an error or already initialized
|
|
55
|
+
if (healthError || initError || isInitialized) return <LoginPage />;
|
|
25
56
|
|
|
57
|
+
// Not initialized yet, go to signup
|
|
26
58
|
return <Navigate to="/sign-up" />;
|
|
27
59
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
|
-
import { useDataProvider } from "ra-core";
|
|
3
2
|
import { checkDatabaseHealth, DatabaseHealthStatus } from "@/lib/database-health-check";
|
|
4
3
|
import { getSupabaseConfig } from "@/lib/supabase-config";
|
|
5
4
|
import { DatabaseSetupGuide } from "../setup/DatabaseSetupGuide";
|
|
@@ -9,7 +8,6 @@ interface DatabaseHealthCheckProps {
|
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
export function DatabaseHealthCheck({ children }: DatabaseHealthCheckProps) {
|
|
12
|
-
const dataProvider = useDataProvider();
|
|
13
11
|
const [healthStatus, setHealthStatus] = useState<DatabaseHealthStatus | null>(null);
|
|
14
12
|
const [isChecking, setIsChecking] = useState(true);
|
|
15
13
|
|
|
@@ -18,7 +16,7 @@ export function DatabaseHealthCheck({ children }: DatabaseHealthCheckProps) {
|
|
|
18
16
|
|
|
19
17
|
async function checkHealth() {
|
|
20
18
|
try {
|
|
21
|
-
const status = await checkDatabaseHealth(
|
|
19
|
+
const status = await checkDatabaseHealth();
|
|
22
20
|
if (!cancelled) {
|
|
23
21
|
setHealthStatus(status);
|
|
24
22
|
setIsChecking(false);
|
|
@@ -36,7 +34,7 @@ export function DatabaseHealthCheck({ children }: DatabaseHealthCheckProps) {
|
|
|
36
34
|
return () => {
|
|
37
35
|
cancelled = true;
|
|
38
36
|
};
|
|
39
|
-
}, [
|
|
37
|
+
}, []);
|
|
40
38
|
|
|
41
39
|
// Show loading state
|
|
42
40
|
if (isChecking) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { supabase } from "@/components/atomic-crm/providers/supabase/supabase";
|
|
2
2
|
|
|
3
3
|
export interface DatabaseHealthStatus {
|
|
4
4
|
isHealthy: boolean;
|
|
@@ -8,10 +8,11 @@ export interface DatabaseHealthStatus {
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Check if the database has the required schema
|
|
11
|
+
* This function directly queries the Supabase client to avoid data provider
|
|
12
|
+
* transformations (e.g., contacts -> contacts_summary) that would fail
|
|
13
|
+
* if the database schema doesn't exist yet.
|
|
11
14
|
*/
|
|
12
|
-
export async function checkDatabaseHealth(
|
|
13
|
-
dataProvider: DataProvider,
|
|
14
|
-
): Promise<DatabaseHealthStatus> {
|
|
15
|
+
export async function checkDatabaseHealth(): Promise<DatabaseHealthStatus> {
|
|
15
16
|
const requiredTables = [
|
|
16
17
|
"contacts",
|
|
17
18
|
"companies",
|
|
@@ -26,23 +27,31 @@ export async function checkDatabaseHealth(
|
|
|
26
27
|
const missingTables: string[] = [];
|
|
27
28
|
|
|
28
29
|
try {
|
|
29
|
-
// Try to query each table
|
|
30
|
+
// Try to query each table directly via Supabase client
|
|
30
31
|
for (const table of requiredTables) {
|
|
31
32
|
try {
|
|
32
|
-
await
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
const { error } = await supabase
|
|
34
|
+
.from(table)
|
|
35
|
+
.select("id")
|
|
36
|
+
.limit(1);
|
|
37
|
+
|
|
38
|
+
if (error) {
|
|
39
|
+
// Check if it's a "table not found" error
|
|
40
|
+
if (
|
|
41
|
+
error.message?.includes("Could not find the table") ||
|
|
42
|
+
error.message?.includes("relation") ||
|
|
43
|
+
error.message?.includes("does not exist") ||
|
|
44
|
+
error.code === "PGRST200" // PostgREST error code for missing table
|
|
45
|
+
) {
|
|
46
|
+
missingTables.push(table);
|
|
47
|
+
} else {
|
|
48
|
+
// Some other error - log it but don't fail health check
|
|
49
|
+
console.warn(`Unexpected error querying ${table}:`, error);
|
|
50
|
+
}
|
|
45
51
|
}
|
|
52
|
+
} catch (error: any) {
|
|
53
|
+
console.warn(`Failed to query ${table}:`, error);
|
|
54
|
+
missingTables.push(table);
|
|
46
55
|
}
|
|
47
56
|
}
|
|
48
57
|
|