Skip to content

Commit 70a44a8

Browse files
committed
adds logging
1 parent f0e5998 commit 70a44a8

1 file changed

Lines changed: 31 additions & 7 deletions

File tree

src/routes/(style)/(admin)/admin/targets/init/+page.svelte

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,46 @@
1111
isLoading = true;
1212
1313
try {
14-
// Create new target using zero-sync mutation
15-
await z.mutate.targets.insert({
14+
console.log('Creating target with data:', { name, image, type, inspo });
15+
console.log('User ID:', z.userID);
16+
17+
if (!z.userID) {
18+
throw new Error('User is not authenticated. Please log in and try again.');
19+
}
20+
21+
const now = Date.now();
22+
const targetData = {
1623
id: crypto.randomUUID(),
1724
name,
1825
image,
1926
type,
2027
inspo,
2128
created_by: z.userID,
22-
is_active: true
23-
});
29+
is_active: true,
30+
archived_at: null,
31+
last_updated_at: now,
32+
created_at: now,
33+
updated_at: now
34+
};
35+
36+
console.log('Full target data:', targetData);
37+
38+
// Create new target using zero-sync mutation
39+
const result = await z.mutate.targets.insert(targetData);
40+
41+
console.log('Target created successfully:', result);
42+
43+
// Small delay to ensure sync completes
44+
await new Promise((resolve) => setTimeout(resolve, 500));
2445
25-
// Redirect to dashboard on success
26-
goto('/dashboard');
46+
// Redirect to targets list on success
47+
await goto('/admin/targets');
2748
} catch (error) {
2849
console.error('Error creating target:', error);
29-
alert('Failed to create target. Please try again.');
50+
console.error('Error details:', JSON.stringify(error, null, 2));
51+
const errorMessage =
52+
error instanceof Error ? error.message : 'Unknown error. Check console for details.';
53+
alert(`Failed to create target: ${errorMessage}`);
3054
} finally {
3155
isLoading = false;
3256
}

0 commit comments

Comments
 (0)