Skip to content

Commit

Permalink
enh(spu-ui): controlled item edit dialog
Browse files Browse the repository at this point in the history
- fix hydration error on dialog trigger
- consistent restyle button
- controlled dialog open state on submit form
  • Loading branch information
matyson committed Jan 9, 2025
1 parent 566baf5 commit eff8909
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions apps/spu-ui/src/app/_components/queue/item-edit-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { z } from "zod";
import { useCallback } from "react";
import { useCallback, useState } from "react";
import { PencilIcon } from "lucide-react";
import type { AnySchema } from "@sophys-web/widgets/lib/create-schema";
import { useQueue } from "@sophys-web/api-client/hooks/use-queue";
Expand All @@ -22,6 +22,7 @@ export function ItemEditDialog(props: QueueItemProps) {
const { data: plans } = api.plans.allowed.useQuery(undefined);
const { data: devices } = api.devices.allowedNames.useQuery(undefined);
const { update } = useQueue();
const [open, setOpen] = useState(false);

const planDetails = (() => {
if (plans) {
Expand All @@ -48,6 +49,7 @@ export function ItemEditDialog(props: QueueItemProps) {
{
onSuccess: () => {
toast.success(`Plan ${props.name} added to the queue`);
setOpen(false);
},
onError: (error) => {
const message = error.message.replace("\n", " ");
Expand All @@ -62,9 +64,13 @@ export function ItemEditDialog(props: QueueItemProps) {
);

return (
<Dialog>
<DialogTrigger>
<Button disabled={!planDetails || !devices} variant="outline">
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button
className="w-full"
disabled={!planDetails || !devices}
variant="outline"
>
<PencilIcon className="mr-2 h-4 w-4" />
Edit Item
</Button>
Expand Down

0 comments on commit eff8909

Please sign in to comment.