diff --git a/src/actions/admin.ts b/src/actions/admin.ts
index 974d49d..e3f82a6 100644
--- a/src/actions/admin.ts
+++ b/src/actions/admin.ts
@@ -3,7 +3,7 @@
import { adminAction } from "@/lib/server/safe-action";
import { z } from "zod";
import { db } from "@/db";
-import { suborgs, cohorts } from "@/db/schema";
+import { suborgs, teams } from "@/db/schema";
import { eq } from "drizzle-orm";
import { nanoid } from "nanoid";
@@ -29,7 +29,7 @@ export const createSuborg = adminAction
return suborg[0];
});
-export const createCohort = adminAction
+export const createTeam = adminAction
.schema(
z.object({
suborgSlug: z.string().min(1),
@@ -49,8 +49,8 @@ export const createCohort = adminAction
throw new Error("Suborg not found");
}
- const cohort = await db
- .insert(cohorts)
+ const team = await db
+ .insert(teams)
.values({
id: nanoid(8),
name,
@@ -60,5 +60,5 @@ export const createCohort = adminAction
})
.returning();
- return cohort[0];
+ return team[0];
});
diff --git a/src/actions/settings.ts b/src/actions/settings.ts
index 20ee12a..3cba608 100644
--- a/src/actions/settings.ts
+++ b/src/actions/settings.ts
@@ -2,7 +2,7 @@
"use server";
import { z } from "zod";
-import { userToCohorts } from "@/db/schema";
+import { userToTeams } from "@/db/schema";
import { revalidatePath } from "next/cache";
import { authedAction } from "@/lib/server/safe-action";
import { and, eq } from "drizzle-orm";
@@ -11,91 +11,91 @@ import { UserSettingsSchema } from "@/lib/zod";
import { user } from "@/db/schema";
-// Schema for joining a cohort
-const joinCohortSchema = z.object({
- cohortId: z.string(),
+// Schema for joining a team
+const joinTeamSchema = z.object({
+ teamId: z.string(),
});
-// Action to join a cohort
-export const joinCohort = authedAction
- .schema(joinCohortSchema)
+// Action to join a team
+export const joinTeam = authedAction
+ .schema(joinTeamSchema)
.action(async ({ ctx, parsedInput }) => {
- const { cohortId } = parsedInput;
+ const { teamId } = parsedInput;
const userId = ctx.session.user.id;
try {
- // Check if user is already in the cohort
- const existingLink = await db.query.userToCohorts.findFirst({
+ // Check if user is already in the team
+ const existingLink = await db.query.userToTeams.findFirst({
where: (link, { eq, and }) =>
- and(eq(link.userId, userId), eq(link.cohortId, cohortId)),
+ and(eq(link.userId, userId), eq(link.teamId, teamId)),
});
if (existingLink) {
return {
success: false,
- message: "Already a member of this cohort",
+ message: "Already a member of this team",
};
}
- // Add user to cohort
- await db.insert(userToCohorts).values({
+ // Add user to team
+ await db.insert(userToTeams).values({
userId,
- cohortId,
+ teamId,
});
// Revalidate the settings page to reflect the changes
revalidatePath("/settings");
- return { success: true, message: "Successfully joined cohort" };
+ return { success: true, message: "Successfully joined team" };
} catch (error) {
- console.error("Error joining cohort:", error);
- return { success: false, message: "Failed to join cohort" };
+ console.error("Error joining team:", error);
+ return { success: false, message: "Failed to join team" };
}
});
-// Schema for leaving a cohort
-const leaveCohortSchema = z.object({
- cohortId: z.string(),
+// Schema for leaving a team
+const leaveTeamSchema = z.object({
+ teamId: z.string(),
});
-// Action to leave a cohort
-export const leaveCohort = authedAction
- .schema(leaveCohortSchema)
+// Action to leave a team
+export const leaveTeam = authedAction
+ .schema(leaveTeamSchema)
.action(async ({ ctx, parsedInput }) => {
- const { cohortId } = parsedInput;
+ const { teamId } = parsedInput;
const userId = ctx.session.user.id;
try {
- // Check if user is in the cohort
- const existingLink = await db.query.userToCohorts.findFirst({
+ // Check if user is in the team
+ const existingLink = await db.query.userToTeams.findFirst({
where: (link, { eq, and }) =>
- and(eq(link.userId, userId), eq(link.cohortId, cohortId)),
+ and(eq(link.userId, userId), eq(link.teamId, teamId)),
});
if (!existingLink) {
return {
success: false,
- message: "Not a member of this cohort",
+ message: "Not a member of this team",
};
}
- // Remove user from cohort
+ // Remove user from team
await db
- .delete(userToCohorts)
+ .delete(userToTeams)
.where(
and(
- eq(userToCohorts.userId, userId),
- eq(userToCohorts.cohortId, cohortId),
+ eq(userToTeams.userId, userId),
+ eq(userToTeams.teamId, teamId),
),
);
// Revalidate the settings page to reflect the changes
revalidatePath("/settings");
- return { success: true, message: "Successfully left cohort" };
+ return { success: true, message: "Successfully left team" };
} catch (error) {
- console.error("Error leaving cohort:", error);
- return { success: false, message: "Failed to leave cohort" };
+ console.error("Error leaving team:", error);
+ return { success: false, message: "Failed to leave team" };
}
});
diff --git a/src/app/(core)/admin/teams/client.tsx b/src/app/(core)/admin/teams/client.tsx
index 665ed24..0010955 100644
--- a/src/app/(core)/admin/teams/client.tsx
+++ b/src/app/(core)/admin/teams/client.tsx
@@ -15,7 +15,7 @@ import {
} from "@/components/ui/dialog";
import { Label } from "@/components/ui/label";
import { Plus } from "lucide-react";
-import { createSuborg, createCohort } from "@/actions/admin";
+import { createSuborg, createTeam } from "@/actions/admin";
import { toast } from "sonner";
import { useAction } from "next-safe-action/hooks";
@@ -66,7 +66,7 @@ export function CreateSuborgDialog() {