Skip to content

Instantly share code, notes, and snippets.

@xorostar
Created December 6, 2024 12:54
Show Gist options
  • Select an option

  • Save xorostar/1dc6abddb23cabf0b37a55759745d32b to your computer and use it in GitHub Desktop.

Select an option

Save xorostar/1dc6abddb23cabf0b37a55759745d32b to your computer and use it in GitHub Desktop.
Sample Code TS
import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
import { Application } from "@/schema/application"
import { ChevronRight } from "lucide-react"
import { useTranslation } from "@/i18n/client"
interface ChangeStageButtonProps {
application: Pick<Application, "id" | "pipeline" | "status" | "offer">
pipelines: Array<{
id: number
name: string
}>
onPipelineChange: (newPipelineId: number) => Promise<void>
isDisabled?: boolean
}
export default function ChangeStageButton({
application,
pipelines,
onPipelineChange,
isDisabled = false
}: ChangeStageButtonProps) {
const { t } = useTranslation("common")
const nextPipeline = pipelines.at(
pipelines.findIndex(p => p.id === application.pipeline.id) + 1
)
const isChangeable = !application.offer || application.offer.status === "PENDING"
return (
<div className="rounded-md border border-input flex items-center h-9">
{application.status === "APPLIED" ? (
<>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="sm"
className="rounded-none"
disabled={isDisabled || !isChangeable}
>
{application.pipeline.name}
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>{t("stages")}</DropdownMenuLabel>
<DropdownMenuRadioGroup
value={application.pipeline.id.toString()}
onValueChange={v => onPipelineChange(Number(v))}
>
{pipelines.map(pipeline => (
<DropdownMenuRadioItem
key={pipeline.id}
value={pipeline.id.toString()}
disabled={!isChangeable}
>
{pipeline.name}
</DropdownMenuRadioItem>
))}
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
{nextPipeline && (
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
className="h-9 w-7 rounded-none"
onClick={() => onPipelineChange(nextPipeline.id)}
disabled={isDisabled || !isChangeable}
>
<ChevronRight className="h-4 w-4" />
</Button>
</TooltipTrigger>
<TooltipContent>
{t("nextStage")} ({nextPipeline.name})
</TooltipContent>
</Tooltip>
)}
</>
) : (
<span className="text-sm font-medium px-3">
{application.pipeline.name}
</span>
)}
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment