Something went wrong. Try again.
A simple to-do app focused on tasks that can be completed within a specific time span. taskline.tobinio.dev
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788import { v4 } from "uuid";
export const useCreateOrganization = defineMutation({ async mutation(organization: { name: string }, { uuid }: { uuid: UUID }) { const { $api } = useNuxtApp(); return await $api(`/api/organization`, { method: "POST", body: { ...organization, uuid }, }); }, onMutate({ name }: { name: string }) { const queryCache = useQueryCache();
const activeOrganizations = queryCache.getQueryData<Organization[]>([ "organizations", ]); if (!activeOrganizations) return;
const organization = { uuid: v4(), name, };
activeOrganizations.push(organization); queryCache.setQueryData(["organizations"], [...activeOrganizations]);
return { uuid: organization.uuid }; }, onError(error) { const { showError } = useToast(); showError(error.message);
const queryCache = useQueryCache(); queryCache.invalidateQueries({ key: ["organizations"] }); },});
export const useLeaveOrganization = defineMutation({ async mutation(uuid: string) { const { $api } = useNuxtApp(); return await $api(`/api/organization/leave`, { method: "POST", body: { uuid: uuid }, }); }, onMutate(uuid: string) { const queryCache = useQueryCache();
const activeOrganizations = queryCache.getQueryData<Organization[]>([ "organizations", ]); if (!activeOrganizations) return;
queryCache.setQueryData( ["organizations"], activeOrganizations.filter((organization) => organization.uuid !== uuid), ); }, onError(error) { const { showError } = useToast(); showError(error.message);
const queryCache = useQueryCache(); queryCache.invalidateQueries({ key: ["organizations"] }); },});
export const useJoinOrganization = defineMutation({ async mutation(uuid: string) { const { $api } = useNuxtApp(); return await $api(`/api/organization/join`, { method: "POST", body: { uuid: uuid }, }); }, onSettled: () => { const queryCache = useQueryCache(); queryCache.invalidateQueries({ key: ["organizations"] }); }, onError(error) { const { showError } = useToast(); showError(error.message);
const queryCache = useQueryCache(); queryCache.invalidateQueries({ key: ["organizations"] }); },});