Skip to content

Commit

Permalink
Adds button to delete project in project configurations (#163)
Browse files Browse the repository at this point in the history
* Adds button to delete project in project configurations

* Fixes linter issues
  • Loading branch information
sudoFerraz authored Jun 13, 2024
1 parent d47ff62 commit 6b66b72
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/app/(dashboard)/projects/[projectId]/configuration/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ export default function ProjectConfigurationPage({ params }: PageProps) {
}
};

const handleDeleteProject = async () => {
const { data } = await axios.delete(`/api/projects?team_id=${teamId}`);
if (data.success) {
router.push(`/projects`);
} else {
console.log("Error deleting project");
}
};

const handleCalculate = async () => {
const { data } = await axios.get(`/api/credmanager?team_id=${team!.id}`);
if (data && data.success) {
Expand Down Expand Up @@ -108,6 +117,15 @@ export default function ProjectConfigurationPage({ params }: PageProps) {
>
Save
</Button>
<Button
variant={"destructive"}
className="ml-3"
onClick={() => {
handleDeleteProject();
}}
>
Delete Project
</Button>
</div>
</>
)}
Expand Down
15 changes: 15 additions & 0 deletions src/app/api/projects/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { fetchUserTeam } from "../teams/fetchTeam";
import { fetchUserTeams } from "../teams/fetchUserTeams";
import { ProjectRegisterDto } from "./types/project.dto";
import { registerUserTeam } from "../teams/registerUserTeam";
import { deleteTeam } from "../teams/deleteTeam";

export async function GET(req: NextRequest) {
const session = await getServerSession(options);
Expand All @@ -26,6 +27,20 @@ export async function GET(req: NextRequest) {
}
}

export async function DELETE(req: NextRequest) {
try {
const session = await getServerSession(options);
const teamId = req.nextUrl.searchParams.get("team_id");
if (teamId && session?.userId) {
await deleteTeam(teamId, session.userId);
return NextResponse.json({ success: true });
}
} catch (error) {
console.log(error);
return NextResponse.json({ success: false });
}
}

export async function POST(req: NextRequest) {
try {
const session = await getServerSession(options);
Expand Down

0 comments on commit 6b66b72

Please sign in to comment.