Skip to main content

Project Actions

Project server actions are functions which interact with the project data in the database. These functions are used to perform operations on the project data, such as creating, updating, and deleting project data.

Functions

async getCurrentProjects()

Gets all current project documents for the current user. Filters projects by the current year (Ex. 2016-17).

Example usage:

import { getCurrentProjects } from "@/app/_db/server-actions/project";
...
const [projects, setProjects] = useState(null);

useEffect(() => {
try {
getCurrentProjects().then((data) => {
setProjects(data);
});
} catch (error) {
console.error("Error fetching projects:", error);
}
}, []);
...

async getProjects()

Gets all project documents for a user.

Example usage:

import { getProjects } from "@/app/_db/server-actions/project";
...
const [projects, setProjects] = useState(null);

useEffect(() => {
try {
getProjects().then((data) => {
setProjects(data);
});
} catch (error) {
console.error("Error fetching projects:", error);
}
}, []);
...

async getProject(projectId)

Gets a project document by its ID.

Example usage:

import { getProject } from "@/app/_db/server-actions/project";
...
const [project, setProject] = useState(null);

useEffect(() => {
try {
getProject(projectId).then((data) => {
setProject(data);
});
} catch (error) {
console.error("Error fetching project:", error);
}
}, []);
...

async addProject(prevState, formData)

Add a new project document to the database. This function is intended to be used with an HTML form data object. This will often be called with the react hook useFormState.

Example usage:

import { addProject } from "@/app/_db/server-actions/project";
...
const [formState, setFormState] = useFormState(addProject, null);
...

async updateProject(prevState, formData)

Updates a project document in the database. This function is intended to be used with an HTML form data object. This will often be called with the react hook useFormState.

Example usage:

import { updateProject } from "@/app/_db/server-actions/project";
...
const [formState, setFormState] = useFormState(updateProject, project);
...