Solve an issue with project.find
This commit is contained in:
parent
f202c0488c
commit
167a4ae52c
2 changed files with 18 additions and 17 deletions
|
|
@ -55,11 +55,10 @@ const InboxItems: React.FC = () => {
|
|||
const refreshInboxItems = useCallback(() => {
|
||||
loadInboxItemsToStore();
|
||||
}, []);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
// Initial data loading
|
||||
refreshInboxItems();
|
||||
loadProjects();
|
||||
|
||||
// Set up an event listener for force reload
|
||||
const handleForceReload = () => {
|
||||
|
|
@ -104,16 +103,6 @@ const InboxItems: React.FC = () => {
|
|||
};
|
||||
}, [refreshInboxItems, showSuccessToast, t]);
|
||||
|
||||
// Load projects for the modals
|
||||
const loadProjects = async () => {
|
||||
try {
|
||||
const projectData = await fetchProjects();
|
||||
setProjects(projectData);
|
||||
} catch (error) {
|
||||
console.error('Failed to load projects:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleProcessItem = async (id: number) => {
|
||||
try {
|
||||
await processInboxItemWithStore(id);
|
||||
|
|
@ -155,7 +144,18 @@ const InboxItems: React.FC = () => {
|
|||
};
|
||||
|
||||
// Modal handlers
|
||||
const handleOpenTaskModal = (task: Task, inboxItemId?: number) => {
|
||||
const handleOpenTaskModal = async (task: Task, inboxItemId?: number) => {
|
||||
// Load projects first before opening the modal
|
||||
try {
|
||||
const projectData = await fetchProjects();
|
||||
// Make sure we always set an array
|
||||
setProjects(Array.isArray(projectData) ? projectData : []);
|
||||
} catch (error) {
|
||||
console.error('Failed to load projects:', error);
|
||||
showErrorToast(t('project.loadError', 'Failed to load projects'));
|
||||
setProjects([]); // Ensure we have an empty array even on error
|
||||
}
|
||||
|
||||
setTaskToEdit(task);
|
||||
|
||||
if (inboxItemId) {
|
||||
|
|
@ -326,7 +326,7 @@ const InboxItems: React.FC = () => {
|
|||
task={taskToEdit || { name: '', status: 'not_started', priority: 'medium' }}
|
||||
onSave={handleSaveTask}
|
||||
onDelete={() => {}} // No need to delete since it's a new task
|
||||
projects={projects}
|
||||
projects={Array.isArray(projects) ? projects : []}
|
||||
onCreateProject={handleCreateProject}
|
||||
/>
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ const TaskModal: React.FC<TaskModalProps> = ({
|
|||
}) => {
|
||||
const [formData, setFormData] = useState<Task>(task);
|
||||
const [tags, setTags] = useState<string[]>(task.tags?.map((tag) => tag.name) || []);
|
||||
const [filteredProjects, setFilteredProjects] = useState<Project[]>(projects);
|
||||
const [filteredProjects, setFilteredProjects] = useState<Project[]>(projects || []);
|
||||
const [newProjectName, setNewProjectName] = useState<string>("");
|
||||
const [isCreatingProject, setIsCreatingProject] = useState(false);
|
||||
const [dropdownOpen, setDropdownOpen] = useState(false);
|
||||
|
|
@ -55,7 +55,8 @@ const TaskModal: React.FC<TaskModalProps> = ({
|
|||
setFormData(task);
|
||||
setTags(task.tags?.map((tag) => tag.name) || []);
|
||||
|
||||
const currentProject = projects.find((project) => project.id === task.project_id);
|
||||
// Safely find the current project, handling the case where projects might be undefined
|
||||
const currentProject = projects?.find((project) => project.id === task.project_id);
|
||||
setNewProjectName(currentProject ? currentProject.name : '');
|
||||
|
||||
// Fetch parent task if this is a child task
|
||||
|
|
@ -202,7 +203,7 @@ const TaskModal: React.FC<TaskModalProps> = ({
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
setFilteredProjects(projects);
|
||||
setFilteredProjects(projects || []);
|
||||
}, [projects]);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue