Skip to content

Commit

Permalink
Refactor: streamline fetch requests and clean up imports in frontend …
Browse files Browse the repository at this point in the history
…components
  • Loading branch information
JustNZ committed Jan 28, 2025
1 parent 5d5b57b commit 5617b85
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import TimeAgo from "react-timeago";
import ChangeRunnerStatusModal from "@/components/functions/runner/changeStatus";
import DeleteRunnerModal from "@/components/functions/runner/delete";
import EditRunnerModal from "@/components/functions/runner/edit";
import RunnerDrawer from "@/components/functions/runner/plugins";

import AdminAlertFlowRunnerDetails from "./AlertFlowRunnerDetails";
import RunnerDrawer from "@/components/functions/runner/plugins";

export function AlertflowRunnerList({ runners, settings }: any) {
const [status, setStatus] = React.useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import React, { useState } from "react";
import { toast } from "sonner";

import ErrorCard from "@/components/error/ErrorCard";
import CreateProjectToken from "@/lib/fetch/project/POST/CreateProjectToken";
import CreateServiceToken from "@/lib/fetch/admin/POST/CreateServiceToken";

export default function CreateServiceTokenModal({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
"use client";

import { Icon } from "@iconify/react";
import {
Avatar,
Badge,
Button,
Card,
CardBody,
Spacer,
} from "@heroui/react";
import { Avatar, Badge, Button, Card, CardBody, Spacer } from "@heroui/react";
import { useRouter } from "next/navigation";
import React from "react";
import ReactTimeago from "react-timeago";
Expand Down
27 changes: 15 additions & 12 deletions services/frontend/lib/fetch/flow/POST/CreateFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ export default async function CreateFlow(
};
}

const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/flows/`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: token.value,
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/flows/`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: token.value,
},
body: JSON.stringify({
name,
description,
project_id: projectId,
runner_id: runnerId,
}),
},
body: JSON.stringify({
name,
description,
project_id: projectId,
runner_id: runnerId,
}),
});
);

if (!res.ok) {
const errorData = await res.json();
Expand Down
15 changes: 9 additions & 6 deletions services/frontend/lib/fetch/flow/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ export async function GetFlows(): Promise<SuccessResponse | ErrorResponse> {
};
}

const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/flows/`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: token.value,
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/flows/`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: token.value,
},
},
});
);

if (!res.ok) {
const errorData = await res.json();
Expand Down
15 changes: 9 additions & 6 deletions services/frontend/lib/fetch/payload/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ export async function GetPayloads(): Promise<SuccessResponse | ErrorResponse> {
};
}

const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/payloads/`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: token.value,
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/payloads/`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: token.value,
},
},
});
);

if (!res.ok) {
const errorData = await res.json();
Expand Down
29 changes: 16 additions & 13 deletions services/frontend/lib/fetch/project/POST/CreateProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,23 @@ export default async function CreateProject(
};
}

const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/projects/`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: token.value,
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/projects/`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: token.value,
},
body: JSON.stringify({
name,
description,
alertflow_runners: alertflowRunners,
icon,
color,
}),
},
body: JSON.stringify({
name,
description,
alertflow_runners: alertflowRunners,
icon,
color,
}),
});
);

if (!res.ok) {
const errorData = await res.json();
Expand Down
15 changes: 9 additions & 6 deletions services/frontend/lib/fetch/project/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ export async function GetProjects(): Promise<SuccessResponse | ErrorResponse> {
};
}

const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/projects/`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: token.value,
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/projects/`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: token.value,
},
},
});
);

if (!res.ok) {
const errorData = await res.json();
Expand Down
15 changes: 9 additions & 6 deletions services/frontend/lib/fetch/runner/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ export async function GetRunners(): Promise<SuccessResponse | ErrorResponse> {
const cookieStore = await cookies();
const token = cookieStore.get("session");

const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/runners/`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: token.value,
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/runners/`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: token.value,
},
},
});
);

if (!res.ok) {
const errorData = await res.json();
Expand Down

0 comments on commit 5617b85

Please sign in to comment.