Skip to content

Commit 64e6a15

Browse files
committed
feat: add DFlowFolderCreateDialog component for creating new flow folders
1 parent d22fda9 commit 64e6a15

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import {DFlowFolderProps} from "./DFlowFolder";
2+
import React from "react";
3+
import {TextInput, useForm} from "../form";
4+
import {Dialog, DialogClose, DialogContent, DialogPortal} from "../dialog/Dialog";
5+
import {Flex} from "../flex/Flex";
6+
import {Button} from "../button/Button";
7+
import {FlowType} from "@code0-tech/sagittarius-graphql-types";
8+
import {DFlowFolderItemPathInput} from "./DFlowFolderItemPathInput";
9+
10+
export interface DFlowFolderCreateDialogProps extends DFlowFolderProps {
11+
open?: boolean
12+
onOpenChange?: (open: boolean) => void
13+
flowTypeId: FlowType['id']
14+
}
15+
16+
export const DFlowFolderCreateDialog: React.FC<DFlowFolderCreateDialogProps> = (props) => {
17+
const {open} = props
18+
19+
const [createDialogOpen, setCreateDialogOpen] = React.useState(open)
20+
const initialValues = React.useMemo(() => ({
21+
name: ""
22+
}), [])
23+
24+
React.useEffect(() => {
25+
setCreateDialogOpen(open)
26+
}, [open])
27+
28+
const [inputs, validate] = useForm({
29+
initialValues: initialValues,
30+
validate: {
31+
name: (value) => {
32+
if (!value) return "Name is required"
33+
return null
34+
}
35+
},
36+
onSubmit: (values) => {
37+
props.onCreate?.(values.name, props.flowTypeId)
38+
props.onOpenChange?.(false)
39+
}
40+
})
41+
42+
return <Dialog open={createDialogOpen} onOpenChange={(open) => {
43+
props.onOpenChange?.(open)
44+
}}>
45+
<DialogPortal>
46+
<DialogContent autoFocus showCloseButton
47+
title={"Create new flow"}>
48+
<div>
49+
<DFlowFolderItemPathInput
50+
description={"You can choose a name here and only use alphanumeric names."}
51+
title={"Name of the flow"}
52+
{...inputs.getInputProps("name")}/>
53+
</div>
54+
<Flex justify={"space-between"} align={"center"}>
55+
<DialogClose asChild>
56+
<Button color={"secondary"}>No, go back!</Button>
57+
</DialogClose>
58+
<Button color={"success"} onClick={validate}>Yes, create!</Button>
59+
</Flex>
60+
</DialogContent>
61+
</DialogPortal>
62+
</Dialog>
63+
}

0 commit comments

Comments
 (0)