|
|
@@ -1,5 +1,6 @@
|
|
|
'use client';
|
|
|
|
|
|
+import { useKindeBrowserClient } from "@kinde-oss/kinde-auth-nextjs";
|
|
|
import { useState, useEffect } from 'react';
|
|
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
@@ -29,6 +30,7 @@ export function CreateImportDialog({ open, onOpenChange, onSuccess }: CreateImpo
|
|
|
const [layouts, setLayouts] = useState<LayoutConfiguration[]>([]);
|
|
|
const [loadingLayouts, setLoadingLayouts] = useState(true);
|
|
|
const { toast } = useToast();
|
|
|
+ const { user } = useKindeBrowserClient();
|
|
|
|
|
|
useEffect(() => {
|
|
|
async function loadLayouts() {
|
|
|
@@ -98,21 +100,14 @@ export function CreateImportDialog({ open, onOpenChange, onSuccess }: CreateImpo
|
|
|
|
|
|
try {
|
|
|
// First, upload the file
|
|
|
- const uploadResult = await uploadFile(selectedFile);
|
|
|
- if (!uploadResult.success) {
|
|
|
- toast({
|
|
|
- title: 'Error',
|
|
|
- description: uploadResult.error || 'Failed to upload file',
|
|
|
- variant: 'destructive',
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
+ const userId = user?.id ? user.id : "unknown-user-id";
|
|
|
+ const uploadResult = await uploadFile(selectedFile, userId);
|
|
|
|
|
|
// Then create the import with the file reference
|
|
|
const result = await createImport({
|
|
|
name: name.trim(),
|
|
|
layoutId: parseInt(layoutId),
|
|
|
- fileId: uploadResult.data?.id,
|
|
|
+ fileId: uploadResult.id,
|
|
|
});
|
|
|
|
|
|
if (result.success) {
|
|
|
@@ -199,8 +194,8 @@ export function CreateImportDialog({ open, onOpenChange, onSuccess }: CreateImpo
|
|
|
<Button type="button" variant="outline" onClick={() => onOpenChange(false)} disabled={loading}>
|
|
|
Cancel
|
|
|
</Button>
|
|
|
- <Button
|
|
|
- type="submit"
|
|
|
+ <Button
|
|
|
+ type="submit"
|
|
|
disabled={loading || !selectedFile || !name || !layoutId}
|
|
|
>
|
|
|
{loading ? 'Creating...' : 'Create Import'}
|