feat: connect the combobox to the api (sortof)

This commit is contained in:
Juan Di Toro 2023-12-09 16:22:22 +01:00
parent 192d7049c8
commit d203ad3400
3 changed files with 43 additions and 36 deletions

View File

@ -17,38 +17,13 @@ import {
PopoverTrigger
} from "@/components/ui/popover"
import { ChevronDownIcon } from "@heroicons/react/24/solid"
type Status = {
value: string
label: string
}
const statuses: Status[] = [
{
value: "backlog",
label: "Backlog"
},
{
value: "todo",
label: "Todo"
},
{
value: "in progress",
label: "In Progress"
},
{
value: "done",
label: "Done"
},
{
value: "canceled",
label: "Canceled"
}
]
import useSWR from "swr"
import { getAvailableSites } from "@/utils"
export function SitesCombobox() {
const {data: statuses} = useSWR('/api/statuses', getAvailableSites)
const [open, setOpen] = React.useState(false)
const [selectedStatus, setSelectedStatus] = React.useState<Status | null>(
const [selectedStatus, setSelectedStatus] = React.useState<SelectOptions | null>(
null
)
@ -67,7 +42,7 @@ export function SitesCombobox() {
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup>
{statuses.map((status) => (
{statuses?.map((status) => (
<CommandItem
className="text-white"
key={status.value}

17
src/types.d.ts vendored
View File

@ -1,7 +1,12 @@
type SearchResult = {
id: number
timestamp: Date
title: string
description: string
slug: string
}
id: number
timestamp: Date
title: string
description: string
slug: string
}
type SelectOptions = {
value: string
label: string
}

View File

@ -44,3 +44,30 @@ export async function getResults({
]
}
export async function getAvailableSites() {
const statuses: SelectOptions[] = [
{
value: "backlog",
label: "Backlog"
},
{
value: "todo",
label: "Todo"
},
{
value: "in progress",
label: "In Progress"
},
{
value: "done",
label: "Done"
},
{
value: "canceled",
label: "Canceled"
}
]
return statuses;
}