Ready for release soon.

This commit is contained in:
charlesgauthereau
2025-07-17 09:28:57 +02:00
parent 7abdcd57f9
commit 4d52419247
18 changed files with 1779 additions and 3335 deletions
+86 -61
View File
@@ -1,17 +1,17 @@
"use client";
import { useEffect, useState } from "react";
import {useEffect, useState} from "react";
import { Check, ChevronDown } from "lucide-react";
import {Check, ChevronDown} from "lucide-react";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { FormControl } from "@/components/ui/form";
import { SidebarMenuButton } from "@/components/ui/sidebar";
import { Separator } from "@/components/ui/separator";
import { CreateOrganizationModal } from "@/components/wrappers/dashboard/organization/create-organisation-modal";
import {cn} from "@/lib/utils";
import {Button} from "@/components/ui/button";
import {Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList} from "@/components/ui/command";
import {Popover, PopoverContent, PopoverTrigger} from "@/components/ui/popover";
import {FormControl} from "@/components/ui/form";
import {SidebarMenuButton} from "@/components/ui/sidebar";
import {Separator} from "@/components/ui/separator";
import {CreateOrganizationModal} from "@/components/wrappers/dashboard/organization/create-organisation-modal";
export type comboBoxProps = {
values: Array<{ value: string; label: string }>;
@@ -19,10 +19,18 @@ export type comboBoxProps = {
onValueChange?: any;
searchField?: boolean;
sideBar?: boolean;
reload?: () => void;
};
export function ComboBox(props: comboBoxProps) {
const { values: choices, defaultValue: defaultChoice = "", onValueChange, searchField = false, sideBar = false } = props;
const {
values: choices,
defaultValue: defaultChoice = "",
onValueChange,
searchField = false,
sideBar = false
} = props;
const [value, setValue] = useState<string>();
@@ -31,53 +39,68 @@ export function ComboBox(props: comboBoxProps) {
}, [defaultChoice]);
const [open, setOpen] = useState(false);
const [openModal, setOpenModal] = useState(false);
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
{sideBar ? (
<SidebarMenuButton>
{value ? choices.find((choice) => choice.value === value)?.label : "Select choice..."}
<ChevronDown className="ml-auto" />
</SidebarMenuButton>
) : (
<Button variant="outline" role="combobox" aria-expanded={open} className="w-full justify-between">
{value ? choices.find((choice) => choice.value === value)?.label : "Select choice..."}
<ChevronDown className="opacity-50" />
</Button>
)}
</PopoverTrigger>
<PopoverContent className="p-0 popover-content-width-full">
<Command>
{searchField ? <CommandInput placeholder="Search choice..." className="h-9" /> : null}
<CommandList>
<CommandEmpty>No choice found.</CommandEmpty>
<CommandGroup>
{choices.map((choice) => (
<CommandItem
key={choice.value}
value={choice.value}
onSelect={(currentValue) => {
setValue(currentValue);
onValueChange(currentValue);
setOpen(false);
}}
>
{choice.label}
<Check className={cn("ml-auto", value === choice.value ? "opacity-100" : "opacity-0")} />
</CommandItem>
))}
</CommandGroup>
</CommandList>
</Command>
<Separator />
{sideBar ? (
<CreateOrganizationModal>
<SidebarMenuButton>+ Create new organization</SidebarMenuButton>
</CreateOrganizationModal>
) : null}
</PopoverContent>
</Popover>
<div>
<CreateOrganizationModal
open={openModal}
onSuccess={() => {
props.reload?.();
}}
onOpenChange={setOpenModal}
/>
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
{sideBar ? (
<SidebarMenuButton>
{value ? choices.find((choice) => choice.value === value)?.label : "Select choice..."}
<ChevronDown className="ml-auto"/>
</SidebarMenuButton>
) : (
<Button variant="outline" role="combobox" aria-expanded={open}
className="w-full justify-between">
{value ? choices.find((choice) => choice.value === value)?.label : "Select choice..."}
<ChevronDown className="opacity-50"/>
</Button>
)}
</PopoverTrigger>
<PopoverContent className="p-0 popover-content-width-full">
<Command>
{searchField ? <CommandInput placeholder="Search choice..." className="h-9"/> : null}
<CommandList>
<CommandEmpty>No choice found.</CommandEmpty>
<CommandGroup>
{choices.map((choice) => (
<CommandItem
key={choice.value}
value={choice.value}
onSelect={(currentValue) => {
setValue(currentValue);
onValueChange(currentValue);
setOpen(false);
}}
>
{choice.label}
<Check
className={cn("ml-auto", value === choice.value ? "opacity-100" : "opacity-0")}/>
</CommandItem>
))}
</CommandGroup>
</CommandList>
</Command>
<Separator/>
{sideBar ? (
<SidebarMenuButton onClick={() => {
setOpen(false)
setOpenModal(true)
}
}>+ Create new organization</SidebarMenuButton>
) : null}
</PopoverContent>
</Popover>
</div>
);
}
@@ -89,7 +112,7 @@ export type comboBoxFormItemProps = comboBoxProps & {
/** Combobox to use when working with zodForm. */
export function ComboBoxFormItem(props: comboBoxFormItemProps) {
const { values: choices, searchField = false, value, name, onChange } = props;
const {values: choices, searchField = false, value, name, onChange} = props;
const [open, setOpen] = useState(false);
@@ -97,15 +120,16 @@ export function ComboBoxFormItem(props: comboBoxFormItemProps) {
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<FormControl>
<Button variant="outline" role="combobox" aria-expanded={open} className={cn("w-full justify-between", !value && "text-muted-foreground")}>
<Button variant="outline" role="combobox" aria-expanded={open}
className={cn("w-full justify-between", !value && "text-muted-foreground")}>
{value ? choices.find((choice) => choice.value === value)?.label : `Select ${name}`}
<ChevronDown className="opacity-50" />
<ChevronDown className="opacity-50"/>
</Button>
</FormControl>
</PopoverTrigger>
<PopoverContent className="p-0 popover-content-width-full">
<Command>
{searchField ? <CommandInput placeholder="Search choice..." className="h-9" /> : null}
{searchField ? <CommandInput placeholder="Search choice..." className="h-9"/> : null}
<CommandList>
<CommandEmpty>No {name} found.</CommandEmpty>
<CommandGroup>
@@ -119,7 +143,8 @@ export function ComboBoxFormItem(props: comboBoxFormItemProps) {
}}
>
{choice.label}
<Check className={cn("ml-auto", choice.value === value ? "opacity-100" : "opacity-0")} />
<Check
className={cn("ml-auto", choice.value === value ? "opacity-100" : "opacity-0")}/>
</CommandItem>
))}
</CommandGroup>