Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieCubed committed Feb 22, 2024
1 parent 4455b8a commit 8d67432
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 88 deletions.
114 changes: 57 additions & 57 deletions src/components/appbar/AgentStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,71 +8,71 @@ import axios from "axios";

//Need to change based on every single diff. Taskrouter workspace
const activities = {
Available: "",
Unavailable: "",
Offline: "",
Available: "",
Unavailable: "",
Offline: "",
};

const AgentStatus: React.FC = () => {
const [activity, setActivity] = useState("Unavailable");
const [activity, setActivity] = useState("Unavailable");

const toggleAvailability = async () => {
const newActivity =
activity === "Unavailable" ? "Available" : "Unavailable";
setActivity(newActivity);
const activitySid = activities[newActivity];
const toggleAvailability = async () => {
const newActivity =
activity === "Unavailable" ? "Available" : "Unavailable";
setActivity(newActivity);
const activitySid = activities[newActivity];

//Request to API route
try {
// Send a request to your API route using axios
const response = await axios.post("/api/agent", {
activitySid,
});
} catch (error) {
console.error("Error updating status:", error);
// If API call fail, make no change
setActivity(activity);
}
};
//Request to API route
try {
// Send a request to your API route using axios
const response = await axios.post("/api/agent", {
activitySid,
});
} catch (error) {
console.error("Error updating status:", error);
// If API call fail, make no change
setActivity(activity);
}
};

return (
<div className="flex gap-2 justify-center items-center">
<Button variant="outline" onClick={toggleAvailability}>
{activity === "Available" ? "Go Offline" : "Go Available"}
</Button>
<div className="flex gap-2 border border-gray-300 p-2 m-4 bg-gray-100 rounded">
<div>Status</div>
return (
<div className="flex gap-2 justify-center items-center">
<Button variant="outline" onClick={toggleAvailability}>
{activity === "Available" ? "Go Offline" : "Go Available"}
</Button>
<div className="flex gap-2 border border-gray-300 p-2 m-4 bg-gray-100 rounded">
<div>Status</div>

<div>
{activity === "Available" ? (
<>
<Chip
variant="ghost"
color="green"
size="sm"
value="Available"
icon={
<span className="mx-auto mt-1 block h-2 w-2 rounded-full bg-green-900 content-['']" />
}
/>
</>
) : (
<>
<Chip
variant="ghost"
color="red"
size="sm"
value="Unavailable"
icon={
<span className="mx-auto mt-1 block h-2 w-2 rounded-full bg-red-900 content-['']" />
}
/>
</>
)}
</div>
</div>
<div>
{activity === "Available" ? (
<>
<Chip
variant="ghost"
color="green"
size="sm"
value="Available"
icon={
<span className="mx-auto mt-1 block h-2 w-2 rounded-full bg-green-900 content-['']" />
}
/>
</>
) : (
<>
<Chip
variant="ghost"
color="red"
size="sm"
value="Unavailable"
icon={
<span className="mx-auto mt-1 block h-2 w-2 rounded-full bg-red-900 content-['']" />
}
/>
</>
)}
</div>
);
</div>
</div>
);
};

export default AgentStatus;
2 changes: 0 additions & 2 deletions src/components/audittable/AuditTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import React, {
useEffect,
useState,
useCallback,
TdHTMLAttributes,
} from "react";
import axios from "axios";
import * as XLSX from "xlsx";
import { Row } from "@tanstack/react-table";

import { FetchedCalls, columns } from "./columns";
import { DataTable } from "./DataTable";
Expand Down
58 changes: 29 additions & 29 deletions src/components/audittable/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { ColumnDef } from "@tanstack/react-table"
import { MoreHorizontal } from "lucide-react"
import {Checkbox} from "@/components/ui/checkbox"
import { Checkbox } from "@/components/ui/checkbox"

import { Button } from "@/components/ui/button"
import {
Expand All @@ -17,36 +17,36 @@ import {

// This type is used to define the shape of our data.
export type FetchedCalls = {
id: string;
direction: string;
from: string | null;
to: string | null;
timestamp: string;
id: string;
direction: string;
from: string | null;
to: string | null;
timestamp: string;
}

export const columns: ColumnDef<FetchedCalls>[] = [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && "indeterminate")
}
onCheckedChange={(value: any) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value: any) => row.toggleSelected(!!value)}
aria-label="Select row"
/>
),
enableSorting: false,
enableHiding: false,
},
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && "indeterminate")
}
onCheckedChange={(value: any) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value: any) => row.toggleSelected(!!value)}
aria-label="Select row"
/>
),
enableSorting: false,
enableHiding: false,
},

{
accessorKey: "direction",
Expand All @@ -70,7 +70,7 @@ export const columns: ColumnDef<FetchedCalls>[] = [
id: "actions",
cell: ({ row }) => {
const call = row.original

return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
Expand Down

0 comments on commit 8d67432

Please sign in to comment.