manage-projects
A project is linked to a user's profile and is used to set targets for screenings.
localhost:3000/projects
Project data is available via Supabase client import { supabase } from "@utils/supabaseClient";
The users are allocated a project during the import process, so projects must be created before the users are imported.
Within this component the projects can be viewed with and also deleted
Data is filtered based on the user's organisation and they will therefore only see projects for their organisation.
src/pages/projects.js
async function getProjects() {
try {
setLoading(true);
let { data, error, status } = await supabase
.from("projects")
.select("*")
.eq("organisation", organisation)
.order("created_at", { ascending: false });
// .single();
if (error && status !== 406) {
throw error;
}
if (data) {
// console.log(data);
setUserData(data);
}
} catch (error) {
// console.log("user not logged in");
} finally {
setLoading(false);
}
}
Once a project has at least one user associated with it then it can no longer be deleted.
src/pages/projects.js
async function deleteProjectProfile(id) {
const userDataToSend = {
entry: id,
};
try {
setLoading(true);
let { error } = await supabase.from("projects").delete().match({ id: id });
if (error) {
throw error;
}
} catch (error) {
alert("This project is in use and can't be deleted");
console.log(error.message);
} finally {
getProjects(); // reload the data to remove from table
setLoading(false);
}
}