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