Skip to content

Commit

Permalink
More notifications!
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogasp committed Nov 21, 2024
1 parent ad803cb commit bd9eadf
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions src/services/groups/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,31 @@ export const addGroup = async (groupName: string) => {
headers: { "content-type": "application/scim+json" },
});
if (response.ok) {
setNotification({ type: "success", message: "Group created" });
revalidatePath("/groups");
} else {
const msg = await response.text();
throw Error(`Add RootGroup failed with status ${response.status} ${msg}`);
setNotification({
type: "error",
message: "Cannot create group",
subtitle: `Error ${response.status} ${msg}`,
});
}
};

export const deleteGroup = async (groupId: string) => {
const url = `${BASE_URL}/scim/Groups/${groupId}`;
const response = await authFetch(url, { method: "DELETE" });
if (response.ok) {
setNotification({ type: "info", message: "Group deleted" });
revalidatePath("/groups");
} else {
const msg = await response.text();
throw Error(
`Delete RootGroup failed with status ${response.status} ${msg}`
);
setNotification({
type: "error",
message: "Cannot delete group",
subtitle: `Error ${response.status} ${msg}`,
});
}
};

Expand All @@ -122,10 +130,15 @@ export const addSubgroup = async (groupName: string, parentGroup: Group) => {
headers: { "content-type": "application/scim+json" },
});
if (response.ok) {
setNotification({ type: "success", message: "Subgroup added" });
revalidatePath("/groups");
} else {
const msg = await response.text();
throw Error(`Add Subgroup failed with status ${response.status} ${msg}`);
setNotification({
type: "error",
message: "Cannot add subgroup",
subtitle: `Error ${response.status} ${msg}`,
});
}
};

Expand Down Expand Up @@ -207,12 +220,15 @@ export const assignGroupManager = async (groupId: string, userId: string) => {
method: "POST",
});
if (response.ok) {
setNotification({ type: "success", message: "Success" });
revalidatePath(`/groups/${groupId}`);
} else {
const msg = await response.text();
throw Error(
`Assign group manager failed with status ${response.status} ${msg}`
);
setNotification({
type: "error",
message: "Cannot assign group manager",
subtitle: `Error ${response.status} ${msg}`,
});
}
};

Expand All @@ -222,11 +238,14 @@ export const revokeGroupManager = async (groupId: string, userId: string) => {
method: "DELETE",
});
if (response.ok) {
setNotification({ type: "success", message: "Success" });
revalidatePath(`/groups/${groupId}`);
} else {
const msg = await response.text();
throw Error(
`Revoke group manager failed with status ${response.status} ${msg}`
);
setNotification({
type: "error",
message: "Cannot revoke group manager",
subtitle: `Error ${response.status} ${msg}`,
});
}
};

0 comments on commit bd9eadf

Please sign in to comment.