import React, { useState } from 'react'; import { XMarkIcon } from '@heroicons/react/24/outline'; import { getApiPath } from '../../config/paths'; interface SaveViewModalProps { searchQuery: string; filters: string[]; priority: string | null; due: string | null; onClose: () => void; onSave: () => void; } const SaveViewModal: React.FC = ({ searchQuery, filters, priority, due, onClose, onSave, }) => { const [viewName, setViewName] = useState(''); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!viewName.trim()) { setError('View name is required'); return; } setIsLoading(true); setError(''); try { const response = await fetch(getApiPath('views'), { method: 'POST', headers: { 'Content-Type': 'application/json', }, credentials: 'include', body: JSON.stringify({ name: viewName.trim(), search_query: searchQuery || null, filters: filters, priority: priority || null, due: due || null, }), }); if (!response.ok) { throw new Error('Failed to save view'); } onSave(); } catch (err) { setError('Failed to save view. Please try again.'); console.error('Error saving view:', err); } finally { setIsLoading(false); } }; return ( <> {/* Backdrop */}
{/* Modal */}

Save as Smart View

{ setViewName(e.target.value); setError(''); }} className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Enter view name" autoFocus /> {error && (

{error}

)}

This view will save:

    {filters.length > 0 && (
  • • Filters: {filters.join(', ')}
  • )} {searchQuery && (
  • • Search: "{searchQuery}"
  • )} {priority &&
  • • Priority: {priority}
  • } {due &&
  • • Due: {due}
  • }
); }; export default SaveViewModal;