Skip to content

Commit

Permalink
intermittent component mounting / state update error, seems to be res…
Browse files Browse the repository at this point in the history
…olved
  • Loading branch information
lcchrty committed May 31, 2024
1 parent 5357fd5 commit ec501c3
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions client/src/components/ProjectForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export default function ProjectForm({
const history = useHistory();

// ----------------- States -----------------
const { auth } = useAuth();
const [isLoading, setIsLoading] = useState(false);
const [locationType, setLocationType] = useState('remote');
// State to track the toggling from Project view to Edit Project View via edit icon.
const [editMode, setEditMode] = useState(false);
const { auth } = useAuth();
const [isModalOpen, setIsModalOpen] = useState(false);
const handleOpen = () => setIsModalOpen(true);
const handleClose = () => setIsModalOpen(false);
Expand Down Expand Up @@ -112,27 +112,24 @@ export default function ProjectForm({

// Handles POST request found in api/ProjectApiService.
const submitNewProject = async (data) => {
setIsLoading(true);
const projectApi = new ProjectApiService();

try {
setIsLoading(true);
const id = await projectApi.create(data);
history.push(`/projects/${id}`);
setIsLoading(false);
} catch (errors) {
console.error(errors);
setIsLoading(false);

return;
}
return () => setIsLoading(false);
};

// Fires PUT request to update the project,
const submitEditProject = async (data) => {
setIsLoading(true);
const projectApi = new ProjectApiService();
try {
const res = await projectApi.updateProject(projectToEdit._id, data);
setIsLoading(true);
await projectApi.updateProject(projectToEdit._id, data);
} catch (errors) {
console.error(errors);
setIsLoading(false);
Expand Down

0 comments on commit ec501c3

Please sign in to comment.