|
@@ -7,6 +7,7 @@ import { Upload, FileText, Database, BarChart3, CheckCircle, Loader2, History, P
|
|
|
import { UploadForm } from '@/app/components/uploadForm';
|
|
import { UploadForm } from '@/app/components/uploadForm';
|
|
|
import { createCintasImportRecord, processCintasImportData } from '@/app/actions/cintas-workflow';
|
|
import { createCintasImportRecord, processCintasImportData } from '@/app/actions/cintas-workflow';
|
|
|
import { getImports } from '@/app/actions/imports';
|
|
import { getImports } from '@/app/actions/imports';
|
|
|
|
|
+import { useKindeBrowserClient } from "@kinde-oss/kinde-auth-nextjs";
|
|
|
|
|
|
|
|
interface FileData {
|
|
interface FileData {
|
|
|
id: string;
|
|
id: string;
|
|
@@ -43,6 +44,7 @@ interface ImportRecord {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export default function CintasCalendarSummaryPage() {
|
|
export default function CintasCalendarSummaryPage() {
|
|
|
|
|
+ const { user } = useKindeBrowserClient();
|
|
|
const [viewMode, setViewMode] = useState<'imports' | 'new-import' | 'summary'>('imports');
|
|
const [viewMode, setViewMode] = useState<'imports' | 'new-import' | 'summary'>('imports');
|
|
|
const [currentStep, setCurrentStep] = useState(1);
|
|
const [currentStep, setCurrentStep] = useState(1);
|
|
|
const [uploadedFile, setUploadedFile] = useState<FileData | null>(null);
|
|
const [uploadedFile, setUploadedFile] = useState<FileData | null>(null);
|
|
@@ -56,13 +58,22 @@ export default function CintasCalendarSummaryPage() {
|
|
|
const [loadingImports, setLoadingImports] = useState(true);
|
|
const [loadingImports, setLoadingImports] = useState(true);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- loadPriorImports();
|
|
|
|
|
- }, []);
|
|
|
|
|
|
|
+ if (user) {
|
|
|
|
|
+ loadPriorImports();
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [user]);
|
|
|
|
|
|
|
|
const loadPriorImports = async () => {
|
|
const loadPriorImports = async () => {
|
|
|
try {
|
|
try {
|
|
|
setLoadingImports(true);
|
|
setLoadingImports(true);
|
|
|
- const result = await getImports();
|
|
|
|
|
|
|
+ setError(null); // Clear any previous errors
|
|
|
|
|
+
|
|
|
|
|
+ if (!user?.id) {
|
|
|
|
|
+ // Don't set error here, just return - user might still be loading
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const result = await getImports(user.id);
|
|
|
if (result.success && result.data) {
|
|
if (result.success && result.data) {
|
|
|
// Map the data to match our ImportRecord interface
|
|
// Map the data to match our ImportRecord interface
|
|
|
const mappedData = result.data.map((item: any) => ({
|
|
const mappedData = result.data.map((item: any) => ({
|
|
@@ -274,10 +285,14 @@ export default function CintasCalendarSummaryPage() {
|
|
|
</div>
|
|
</div>
|
|
|
) : priorImports.length === 0 ? (
|
|
) : priorImports.length === 0 ? (
|
|
|
<div className="text-center py-8">
|
|
<div className="text-center py-8">
|
|
|
- <p className="text-muted-foreground mb-4">No prior imports found</p>
|
|
|
|
|
- <Button onClick={handleStartNewImport}>
|
|
|
|
|
- Create First Import
|
|
|
|
|
- </Button>
|
|
|
|
|
|
|
+ <p className="text-muted-foreground mb-4">
|
|
|
|
|
+ {user ? 'No prior imports found' : 'Please sign in to view imports'}
|
|
|
|
|
+ </p>
|
|
|
|
|
+ {user && (
|
|
|
|
|
+ <Button onClick={handleStartNewImport}>
|
|
|
|
|
+ Create First Import
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ )}
|
|
|
</div>
|
|
</div>
|
|
|
) : (
|
|
) : (
|
|
|
<div className="space-y-4">
|
|
<div className="space-y-4">
|