Skip to content

Commit 6b66b72

Browse files
authored
Adds button to delete project in project configurations (#163)
* Adds button to delete project in project configurations * Fixes linter issues
1 parent d47ff62 commit 6b66b72

File tree

2 files changed

+33
-0
lines changed
  • src/app

2 files changed

+33
-0
lines changed

src/app/(dashboard)/projects/[projectId]/configuration/page.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ export default function ProjectConfigurationPage({ params }: PageProps) {
6666
}
6767
};
6868

69+
const handleDeleteProject = async () => {
70+
const { data } = await axios.delete(`/api/projects?team_id=${teamId}`);
71+
if (data.success) {
72+
router.push(`/projects`);
73+
} else {
74+
console.log("Error deleting project");
75+
}
76+
};
77+
6978
const handleCalculate = async () => {
7079
const { data } = await axios.get(`/api/credmanager?team_id=${team!.id}`);
7180
if (data && data.success) {
@@ -108,6 +117,15 @@ export default function ProjectConfigurationPage({ params }: PageProps) {
108117
>
109118
Save
110119
</Button>
120+
<Button
121+
variant={"destructive"}
122+
className="ml-3"
123+
onClick={() => {
124+
handleDeleteProject();
125+
}}
126+
>
127+
Delete Project
128+
</Button>
111129
</div>
112130
</>
113131
)}

src/app/api/projects/route.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { fetchUserTeam } from "../teams/fetchTeam";
55
import { fetchUserTeams } from "../teams/fetchUserTeams";
66
import { ProjectRegisterDto } from "./types/project.dto";
77
import { registerUserTeam } from "../teams/registerUserTeam";
8+
import { deleteTeam } from "../teams/deleteTeam";
89

910
export async function GET(req: NextRequest) {
1011
const session = await getServerSession(options);
@@ -26,6 +27,20 @@ export async function GET(req: NextRequest) {
2627
}
2728
}
2829

30+
export async function DELETE(req: NextRequest) {
31+
try {
32+
const session = await getServerSession(options);
33+
const teamId = req.nextUrl.searchParams.get("team_id");
34+
if (teamId && session?.userId) {
35+
await deleteTeam(teamId, session.userId);
36+
return NextResponse.json({ success: true });
37+
}
38+
} catch (error) {
39+
console.log(error);
40+
return NextResponse.json({ success: false });
41+
}
42+
}
43+
2944
export async function POST(req: NextRequest) {
3045
try {
3146
const session = await getServerSession(options);

0 commit comments

Comments
 (0)