Revert "sad"

This reverts commit 550a8f26a2.
This commit is contained in:
alorig
2025-11-30 06:14:54 +05:00
parent 550a8f26a2
commit 8d47d6a555
5 changed files with 31 additions and 142 deletions

View File

@@ -404,84 +404,29 @@ export default function IndustriesSectorsKeywords() {
const formData = new FormData();
formData.append('file', importFile);
// Get token from auth store (consistent with other API calls)
const getAuthToken = () => {
try {
const authStorage = localStorage.getItem('auth-storage');
if (authStorage) {
const parsed = JSON.parse(authStorage);
return parsed?.state?.token || null;
}
} catch (e) {
// Ignore parsing errors
}
return null;
};
const token = getAuthToken();
const headers: HeadersInit = {};
if (token) {
headers['Authorization'] = `Bearer ${token}`;
}
const response = await fetch('/api/v1/auth/seed-keywords/import_seed_keywords/', {
method: 'POST',
headers,
headers: {
'Authorization': `Token ${localStorage.getItem('authToken')}`,
},
body: formData,
credentials: 'include', // Add credentials for consistency
});
let errorMessage = 'Import failed';
// Handle common HTTP status codes
if (response.status === 404) {
errorMessage = 'Import endpoint not found. Please check if the backend service is running.';
} else if (response.status === 429) {
errorMessage = 'Too many requests. Please wait a moment before trying again.';
} else if (response.status === 403) {
errorMessage = 'Access denied. Admin privileges required for seed keyword import.';
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || 'Import failed');
}
const result = await response.json();
toast.success(`Successfully imported ${result.created || 0} keywords`);
try {
const result = await response.json();
if (!response.ok) {
// Try to get error message from response (override status-based message if available)
if (result.error) {
errorMessage = result.error;
} else if (result.message) {
errorMessage = result.message;
}
throw new Error(errorMessage);
}
// Success case
const importedCount = result.data?.imported || result.imported || 0;
const skippedCount = result.data?.skipped || result.skipped || 0;
const errors = result.data?.errors || result.errors || [];
toast.success(
`Successfully imported ${importedCount} keyword(s)${skippedCount > 0 ? `, ${skippedCount} skipped` : ''}`
);
if (errors.length > 0) {
toast.info(`Errors: ${errors.slice(0, 3).join(', ')}`);
}
// Reset and close modal
setImportFile(null);
setIsImportModalOpen(false);
// Reload keywords
if (activeSite) {
loadSeedKeywords();
}
} catch (jsonError: any) {
// If JSON parsing fails, handle it gracefully
if (!response.ok) {
throw new Error(errorMessage || `Server error: ${response.status}`);
}
throw jsonError;
// Reset and close modal
setImportFile(null);
setIsImportModalOpen(false);
// Reload keywords
if (activeSite) {
loadSeedKeywords();
}
} catch (error: any) {
console.error('Import error:', error);
@@ -686,21 +631,6 @@ export default function IndustriesSectorsKeywords() {
title="Add Keywords"
badge={{ icon: <BoltIcon />, color: 'blue' }}
/>
{/* Action Buttons */}
{isAdmin && (
<div className="px-6 pt-4 pb-2 flex justify-end gap-2">
<Button
variant="secondary"
size="md"
startIcon={<PlusIcon className="w-4 h-4" />}
onClick={handleImportClick}
>
Import Keywords
</Button>
</div>
)}
<TablePageTemplate
columns={pageConfig.columns}
data={seedKeywords}
@@ -731,7 +661,18 @@ export default function IndustriesSectorsKeywords() {
}
}}
bulkActions={pageConfig.bulkActions}
customActions={undefined}
customActions={
isAdmin ? (
<Button
variant="secondary"
size="sm"
onClick={handleImportClick}
>
<PlusIcon className="w-4 h-4 mr-2" />
Import Keywords
</Button>
) : undefined
}
pagination={{
currentPage,
totalPages,
@@ -761,7 +702,6 @@ export default function IndustriesSectorsKeywords() {
setImportFile(null);
}
}}
className="max-w-md"
>
<div className="p-6 space-y-4">
<h2 className="text-xl font-semibold text-gray-900 dark:text-white mb-4">