feat(topic state and command) - add tab
This commit is contained in:
@@ -1,10 +1,24 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { getTopicsState } from "../../../repositories/device";
|
||||
import { getTopicsCommand, getTopicsState } from "../../../repositories/device";
|
||||
|
||||
export function useTopics() {
|
||||
const result = useQuery({
|
||||
queryKey: ["topics/state"],
|
||||
queryFn: () => getTopicsState(),
|
||||
gcTime: 0,
|
||||
});
|
||||
|
||||
return {
|
||||
...result,
|
||||
data: result?.data?.data,
|
||||
};
|
||||
}
|
||||
|
||||
export function useTopicCommand() {
|
||||
const result = useQuery({
|
||||
queryKey: ["topics/command"],
|
||||
queryFn: () => getTopicsCommand(),
|
||||
gcTime: 0,
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Edit, PlusIcon, Trash2 } from "lucide-react";
|
||||
import { useTopics } from "./hooks/queries";
|
||||
import { PlusIcon } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { cn } from "../../utils/classname";
|
||||
import StateSection from "./sections/state";
|
||||
import CommandSection from "./sections/command";
|
||||
|
||||
export default function TopicsFeature() {
|
||||
const { data } = useTopics();
|
||||
const [tab, setTab] = useState("state");
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="p-4 flex justify-end">
|
||||
@@ -11,18 +14,28 @@ export default function TopicsFeature() {
|
||||
Tambah Topic
|
||||
</button>
|
||||
</div>
|
||||
{data?.map((item, key) => (
|
||||
<div
|
||||
key={key}
|
||||
className="bg-white border-b border-neutral-200 p-4 flex justify-between"
|
||||
<div className="flex justify-between">
|
||||
<button
|
||||
onClick={() => setTab("state")}
|
||||
className={cn(
|
||||
"w-full text-center p-x2 py-4 border-b-2 border-transparent",
|
||||
tab === "state" && "border-amber-500",
|
||||
)}
|
||||
>
|
||||
<h1>{item.topic}</h1>
|
||||
<div className="flex gap-2 ">
|
||||
<Edit className="text-blue-500 cursor-pointer" size={18} />
|
||||
<Trash2 className="text-red-500 cursor-pointer" size={18} />
|
||||
state-reply
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setTab("command")}
|
||||
className={cn(
|
||||
"w-full text-center p-x2 py-4 border-b-2 border-transparent",
|
||||
tab === "command" && "border-amber-500",
|
||||
)}
|
||||
>
|
||||
commands
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{tab === "state" && <StateSection />}
|
||||
{tab === "command" && <CommandSection />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
22
src/features/topics/sections/command.tsx
Normal file
22
src/features/topics/sections/command.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { useTopicCommand } from "../hooks/queries";
|
||||
import { Edit, Trash2 } from "lucide-react";
|
||||
|
||||
export default function CommandSection() {
|
||||
const { data } = useTopicCommand();
|
||||
return (
|
||||
<>
|
||||
{data?.map((item, key) => (
|
||||
<div
|
||||
key={key}
|
||||
className="bg-white border-b border-neutral-200 p-4 flex justify-between"
|
||||
>
|
||||
<h1>{item.topic}</h1>
|
||||
<div className="flex gap-2 ">
|
||||
<Edit className="text-blue-500 cursor-pointer" size={18} />
|
||||
<Trash2 className="text-red-500 cursor-pointer" size={18} />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
22
src/features/topics/sections/state.tsx
Normal file
22
src/features/topics/sections/state.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { useTopics } from "../hooks/queries";
|
||||
import { Edit, Trash2 } from "lucide-react";
|
||||
|
||||
export default function StateSection() {
|
||||
const { data } = useTopics();
|
||||
return (
|
||||
<>
|
||||
{data?.map((item, key) => (
|
||||
<div
|
||||
key={key}
|
||||
className="bg-white border-b border-neutral-200 p-4 flex justify-between"
|
||||
>
|
||||
<h1>{item.topic}</h1>
|
||||
<div className="flex gap-2 ">
|
||||
<Edit className="text-blue-500 cursor-pointer" size={18} />
|
||||
<Trash2 className="text-red-500 cursor-pointer" size={18} />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -17,6 +17,16 @@ export const postCommandStatus = async (
|
||||
};
|
||||
|
||||
export const getTopicsState = async (): Promise<TopicData> => {
|
||||
const res = await api.get("/topics/v1/state-reply", {
|
||||
headers: {
|
||||
Authorization: basicAuth(ENV.basicUsername, ENV.basicPassword),
|
||||
},
|
||||
});
|
||||
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getTopicsCommand = async (): Promise<TopicData> => {
|
||||
const res = await api.get("/topics/v1/commands", {
|
||||
headers: {
|
||||
Authorization: basicAuth(ENV.basicUsername, ENV.basicPassword),
|
||||
|
||||
Reference in New Issue
Block a user